(NSArray)writeToFile: issue
- Get link
- X
- Other Apps
hi all,
have been struggling few days , need help. (nsarray) writetofile: fails. have written test code closely emulates code trying write. takes instance of class, places in nsarray, writes nsurl. measure, file @ given nsurl first read.
here code. (xcode(4.3.3), command line tool. file, "h.txt" words "this test" exists in folder called "testplist" on desktop.
output:code:#import <foundation/foundation.h> @interface testclass : nsobject @property(strong)nsstring * code; @property(strong)nsstring * desc; @end @implementation testclass @synthesize code, desc; @end int main(int argc, const char * argv[]) { @autoreleasepool { nsstring * path = [nsstring stringwithstring:@"/users/m/desktop/testplist/h.txt"]; testclass * 1 = [[testclass alloc]init]; [one setcode:@"123"]; [one setdesc:@"foo bar"]; nsarray *arrwithclass = [nsarray arraywithobject:one]; nsurl * url = [nsurl fileurlwithpath:path]; nslog(@"url:%@",url); nsstring *filecontents = [nsstring stringwithcontentsofurl:url encoding:nsutf8stringencoding error:nil]; nslog(@"file contents: %@", filecontents); bool success = [arrwithclass writetourl:url atomically:yes]; if (success == yes) nslog(@"suceeded"); else { nslog(@"failed"); } } return 0; }
2012-07-15 15:35:33.138 testplistmaker[996:403] url:file://localhost/users/m/desktop/testplist/h.txt
2012-07-15 15:35:33.140 testplistmaker[996:403] file contents: test.
2012-07-15 15:35:33.140 testplistmaker[996:403] failed
appreciate input.
see reference doc nsarray's writetoxxx methods. types of objects (i.e. classes) supported? object 1 of supported types?
property list programming guide. read "what property list" heading under "about property lists".
Forums Macs Mac Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
- Get link
- X
- Other Apps
Comments
Post a Comment