2014-06-06 48 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")