osx - Binding an NSTableView to an array of strings in Swift -


i'm showing contents of array of strings nstableview via binding through array controller.

i have "nsstring" in class name in attributes inspector array controller , in model key path of array controller's binding inspector have path array. , have column of table bound in value section array controller without model key path specified (it's array of strings).

as result, array's strings displayed fine in table. can't edit of rows:

2015-06-17 15:48:44.285 projectname[9043:123132] uncaught exception raised 2015-06-17 15:48:44.285 projectname[9043:123132] error setting value key path  of object 5 (from bound object <nstablecolumn: 0x618000082d50>    identifier: (null)): [<swift._nscontiguousstring 0x608000045d60> setvalue:forundefinedkey:]: class not key value coding-compliant key . 

"five" fifth string in array trying edit. , can see there gap in "path of" because model key path empty column's values.

so somehow refer string in model key path make array editable via table?

the class name should absolutely set valid class. bigger problem array controller doesn't play nicely arrays of strings. there's no (reasonable) way use -setvalue:forkey: on string since string what's being edited (replaced), not property (like "displayname").

i know seems wasteful, if must use array controller (more on in moment), should create class string property , set that controller's class name , maintain array of class instead of plain strings. array of strings represents tags. make tag class name property of type string (or nsstring). set controller's class name tag. way, there's key path bind.

but if don't see needing array of strings, use standard (and infinitely more flexible) [nstableviewdatasource][1] protocol , old-fashioned actions triggered buttons (like add , remove). way you're not fighting cocoa bindings / kvc / kvo mechanisms in case amounts too-primitive type (string) abstract controller.

as amount of work, it's "six of 1 half-dozen of other" not quite -- i'd go "make class name property" route 2 reasons: 1) it's less work spinning whole table controller / data source, , 2) it's you'll later wish had more extensible class instead of simple string "list of stuff" if don't think now.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -