On second time I tap button I do not have value anymore. How to Load variable on every app load. The variable I am talking about is changing since it is always textField.text!
and it is user input. I use it when user taps LocalNotification
action, app opens and then function triggers like this:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "someFunctionWhereIsMyProblematicVariableINeedToLoad:", name: IDENTIFIER, object: nil)
How to stick the variable every time user enters it, into local notification. Are every notification somehow different or just text changes?Are there any ID-s to make every notification special?
LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey("someText", title: "see options(left)", message:textField.text!+"someText", date: deadlinePicker.date, userInfo: userInfo)
I need that textField.text
to be in this variable: let predicate = CNContact.predicateForContactsMatchingName(textField.text!)
I tried to store them into NSUserDefaults
and into arrays and loop through arrays
to find if value exists etc. But It works only first time and second time it is nil
Edit: It keeps only the last entered value as variable. How to keep them all?
Here I show you in the pictures what I tried to explain with words:
Now if blue button is tapped I start function where I need to use the "firstTimeEntered" as variable but at the second notification it is"SecondTimeEntered"
Variables class scope:
var sentence:String = ""
var firstWord = [String]()
var firstWordAsString:String = ""
Function "A":
sentence = textField.text! + " needs to be deleted from array."
var firstWordAsString = sentence.characters.split(" ").first.map(String.init)
firstWord.append(firstWordAsString!)
defaults.setObject(firstWord, forKey: "firstWord")
let userInfo = ["url" : "Hello"]
//Set notification
LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey("someText", title: "see options(left)", message: sentence, date: deadlinePicker.date, userInfo: userInfo)
Function "B":
defaults.objectForKey("firstWord") as? String
if contacts.contains(firstWordAsString){
let predicate = CNContact.predicateForContactsMatchingName(firstWordAsString)