通過foo.property訪問對象屬性或方法與[foo property]有什麼區別?Objective-C Property Access
5
A
回答
10
沒什麼! Dot-notation是Objective-C 2.0中引入的「語法糖」。事實上,編譯器在編譯期間將編譯器foo.property轉換爲[foo屬性],所以它們的編譯完全一樣。
這只是你喜歡的問題。
1
在編譯時它們被視爲相同,但使用點符號來處理屬性的一個好處是,在編碼時,在放置「。」之後。代碼完成/代碼窗口將只顯示有效的屬性作爲建議,而使用括號將顯示所有方法。
相關問題
- 1. Bean Property Access and Annotations
- 2. 使用@property(copy)和@property(retain)的經驗法則是什麼?
- 3. NumberFormatter - ObjectiveC
- 4. ObjectiveC分配和init?
- 5. 的ObjectiveC,創建類的
- 6. JSON ObjectiveC - 錯誤
- 7. 中的ObjectiveC
- 8. 在的ObjectiveC
- 9. 在的ObjectiveC
- 10. 在的ObjectiveC
- 11. ObjectiveC隨機數字
- 12. @property @synthesize
- 13. From Performance Wise:Class Computed Property vs Stored Property
- 14. _iVar和@property?
- 15. People Picker AllowEmpty Property
- 16. Objective C @property comments
- 17. Property not visible
- 18. VB.net 2008 Property Array
- 19. 使@property私人
- 20. Array class property
- 21. @property Objective-C
- 22. WCF ChannelFactory State Property
- 23. Xcode Property Automation
- 24. Python對象@property
- 25. Typescript select property
- 26. WPF Property Grid
- 27. Set AssemblyName.Version Property
- 28. Button BackgroundImage Property
- 29. CGFloat as Property
- 30. Kotlin Property Observable