Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the tokens from NSTokenField

I can get the value of a NSTokenField by doing [NSTokenField stringValue] but this does not return the tokens individually. What I'm trying to get is the token fields in an array i.e ['token', 'token2'].

I'm a bit ignorant when it comes to Cocoa/Objective-c so I wouldn't be surprised if I'm missing something obvious.

NSTokenField doesn't respond to count so I'm not sure if it's even possible to get the tokens back.

Thanks.

like image 380
K-2052 Avatar asked Feb 28 '12 21:02

K-2052


1 Answers

From the Apple documentation:

To retrieve the objects represented by the tokens in a token field, send the token field an objectValue message. Although this method is declared by NSControl, NSTokenField implements it to return an array of represented objects. If the token field simply contains a series of strings, objectValue returns an array of strings. To set the represented objects of a token field, use the setObjectValue: method, passing in an array of represented objects. If these objects aren’t strings, NSTokenField then queries its delegate for the display strings to use for each token.

like image 157
Roger Avatar answered Oct 23 '22 09:10

Roger