Sto imparando Swift e sono stato frustrato nel tentativo di capire come non riesco a caricare i file. Si scopre che il codice funziona in Xcode ma non funziona in un parco giochi. Qual è la ragione di questo?Il codice Swift 2.0 funziona in Xcode ma non in Playground
Ecco il codice:
func testFileLoad(){
let myFilePath: String = "/Users/clay/Desktop/test.txt"
let t: Bool = NSFileManager.defaultManager().fileExistsAtPath(myFilePath)
print(t)
let s: String = try! String(contentsOfFile: myFilePath, encoding: NSUTF8StringEncoding)
print(s)
do {
let p: String = try String(contentsOfFile: myFilePath, encoding: NSUTF8StringEncoding)
print(p)
} catch {
print("nope")
}
}
esecuzione in un modulo di test in Xcode, funziona correttamente e stampa quello che vorrei sperare alla console.
Test Suite 'Selected tests' started at 2015-08-05 14:24:15.977
Test Suite 'swiftgraphTests' started at 2015-08-05 14:24:15.978
Test Case '-[swiftgraphTests.swiftgraphTests testFileLoad]' started.
true
this is a test
this is a test
Test Case '-[swiftgraphTests.swiftgraphTests testFileLoad]' passed (0.001 seconds).
Test Suite 'swiftgraphTests' passed at 2015-08-05 14:24:15.979.
Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'Selected tests' passed at 2015-08-05 14:24:15.979.
Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.002) seconds
in un parco giochi, ottengo questo:
Che cosa sto facendo male qui? Sto usando il campo giochi in modo improprio?
è la cartella 'var' nel fascio di file del parco giochi? – Clay
Ho aggiornato la mia risposta con ulteriori dettagli su questa cartella. – Moritz