基本的に、配列をうまく渡しています。列挙された配列をテーブル行として使用しようとすると、nil found と表示されます。
電話
import UIKit
import WatchConnectivity
class ViewController: UIViewController, WCSessionDelegate {
@IBOutlet weak var sendButton: UIButton!
var watchSession: WCSession?
var arrayCustom = ["thing1", "thing2"]
override func viewDidLoad() {
super.viewDidLoad()
if(WCSession.isSupported()) {
watchSession = WCSession.defaultSession()
watchSession?.delegate = self
watchSession?.activateSession()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func sendArray(sender: AnyObject) {
sendToWatch()
}
private func sendToWatch() {
do {
let applicationDict = ["Array1": arrayCustom]
try WCSession.defaultSession().updateApplicationContext(applicationDict)
}
catch {
print(error)
}
}
}
ウォッチキット
private func loadThCust() {
if (WCSession.isSupported()) {
watchSession = WCSession.defaultSession()
watchSession.delegate = self;
watchSession.activateSession()]
}
func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]) {
dispatch_async(dispatch_get_main_queue()) { () -> Void in
if let retrievedArray1 = applicationContext["Array1"] as? [String] {
self.custArray = retrievedArray1
print(self.custArray)
}
for (index, thName) in self.custArray.enumerate() {
let row2 = self.choiceTable.rowControllerAtIndex(index) as! ChoiceTableRowController
row2.choiceLabel.setText(thName)
}
}
}
私の問題は、TableView をロードしようとするたびに、このコンソール出力 + エラーが発生することです。
["thing1", "thing2"]
2016-02-24 03:21:25.912 WristaRoo WatchKit Extension[9401:243561] Error - attempt to ask for row 0. Valid range is 0..0
fatal error: unexpectedly found nil while unwrapping an Optional value
アンラップされた値がまだゼロである理由を誰かが知っていますか? 設定して[String]配列に値があることを確認できたら、それを列挙できることを望んでいましたが、それらは見えないようです。