@property and @synthesize有什麼用?你能用一個例子來解釋一下嗎?Objective-C中使用的@property和@synthesize是什麼?
1
A
回答
6
真的很簡短回答:他們爲ivars創建訪問器。
還有some examples on wikipedia。看看那些。
3
你可以把屬性聲明爲等同於聲明兩個存取方法。因此
@property float value;
等同於:
- (float)value;
- (void)setValue:(float)newValue;
,並通過使用@synthesize,編譯器創建存取方法,你(看更多here)
1
// Sample for @property and @sythesize //
@interface ClassA
NSString *str;
@end
@implementation ClassA
@end
The Main Function main()
//確保你#import ClassA
ClassA *obj=[[ClassA alloc]init];
[email protected]"XYZ"; // That time it will give the error that we don't have the getter or setter method. To use string like this we use @property and @sythesize
相關問題
- 1. @property和@synthesize有什麼意義?
- 2. @property和@synthesize有什麼區別?
- 3. @property和@synthesize:爲什麼這兩個?
- 4. @property和@synthesize
- 5. 什麼時候你必須在iPhone SDK中使用@property和@synthesize?
- 6. 關於@property和@synthesize
- 7. @property @synthesize
- 8. 使用@property和@synthesize的任何錯誤
- 9. 使用@property和@synthesize時防止泄漏
- 10. 關於產品@property和@synthesize
- 11. 何時需要@property和@synthesize?
- 12. 什麼是ObjectiveC中的retainCount?
- 13. 使用@property(copy)和@property(retain)的經驗法則是什麼?
- 14. Objective-C:@property和@synthesize和內存泄漏
- 15. @property和@synthesize和內存錯誤
- 16. @property和@synthesize的工作方式如何?
- 17. @property @synthesize @dynamic差異在Xcode
- 18. IOS @property,@synthesize內存泄漏
- 19. 使用@property和@synthesize時得到不正確的值
- 20. @synthesize foo = _foo是什麼?
- 21. OC中@property(strong)的用法是什麼?
- 22. 調用什麼是「@synthesize slider = _slider;」
- 23. 「property =''」是做什麼的?
- 24. SPListItem [「property」]和SPListItem.Properties [「property」]之間的區別是什麼?
- 25. 在ObjectiveC中使用指針的最大優勢是什麼
- 26. 關於@synthesize [property name]語法的問題
- 27. @synthesize window = _window是做什麼的?
- 28. 爲什麼使用@synthesize語句
- 29. 使用@property和@synthesize創建存取方法和ivars的詳細信息
- 30. iOS中@property的默認值是什麼?
幫助自己,讀一本書或蘋果的目標C介紹:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html – 2011-10-11 11:00:15