Swift save an array of strings to NSUserdefaults and reuse for notification.alertbody text

倖福魔咒の 提交于 2019-12-13 04:50:26

问题


i am working on a notification project, see this: Swift notification fire from datePicker

The problem is this: i have a variable

item = news.titleNews 

(in ViewController.Swift) that is a list of strings like this:

one

two

three

etc..

i am converting this variable to an array like this:

myArray = [item]

and saving to NSUserDefaults like that:

NSUserDefaults.standardUserDefaults().setObject(myArray, forKey:"myArray")
NSUserDefaults.standardUserDefaults().synchronize()

then in settings.swift if i put:

 localNotification.alertBody = NSUserDefaults.standardUserDefaults().objectForKey("myArray")

i receive only nil...or if i pass through NSUserdefaults only item string my notification is only one corresponding to first string! i want a notification for each string of my strings list. Thank you in advance for the Help.

来源:https://stackoverflow.com/questions/34257339/swift-save-an-array-of-strings-to-nsuserdefaults-and-reuse-for-notification-aler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!