caxix caxix - 6 months ago 4x
Swift Question

Params to objective-c singleton from swift

So I have an objective-c singleton that I am calling from swift. The project has a Bridging-Header and calling the printValue: method with an explicit value works fine:

SingletonTester.sharedInstance().printValue(64) // works fine

But - parameterizing this call gives me an error:

let note = 64
SingletonTester.sharedInstance().printValue(note) // doesn’t compile

Error: ViewController.swift:21:46: Cannot call value of non-function type '((UInt) -> Void)!'

Real noob issue, but it’s got me flustered.



It appears your value is the wrong type. The printValue function is expecting a UInt, but when you say let note = 64, the compiler assumes Int by default. You can do this:

let note: UInt = 64

Or this:

let note = 64