すべてのデータ作成は で行われますExtensionDelegate.swift
。
問題は、 myExtensionDelegate.swift
getCurrentTimelineEntryForComplication
ComplicationController.swift
の関数の前に呼び出されないことです。
何か案は? ここに私のコードと詳細があります:
したがって、私の配列extEvnts
は my で空ですComplicationController.swift
:
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void)) {
let extEvnts = ExtensionDelegate.evnts
}
myExtensionDelegate.swift
はまだ呼び出されていないため、配列のデータが作成されます。
class ExtensionDelegate: NSObject, WKExtensionDelegate, WCSessionDelegate {
private let session = WCSession.defaultSession()
var receivedData = Array<Dictionary<String, String>>()
static var evnts = [Evnt]()
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
if let tColorValue = userInfo["TeamColor"] as? String, let matchValue = userInfo["Matchup"] as? String {
receivedData.append(["TeamColor" : tColorValue , "Matchup" : matchValue])
ExtensionDelegate.evnts.append(Evnt(dataDictionary: ["TeamColor" : tColorValue , "Matchup" : matchValue]))
} else {
print("tColorValue and matchValue are not same as dictionary value")
}
}
func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
if WCSession.isSupported() {
session.delegate = self
session.activateSession()
}
}
}
編集:
Apple によると、これは何か関係があるように見えますが、何らかの理由で、 を呼び出すことができないため、実際に実装する方法がわかりませんmydelegate.evnts
:
// Get the complication data from the extension delegate.
let myDelegate = WKExtension.sharedExtension().delegate as! ExtensionDelegate
var data : Dictionary = myDelegate.myComplicationData[ComplicationCurrentEntry]!
だから私はこのようなことを試しましたが、まだデータを取得していないため、まだ機能していません:
func someMethod() {
let myDelegate = WKExtension.sharedExtension().delegate as! ExtensionDelegate
let dict = ExtensionDelegate.evnts
print("ExtensionDel.evnts: \(dict.count)")
}