• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Loading image resources
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Loading image resources


  • Subject: Loading image resources
  • From: Charles Jenkins <email@hidden>
  • Date: Sat, 13 Sep 2014 15:28:00 -0400

Hi, everyone.

In my project’s images.xcassets, I created three image sets with these names:

Folder
SinglePage
MultiPage

Each one contains a single PNG image. Now I’m trying to load them into NSImages.

Here’s what doesn’t work:

  let folderImage: NSImage
  let singleDocumentImage: NSImage
  let multiDocumentImage: NSImage

  override init() {

    // Swift requires local properties to be initialized first

    theProject = DocumentNode.CreateSampleProject()

    folderImage = Document.getImageAsset( "Folder" )
    singleDocumentImage = Document.getImageAsset( "SingleDocument" )
    multiDocumentImage = Document.getImageAsset( "MultiDocument" )

    super.init()

  }

  class func getImageAsset( name: String ) -> NSImage {
    let bundle = NSBundle.mainBundle()
    let imageFileName = bundle.pathForResource( name, ofType: "png" )
    let img = NSImage( contentsOfFile: imageFileName )
    return img

  }


After calling bundle.pathForResource:ofType:, imageName is nil. I think what I’m doing is what the Resource Programming Guide says to do. How am I getting it wrong?

--
Charles Jenkins

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Loading image resources
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Singleton or class methods?
  • Next by Date: Re: Loading image resources
  • Previous by thread: Re: Singleton or class methods?
  • Next by thread: Re: Loading image resources
  • Index(es):
    • Date
    • Thread