xcode - Store/Associate NSMenuItems along with folder URLs -
so i'm new oo programming. coming webdesign background , having done design work or more or less intermediate scripting wherever needed in projects. being eager learn , still searching "right" way ;-) things guys do. not script kiddie mind tells me :d. sorry if super beginner question, rather grasp "right" concept start.
i'm programmatically populating nsmenu nsmenuitems based on contents of folder located in documents directory. i'm iterating through subfolders of fellow, getting url of each , every one, extracting folder name using
let folder = el.urlbydeletingpathextension?.lastpathcomponent
and creating nsmenuitems based on names
let menuitem = statusmenu.insertitemwithtitle(folder!, action: #selector(statusmenucontroller.dofancystuff), keyequivalent: "", atindex:0)"
so far good. how store associated url along menuitem later use manipulating when action gets triggered?
by clicking on item want action performed, needs full folder url of course. first idea extend nsmenuitem new variable called "path" or so. since there no stored values allowed in extensions dead end.
how real programmers handle such cases? using dictionary , storing items along respective urls? work, or not? correct way? or getting full url taking menuitems title , "reattaching" basefolder url? work. or hand url method/action called attribute? love stay away messy code :) pro insights appreciated.
thank time! andy
nsmenuitem
has property representedobject
can used purpose.
from documentation:
by setting represented object menu item, make association between menu item , object. represented object functions more specific form of tag allows associate object, not arbitrary integer, items in menu.
if want store more information url assign collection object array
or dictionary
or custom class representedobject
.
Comments
Post a Comment