I have an Xcode project with a ASObjC script
in my script I’m trying to use:
set newData to (current application's NSArray's arrayWithArray:oldData)
set writeArray to newData's writeToFile:filePath atomically:true
if writeArray as boolean is false then error "Failed to write History file"
in my Xcode log I get an error -2700
from research I’ve found this:
errOSAGeneralError = -2700,
/* Signaled by user scripts or applications when no actual error code is to be returned.*/
filePath is ~/Documents/TraktorNameServer/TNS History-181126-0703.plist
any ideas
Perhaps your array contains types that aren’t supported in property lists.
You’re better to use NSPropertyListSerialization to create your plist data – direct saving of arrays is discouraged these days, and although it’s a bit more code, you will get more useful error messages.
set {theData, theError} to current application's NSPropertyListSerialization's dataWithPropertyList:yourArray format:(current application's NSPropertyListBinaryFormat_v1_0) options:0 |error|:(reference) -- might as well use binary format
if theData is missing value then error (theError's localizedDescription() as text) number -10000
-- write data to file
set theResult to theData's writeToFile:posixPath atomically:true
Hang on – is your path really “~/Documents/TraktorNameServer/TNS History-181126-0703.plist”? Because you can’t pass paths with unexpanded tildes.
Yes it was the tilde in my path thanks!
Well with my new code and new array. Both of the above methods are erroring.
- using NSArray’s write to file
- using NSPropertyListSerialization fails when creating the Data
- using NSKeyedArchiver works fine
the NSArray contains Dictionaries of very multilevel further mix of
NSArray, NSDictionaries and NSMutableDictionaries.
the total “node” count is up past 50,000
Rather than just going with NSKeyedArchiver I was stubborn in trying to
make the others work. And also I guess to understand why.
please let me know what you think (or if any of these seem right)
- Using AppleScript V2.5
- the size of the Array
- the mixed state of the Array
- that the Array was created via multiple leveled script libraries
- that NSPropertyListSerialization is marked as being deprecated.
thanks
What does the error say?
No it’s not – just some of its methods have been superseded.