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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -