ios - Using NSUserDefaults to share data to watchkit -
i trying use nsuserdefaults
share data watchkit files. trying have when button function executed watchlabel.settext
data array. array , function selects data created in ios application. (unfortunately many resources come across in objective-c or extremely vague.)
i have set app groups both ios , watchkit
in ios swift file trying share array(arraybook) , function(.randomdata) use watchkit controller. ps: have no compiler errors.
let shareddefaults = nsuserdefaults(suitename: "group.applewatchtest") shareddefaults?.arrayforkey(arraybook.randomdata()) shareddefaults?.synchronize()
watchkit controller; unsure correct syntax fetching data , setting label random string array. - within uibutton func.
let shareddefaults = nsuserdefaults(suitename: "group.applewatchtest") let sharedarray = shareddefaults?.arrayforkey("shared") watchlabel.settext(arraybook.randomdata())
where going wrong when fetching data set label data array stored in ios application.
shareddefaults?.arrayforkey(arraybook.randomdata())
this line of code not doing anything. you're reading array defaults, using key of whatever arraybook.randomdata()
returns, , doing nothing it.
i assume want like
shareddefaults?.setobject(arraybook, forkey:"shared")
which write array defaults. out in watch (which looks fine) , random value using randomdata()
.
Comments
Post a Comment