Sunday, 15 February 2015

osx yosemite - Swift: Can not use NSImage .imageNamed -



osx yosemite - Swift: Can not use NSImage .imageNamed -

i seeing imagenamed deprecated (or removed) available options when following:

var statusimage:nsimage? = nil self.statusimage = nsimage .imagenamed....

i have tried swift document provided apple , other placed.this seemed trivial not find solution imagenamed. missing something?

use init(named: string!) instead: phone call nsimage(named: "foo").

the compiler automatically remaps objc class methods named convenience constructors work swift initializers. if class method follows naming convention of convenience constructor (e.g. +[something thingwithfoo: bar:]), swift remaps initializer (e.g. phone call something(foo: afoo, bar: abar)). goes few methods apple identified working convenience constructor (as in case of imagenamed:).

in cases, if finish typing class-method-style phone call convenience constructor, compiler give error tells how it's been remapped:

class="lang-none prettyprint-override">error: 'imagenamed' unavailable: utilize object construction 'nsimage(named:)'

more generally, can @ autogenerated module "header" api symbol in xcode cmd-clicking symbol (e.g. nsimage) in editor, or in xcode's documentation viewer or online reference docs api, find swift syntax using it.

swift osx-yosemite

No comments:

Post a Comment