Showing posts with label property. Show all posts
Showing posts with label property. Show all posts

Monday, 7 March 2011

methods + properties


@synthesize bob

Auto generates Getters and Setters for 'bob'




notesField.text= @"new value";

This is how you set a property.




[sender setTitle:@"i've been clicked!!" forState:UIControlStateNormal];

This is how you call a method - The Apple term is 'selector' when used it becomes a 'message'. We use the notation:

[object argument1:value argument2:value]

Note that argument1 replaces / is the method name

Sunday, 6 March 2011

Reference Counting & Properties

I have 1 word for this shit - Yuck.

A quick summary of properties:


@property (nonatomic, readonly) int* me

creates a getter: object.me

@property (nonatomic, readwrite) int* me

creates a getter + setter (DEFAULT)




@property (nonatomic, assign) NSString* myStr

'Normal' assign - does not increase reference count. (DEFAULT)

@property (nonatomic, retain) NSString* myStr

as above but increases the reference count by 1. (Retains the String - dont release this I'm using it!).

@property (nonatomic, copy) NSString* myStr

clone.

For Primitives use retain.
For Objects that may change & Strings use copy




Style: Only release the object if you created it. Objects returned from methods should be using autorelease this means you do not have to worry about cleaning up the object when you have finished with it.


Further reading