Monday, April 22, 2019

#1 2018-11-26 09:19:38 am

technomorph
Member
Registered: 2017-12-14
Posts: 103

Xcode error when trying to write an Array to File

I have an Xcode project with a ASObjC script

in my script I'm trying to use:

Applescript:

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

Offline

 

#2 2018-11-26 05:11:50 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5626

Re: Xcode error when trying to write an Array to File

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.

Applescript:

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Online

 

#3 2018-11-27 11:00:23 pm

technomorph
Member
Registered: 2017-12-14
Posts: 103

Re: Xcode error when trying to write an Array to File

Yes it was the tilde in my path thanks!

Offline

 

#4 2018-12-11 09:33:59 pm

technomorph
Member
Registered: 2017-12-14
Posts: 103

Re: Xcode error when trying to write an Array to File

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

Offline

 

#5 2018-12-11 10:56:36 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5626

Re: Xcode error when trying to write an Array to File

technomorph wrote:

Both of the above methods are erroring.



What does the error say?

NSPropertyListSerialization is marked as being deprecated.



No it's not -- just some of its methods have been superseded.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Online

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)