string - How to get first word from sentence in Swift -
i trying first word string
sentence variable. how that? have local notification , need use it's message first word variable, possible? localnotifications
use localnotificationhelper
library easier handling. maybe there logic problem not think so. more not know enough options in swift
language.
edit: have namefield.text!
in nsuserdefaults
array. need delete message first word array. right remove first object array not solution me because need delete namefield.text! array when localnotification pops out , user click on button.
here create notification message:
localnotificationhelper.sharedinstance().schedulenotificationwithkey("text", title: "see options(left)", message: namefield.text!+"some text", date: deadlinepicker.date, userinfo: userinfo)
now need message:namefield.text!
variable @ app launch.
this how trigger notification button actions:
nsnotificationcenter.defaultcenter().addobserver(self, selector: "somefunction:", name: identifier, object: nil)
you can split sentence using white space char , extracting first element.
let sentence = "what wonderful world" if let firstword = sentence.characters.split(" ").first.map(string.init) { print(firstword) // "what" }
Comments
Post a Comment