【发布时间】:2016-06-11 12:59:06
【问题描述】:
嘿,我在放置变量时遇到问题。 我如何使用我使用的变量,让我们在另一个函数“B”中的函数“A”中说。换句话说,在函数“B”中使用函数“A”中的变量
我有函数(“A”)来设置通知文本:
let sentence = textField.text! + " Some 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)
现在我必须在该变量中的另一个函数(“B”)中调用firstWord:
let predicate = CNContact.predicateForContactsMatchingName(firstWord)
我尝试在ViewDidLoad 和课外添加这些第一个变量sentence 和firstWord,但一无所获。我不断收到错误"found nil while unwrapping"
当用户像这样点击通知操作按钮时,我调用变量predicate的函数。
NSNotificationCenter.defaultCenter().addObserver(self, selector: "functionWhereIsPredicateVariable:", name: IDENTIFICATOR, object: nil)
我必须将firstWord 存储到NSUserDefaults 还是必须以其他方式进行??
【问题讨论】:
-
查看textField的outlet
-
我有点困惑...你能尝试更详细地解释一下吗?谢谢
标签: ios swift global-variables