Search code examples
swiftmacoscocoanstokenfield

Setting Token in NSTokenField


I want to set some tokens in a NSTokenField, when it appears.

Apple document says: setObjectValue:

I try to set tokens usign setObjectValue

tokenField.setObjectValue(["One","Two"])

but it doesn't´t compile.

What´s the correct method?


Solution

  • objectValue is a property defined in NSControl. In Objective-C, you can set a value to it, in both property notation or setter method setObjectValue:. But in Swift, you always need to use property notation -- simple assignment:

    tokenField.objectValue = ["One","Two"]