Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Objective-C 2.0: more clues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objective-C 2.0: more clues



Apple seems to have left us more breadcrumbs in the Objective-C test cases: http://gcc.gnu.org/viewcvs/branches/apple/trunk/gcc/testsuite/ objc.dg/?sortby=date#dirlist

Here are some of the new features I've noticed, what have I missed?

Dave


- 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


Attachment: PGP.sig
Description: This is a digitally signed message part

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.