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: objc.dg/?sortby=date#dirlist

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


- Instance variables can have access control:

	@interface MyClass : NSObject
		int public_var;
		int private_var;
		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;

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

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

	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
		- (int)foo;
		- (void)bar: (int)arg;

- 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;

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.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.