Swift playgrounds with UIImage

前端 未结 11 1868
轻奢々
轻奢々 2020-12-01 01:36

I am working with Xcode 6, and I\'m trying to recreate the code demoed during session 401 \"What\'s new in Xcode 6\". I\'ve added an image to Images.xcassets (called Sample)

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 02:39

    I had difficulty getting this setup for an iOS playground, as opposed to an OS X playground. Trying to do it using bundles and relative paths makes it more complicated.

    If you just want to get your hands on an image quickly, you can also just use absolute file path:

    On iOS:

    # iOS
    let absoluteImagePath = "/absolute/path/to/image.png"
    let image = UIImage(contentsOfFile: absoluteImagePath)
    

    And on OS X

    # OS X
    let absoluteImagePath = "/absolute/path/to/image.png"
    let image = NSImage(contentsOfFile: absoluteImagePath)
    

提交回复
热议问题