2

I created a swift playground in my project. But When I add this

var img2 = UIImage(named : "Demo")

It gives me the following Console Output:

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.dylibswift_reflectAny + 198 frame #2: 0x000000010033d603 PlaygroundLoggerPlaygroundLogger.PlaygroundObjectWriter.encode_object (PlaygroundLogger.PlaygroundObjectWriter)(A, Swift.String) -> () + 707 frame #3: 0x000000010031ba5f PlaygroundLogger`playground_log + 319 frame #4: 0x000000010bafa174

I added the image in Images.xcassets. I can run this code in my .swift file, but not in my .playground.

I try to change the Resource Path in the playground settings. Only 'None' option can run , the others give me the error message:

"Playground execution terminated because the playground process exited unexpected"

mstottrop
  • 589
  • 5
  • 21
user3714585
  • 111
  • 1
  • 3

2 Answers2

3

Under "File Inspector" go to "Playground Settings" and select "Resource Path" -> "Absolute path", and below that there is the folder icon, tap on it. it will open the "Finder", now you can select the your Resource/Images Folder and tap "Choose". you can just use the image name with our extension like below:

let image = UIImage(named:"photo1")
Keshav
  • 2,965
  • 3
  • 25
  • 30
1

Try resetting your Playground settings and enter the full path, where you stored the image.

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

Credits: Swift playgrounds with UIImage

Community
  • 1
  • 1
mstottrop
  • 589
  • 5
  • 21
  • I think it is ok now . But I must reset my playground setting , and reboot my Xcode 6 . The code can run now . Thx for your help – user3714585 Jun 06 '14 at 10:50
  • 1
    If everything works for, you can go on and close this issue by accepting this answer :) – mstottrop Jun 06 '14 at 13:05