Unable to compile array.writeToFile in Swift; but in ObjC its okay -
i'm going on assorted cocoa persistent-storage scenarios in swift.
objective-c version compiles out incident:
nsarray *ricarray = @[@"one",@"two",@"three"]; [ricarray writetofile:@"path" atomically:true]; however,
swift version doesn't work.
the compiler doesn't believe array has 'writetofile'.
let docs = nssearchpathfordirectoriesindomains(.documentdirectory,.userdomainmask,true) array let pathtofile = docs[0].stringbyappendingstring("/myfile.txt") var shoppinglist:[string] = ["eggs", "milk"] shoppinglist.writetofile(pathtofile, atomically:true) ...swift:267:5: '[string]' not have member named 'writetofile'
doing wrong?
[string] swift's native array implementation, not nsarray; swift's array not have writetofile() method. can, however, cast between two. should work:
var shoppinglist:[string] = ["eggs", "milk"] (shoppinglist nsarray).writetofile(pathtofile, atomically:true)
Comments
Post a Comment