myView.frame.origin.x = value; does not work – But why?

There are two distinct dot syntaxes being used here. They look the same, but they do different things depending on what they are operating on and what is being done with it: The first myView.frame is a shorthand for [myView frame], a method call that returns a CGRect struct by value. myFrame.origin.x is accessing ordinary … Read more

Get property name as a string

You can try this: unsigned int propertyCount = 0; objc_property_t * properties = class_copyPropertyList([self class], &propertyCount); NSMutableArray * propertyNames = [NSMutableArray array]; for (unsigned int i = 0; i < propertyCount; ++i) { objc_property_t property = properties[i]; const char * name = property_getName(property); [propertyNames addObject:[NSString stringWithUTF8String:name]]; } free(properties); NSLog(@”Names: %@”, propertyNames);

self.variable and variable difference [duplicate]

It’s important to note that dot-syntax is converted to a simple objc_msgSend call by the compiler: that is to say that underneath it acts exactly like a message send to the accessor for that variable. As such, all three of the following are equivalent: self.myVariable = obj; [self setMyVariable:obj]; objc_msgSend(self, @selector(setMyVariable:), obj); Of course, this … Read more

Do declared properties require a corresponding instance variable?

If you are using the Modern Objective-C Runtime (that’s either iOS 3.x or greater, or 64-bit Snow Leopard or greater) then you do not need to define ivars for your properties in cases like this. When you @synthesize the property, the ivar will in effect be synthesized also for you. This gets around the “fragile-ivar” … Read more

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

Nonatomic Nonatomic will not generate threadsafe routines thru @synthesize accessors. atomic will generate threadsafe accessors so atomic variables are threadsafe (can be accessed from multiple threads without botching of data) Copy copy is required when the object is mutable. Use this if you need the value of the object as it is at this moment, … Read more