You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Xcode 11 Playground中使用图片?SwiftUI教程图片不显示求助

Fixing turtlerock.jpg Not Showing in Xcode 11 Playground (Mojave)

Hey there, I’ve dealt with this exact headache while learning SwiftUI on Mojave with Xcode 11 Playgrounds—super frustrating when you’re following the Apple tutorial step-by-step and the image just won’t show up. Let’s go through the most common fixes that got my image working:

  • Double-check how you added the image to Resources
    Playgrounds have a specific way to handle resources that’s easy to mess up. Do this instead of just dragging the file into the sidebar:

    1. Press Cmd + 1 to open the Project Navigator.
    2. Find your Playground’s Resources folder (it’s nested under the Playground file).
    3. Right-click the folder and select Add Files to "[Your Playground Name]".
    4. Select turtlerock.jpg, make sure Copy items if needed is checked, and click Add.
      This ensures the image is properly bundled with the Playground instead of just sitting in the same folder.
  • Verify your image reference code
    On Mojave’s Xcode 11 Playgrounds, the standard Image("turtlerock") sometimes doesn’t pick up the resource correctly. Try using this explicit approach instead:

    Image(uiImage: UIImage(named: "turtlerock")!)
    

    Also, triple-check the filename spelling and capitalization—Mojave’s file system might enforce case sensitivity here, so turtlerock.jpg vs TurtleRock.jpg will break things.

  • Clear Xcode’s Derived Data cache
    Playgrounds love to hold onto old cached resources. Clear it out:

    1. Open Xcode, go to Xcode > Preferences > Locations.
    2. Next to "Derived Data", click the small arrow to open the folder.
    3. Delete the entire folder (it’ll rebuild automatically when you reopen Xcode).
    4. Restart Xcode and your Playground, then run the code again.
  • Confirm the image itself isn’t corrupted
    Sometimes the issue is just a bad image file. Open turtlerock.jpg with Preview to make sure it loads properly. If it doesn’t, re-download the image from the Apple tutorial and try again.

  • Keep in mind Mojave’s SwiftUI limitations
    Remember, SwiftUI was officially released with Catalina—Xcode 11 on Mojave only has partial support. If all else fails, try closing the Playground’s preview pane, clicking the Run My Code button at the top, then re-opening the preview. Sometimes forcing a fresh run fixes the rendering glitch.

Hope one of these gets your turtle rock showing up—happy SwiftUI learning!

内容的提问来源于stack exchange,提问作者Maric Vikike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:02:00