2014-06-06 50 views
2

我在我的項目中創建了一個快速的操場。但是當我添加此關於在雨燕遊樂場UIImage

var img2 = UIImage(named : "Demo") 

它給了我下面的控制檯輸出:

Playground execution failed: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation. * thread #1: tid = 0xac9f4, 0x00000001001a8797 libswift_stdlib_core.dylib (anonymous namespace)::getImplementationForType(swift::Metadata const*, swift::OpaqueValue const*) + 247, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x20) * frame #0: 0x00000001001a8797 libswift_stdlib_core.dylib (anonymous namespace)::getImplementationForType(swift::Metadata const*, swift::OpaqueValue const*) + 247 frame #1: 0x00000001001a8416 libswift_stdlib_core.dylib swift_reflectAny + 198 frame #2: 0x000000010033d603 PlaygroundLogger PlaygroundLogger.PlaygroundObjectWriter.encode_object (PlaygroundLogger.PlaygroundObjectWriter)(A, Swift.String) ->() + 707 frame #3: 0x000000010031ba5f PlaygroundLogger`playground_log + 319 frame #4: 0x000000010bafa174

我Images.xcassets添加的圖像。我可以在.swift文件中運行此代碼,但不能在我的.playground中運行。

我嘗試更改遊樂場設置中的資源路徑。只有「無」選項可以運行,別人給我的錯誤信息:

"Playground execution terminated because the playground process exited unexpected"

+0

爲什麼這會降低投票率?對我來說這似乎是一個很好的問題。 – phatmann

回答

1

嘗試重置您的遊樂場設置和輸入完整的路徑,在這裏你存儲的圖像。

var img2 = UIImage(named: "path/to/the/image") 

現金Swift playgrounds with UIImage

+0

我認爲現在可以。但我必須重置我的遊樂場設置,並重新啓動我的Xcode 6。代碼現在可以運行。 Thx爲您的幫助 – user3714585

+1

如果一切正常,您可以繼續並通過接受此答案來關閉此問題:) – mstottrop

3

在「文件檢查器」去「遊樂場設置」,然後選擇「資源路徑」 - >「絕對路徑」,再下面有文件夾圖標,點擊它。它會打開「Finder」,現在你可以選擇你的資源/圖像文件夾並點擊「選擇」。你可以像下面一樣使用圖像名稱和我們的擴展名:

let image = UIImage(named:"photo1")