Source

pyobjc / Examples / addressbook.m

/*
 * Objective-C version of addressbook.py.
 *
 * This is not necessarily an example of good Objective-C programing, but
 * should help to compare two equivalent programs.
 */
#import <AddressBook/AddressBook.h>
#import <Foundation/Foundation.h>
#include <objc/objc-runtime.h>


int main(void)
{
	NSAutoreleasePool* pl = [[NSAutoreleasePool alloc] init];
	ABAddressBook* book = [objc_lookUpClass("ABAddressBook") sharedAddressBook];
	ABPerson* me = [book me];

	if (!me) {
		printf("You don't have a 'my card'\n");
		return 1;
	}

	NSArray* propNames = [ABPerson properties];
	NSMutableDictionary* d = [NSMutableDictionary dictionary];

	NSEnumerator* e = [propNames objectEnumerator];
	id k;
	while (k = [e nextObject]) {
		id v = [me valueForProperty:k];
		if (v) {
			[d setObject:v forKey:k];
		}
	}

	NSMutableArray* keys = [NSMutableArray arrayWithArray:[d allKeys]];
	[keys sortUsingSelector:@selector(compare:)];

	NSLog(@"Information about me");
	NSLog(@"--------------------");

	e = [keys objectEnumerator];
	while (k = [e nextObject]) {
	    NSLog(@"%@: %@", k, [d objectForKey:k]);
        }

	return 0;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.