Theocacao
Leopard
Design Element
Comment on "WWDC 2006: Wednesday Wrap-Up"
by Mithras — Aug 10
Here's some of the most prominent Objective C changes, cherrypicked from the ObjC mailing list:

-----
- Instance variables can have access control:


@interface MyClass : NSObject
{
@public
int public_var;
@private
int private_var;
@protected
int protected_var;
}


- We have the syntax for properties, in both classes and protocols:


@interface MyClass : NSObject
@property int foo;
@property(getter=_getBaz,setter=_setBaz) float baz;
@end

@implementation MyClass
- (int)_getBaz { return baz; }
- (void)_setBaz: (float)newBaz { baz = abs(newBaz); }
@end

@protocol MyProtocol
@property(copies,readonly) NSString *bar;
@end

int main(void) {
MyClass *m = [MyClass new];
m.baz = -5.0;
printf("%f\n", m.baz); /* -> 5.0000 */
}



- Protocols can list required or optional methods:


@protocol MyProtocol
@optional
- (int)foo;
@required
- (void)bar: (int)arg;
@end


- The syntax for foreach is pretty obvious, but here it is anyhow:


NSArray *arr = randomListOfStrings();
for (NSString *s in arr) {
printf("%@\n", s);
}

It looks like there may be a facility for enumeration of user- defined types...

- To accomodate GC, fields can be weak:


@interface MyClass
{
__weak id some_var;
}
@end
Back to "WWDC 2006: Wednesday Wrap-Up"
Design Element

Copyright © Scott Stevenson 2004-2015