xcode - Swift Playground - Files are not readable -
files not readable in swift playground.
how make files readable?
same code runs on xcode terminal app, fails on swift playground.
demo code below.
import foundation println("hello, world!") var fname:string = "/users/holyfield/desktop/com.apple.iconcomposer.plist" var fm:nsfilemanager = nsfilemanager.defaultmanager() if(fm.fileexistsatpath(fname)){ println("file exists") if(fm.isreadablefileatpath(fname)){ println("file readable") var fd:nsdata? = nsdata(contentsoffile: fname) println(fd?.length) let pl = nsdictionary(contentsoffile: fname) println(pl?.count) println(pl?.allkeys) }else{ println("file not readable") } } else{ println("file not exists") }
sample images:
i have thank nate cook first quick response , solid answer.
just case share answer post, title misleading.
see nate's answer here: https://stackoverflow.com/a/26723557/2360439
playgrounds sandboxed, won't able grab files anywhere in user folder. here's how add file playground make accessible:
- find ".playground" file in finder right click , choose "show package contents"
- you should see "timeline.xctimeline", "contents.xcplayground", , "section-1.swift"
- make new folder called "resources" if doesn't exists yet.
- copy files resources folder
seems there no way access files swift playground outside of playground sandbox. if know how access files outside of sandbox, welcome share solution!!
Comments
Post a Comment