I am trying to use a list of search result properties for my iPhone application. The server is a prototype written in Python.
At first I found Python's built-in plistlib, which is awesome. I want to allow search by your type, so I need it to be as small as possible and the xml to be too large. The binary plastic format seems like a good choice. Unfortunately, plistlib does not execute binaries, so step up PyObjC.
(Segue: I am very open to any other considerations on how to perform a real-time search. I have already simplified the data as much as possible, including only displaying enough results to fill the window with the iPhone keyboard up, which is 5).
Unfortunately, although I know Python and is pretty decent with Cocoa, I still don't get PyObjC.
This is the Cocoa equivalent of what I want to do:
NSArray *plist = [NSArray arrayWithContentsOfFile:read_path];
NSError *err;
NSData *data = [NSPropertyListSerialization dataWithPropertyList:plist
format:NSPropertyListBinaryFormat_v1_0
options:0
error:&err];
[data writeToFile:write_path atomically:YES];
I thought I could do something similar, but dataWithPropertyList is not on the dir () list of the NSPropertyListSerialization object list. I probably should also convert the list to NSArray. I tried PyObjC docs, but it is so much about my real work that I thought I would try SO SOS too.
from Cocoa import NSArray, NSData, NSPropertyListSerialization, NSPropertyListBinaryFormat_v1_0
plist = [dict(key1='val', key2='val2'), dict(key1='val', key2='val2')]
NSPropertyListSerialization.dataWithPropertyList_format_options_error(plist,
NSPropertyListBinaryFormat_v1_0,
?,
?)
This is how I read in the plist on the iPhone side.
NSData *data = [NSData dataWithContentsOfURL:url];
NSPropertyListFormat format;
NSString *err;
id it = [NSPropertyListSerialization
propertyListFromData:data
mutabilityOption:0
format:&format
errorDescription:&err];
We are happy to clarify whether this makes sense.