Unable to use NSFontManager methods in swift

489 Views Asked by At

In Xcode 6 Beta 6,

I am unable to use any NSFontManager methods in Swift. For example:

var fontManager = NSFontManager.sharedFontManager()

fontManager.setAction("changeFont:")

I always get the error: NSFontManager does not have a member named setAction

This occurs for any method (e.g. setDelegate, setTarget)

Thanks for any help.

1

There are 1 best solutions below

0
On BEST ANSWER

Try this:

fontManager.action = Selector("changeFont:")

Properties are set using the property syntax in Swift.

In ObjC, properties were declared with (if not using @property):

- (X) myProp { return ... }
- (void) setMyProp(X value) { ... }

In Swift, the property declarations look more like C#:

var myProp : X { get { return ... } set { ... } }

So you can't call the setter explicitly using the same method name as in ObjC (though I have actually no idea what it will be compiled into...).