Loading image resources
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