synthesize

Why do I need to write @synthesize when I provide getter and setter?

 ̄綄美尐妖づ 提交于 2019-11-26 16:39:30
问题 So the auto synthesize of properties is awesome. However, when you provide both a getter and a setter, you get an error. @property (strong, nonatomic) NSArray *testArray; - (NSArray *)testArray { return _testArray; } - (void)setTestArray:(NSArray *)testArray { _testArray = testArray; } Error: Use of undeclared identifier '_testArray' . Adding @synthesize testArray = _testArray; solves the problem. I am just wondering why this is? 回答1: When you provide both getter and setter, there is often

@synthesize vs @dynamic, what are the differences?

最后都变了- 提交于 2019-11-26 11:27:20
What are the differences between implementing a @property with @dynamic or @synthesize ? diederikh @synthesize will generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass or will be provided at runtime). Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet. @dynamic also can be used to delegate the responsibility of

Difference between _ and self. in Objective-C

吃可爱长大的小学妹 提交于 2019-11-26 10:16:26
问题 Is there a difference between using the underscore and using the self keyword in Objective-C when calling an @property ? Property declaration: @property (weak, nonatomic) NSString *myString; Calling @synthesize on the property: @synthesize myString = _myString; Is there a difference if I want to use it in my code? When? In the getter/setter? self.myString = @\"test\"; _myString = @\"test\"; 回答1: self.myString = @"test"; is exactly equivalent to writing [self setMyString:@"test"]; . Both of

@synthesize vs @dynamic, what are the differences?

偶尔善良 提交于 2019-11-26 03:31:49
问题 What are the differences between implementing a @property with @dynamic or @synthesize ? 回答1: @synthesize will generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass or will be provided at runtime). Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass