declared-property

Difference between self.var and simply var

给你一囗甜甜゛ 提交于 2019-11-26 06:48:39
问题 What is the difference between using self.var vs. just var in an Objective-C class? Are there benefits or dangers to one or the other? 回答1: foo = self.var; self.var = foo; is conceptually identical to foo = [self var]; [self setVar: foo]; So using dot notation, you are really sending messages to self. foo = var; var = foo; is conceptually the same as foo = self->var; self->var = foo; So not using dot notation to access an instance variable is the same as treating self as a pointer to a C

Do declared properties require a corresponding instance variable?

自古美人都是妖i 提交于 2019-11-26 00:47:07
问题 Do properties in Objective-C 2.0 require a corresponding instance variable to be declared? For example, I\'m used to doing something like this: MyObject.h @interface MyObject : NSObject { NSString *name; } @property (nonatomic, retain) NSString *name; @end MyObject.m @implementation @synthesize name; @end However, what if I did this instead: MyObject.h @interface MyObject : NSObject { } @property (nonatomic, retain) NSString *name; @end Is this still valid? And is it in any way different to

Objective-C declared @property attributes (nonatomic, copy, strong, weak)

梦想的初衷 提交于 2019-11-26 00:10:41
问题 Can someone explain to me in detail when I must use each attribute: nonatomic , copy , strong , weak , and so on, for a declared property, and explain what each does? Some sort of example would be great also. I am using ARC. 回答1: This answer has numerous errors and is also outdated. Please see other questions/answers and the comments. Nonatomic nonatomic is used for multi threading purposes. If we have set the nonatomic attribute at the time of declaration, then any other thread wanting