The Old Blog Archive, 2005-2009

ObjectiveFlickr: One note on callMethod:arguments: method

A quick note there. You may have noticed the callMethod:arguments: method in OFFlickrAPICaller class takes an NSString and an NSArray. Normally you’ll pass make the keys and values into an array and pass it to the method. There is one thing that ObjectiveFlickr has done for you.

For those who have played with Flickr API, there are some API arguments that take a list of photo id’s (flickr.photosets.editPhotos comes to mind). Now, we all love using NSArray to store those photo id’s. But to concatenate them into a comma-delimited string is a pain. So ObjectiveFlickr has done that for you. Simply call:

NSArray *somePhotoIDs; // let’s say 123, 456, 789
[apicaller callMethod:@"flickr.photosets.editPhotos" arguments:[NSArray arrayWithObjects:@"photoset_id", myPhotoSetID, @"primary_photo_id", myPrimaryPhotoID, @"photo_ids", somePhotoIDs, nil]];

And ObjectiveFlickr will expand somePhotosIDs into “123,456,789″ for you. Automatically!

Objective-C-native flavor will also work:

[apicaller flickr_photoset_editPhotos:nil photoset_id:myPhotoSetID primary_photo_id:myPrimaryPhotoID photo_ids:somePhotoIDs];

Note that since Flickr API is case-sensitive, you may want to be careful about the cases in the method signature above. In the future I might add some error checking to prevent debugging hell caused by typos.

Comments are closed.