NSString property: copy or retain?

For attributes whose type is an immutable value class that conforms to the NSCopying protocol, you almost always should specify copy in your @property declaration. Specifying retain is something you almost never want in such a situation. Here’s why you want to do that: NSMutableString *someName = [NSMutableString stringWithString:@”Chris”]; Person *p = [[[Person alloc] init] … Read more

How do I use NSTimer?

Firstly I’d like to draw your attention to the Cocoa/CF documentation (which is always a great first port of call). The Apple docs have a section at the top of each reference article called “Companion Guides”, which lists guides for the topic being documented (if any exist). For example, with NSTimer, the documentation lists two … Read more

What are best practices that you use when writing Objective-C and Cocoa? [closed]

There are a few things I have started to do that I do not think are standard: 1) With the advent of properties, I no longer use “_” to prefix “private” class variables. After all, if a variable can be accessed by other classes shouldn’t there be a property for it? I always disliked the … Read more

Best way to define private methods for a class in Objective-C

There isn’t, as others have already said, such a thing as a private method in Objective-C. However, starting in Objective-C 2.0 (meaning Mac OS X Leopard, iPhone OS 2.0, and later) you can create a category with an empty name (i.e. @interface MyClass ()) called Class Extension. What’s unique about a class extension is that … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)