ios - Why I am getting nil while unwrapping an Optional value when I eliminated all nil_s? -


hey have problem placing variables. how can use variables use lets in function "a" in function "b". in word use variables function "a" in function "b"

i have function("a") set notification text:

let sentence = textfield.text! + " beautiful text!"  let firstword = sentence.characters.split(" ").first.map(string.init)  localnotificationhelper.sharedinstance().schedulenotificationwithkey("sometext", title: "see options(left)", message: sentence, date: deadlinepicker.date, userinfo: userinfo) 

now gotta call firstword inside function("b") in variable here:

let predicate = cncontact.predicateforcontactsmatchingname(firstword) 

i tried add first variables sentence , firstword in viewdidload , outside of class nothing. keep getting error "found nil while unwrapping" call function variable predicate when user tap notification action button this.

nsnotificationcenter.defaultcenter().addobserver(self, selector: "functionwhereispredicatevariable:", name: identificator, object: nil) 

do have store firstword nsuserdefaults or have in way??

you can save name userinfo

let userinfo = ["url" : "hello","name":namefield.text!]  //set notification                 localnotificationhelper.sharedinstance().schedulenotificationwithkey("tempco", title: "see options(left)", message:namefield.text!+" contact needs deleted!", date: deadlinepicker.date, userinfo: userinfo) 

then can notification's object , post it.

func application(application: uiapplication, handleactionwithidentifier identifier: string?, forlocalnotification notification: uilocalnotification, completionhandler: () -> void) {     if identifier == deletecontact {         print("delete action - tapped")          nsnotificationcenter.defaultcenter().postnotificationname(deletecontact, object:notification.userinfo) 

and can name notification's object

//**delete contact function**\\ func contactdelete(notification : nsnotification){ let name:string? = notification.object?["name"]  as? string 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -