Re:First Glance at Objective-C and the iPhone SDK (by a Java...
by betamike on Wednesday January 26, 2011 @02:00PM
(#2144513)
You can define a category within your implementation file (.m) and redeclare the property like this:
@interface MyClass (PrivateMethods)
@property(readwrite, retain) NSObject *myProperty;
@end
@implementation MyClass ...
Now only your implementation knows about the generated setter methods, and you don't have to implement them yourself.
Re:First Glance at Objective-C and the iPhone SDK (by a Java...
by rbritton on Wednesday January 26, 2011 @02:28PM
(#2144668)
You can use @public, @private, or @protected on the instance variables. Unfortunately these do not extend to the properties themselves and you have to use a different approach as in the sibling comment:
@interface SomeClass (SomePrivateCategory)
@property (nonatomic, assign) NSUInteger count;
...
@end
- The ability to assign types as ClassName<Protocol>, instead of the protocol specifying the type completely. Neat, I guess...
- Because it's message passing, you get duck typing for free, albeit with compiler warnings (you send a message, and wouldn't you know it, the selector exists!). Not that I recommend this approach over protocols.
- The awesomeness of @selector, especially if you're coming from Java and used to writing anonymous classes everywhere simply for the sake of making functions first-class entities.
- The lack of public/protected/private visibility modifiers and how variables are suddenly part of the public API when you define them in properties. Say you have a variable you want to keep private, but you need to frequently update its value. You go ahead and define @property (nonatomic, retain) for it so within the class so that you can simply do self.varName = newVarValue to update it. But now all your clients/outside clients will see; you need to write the release-and-retain setter yourself in the .m file to prevent this.
- The minimalism of Xcode. Hey, it's faster than Eclipse, thank $DEITY for that. But when I want to alphabetize the filenames in the left sidebar, I have to go to Edit -> Sort -> By Name for _every_ file group?