Failed to send custom object using WatchConnectivity (swift)
<p>I was trying to pass my swift object from the iOS app to the Watch. However, I found it works for basic types like NSString, but my custom object type.</p>

<h2>My custom object is able to cast to NSData</h2>

<p>I've made my object implement NSObject and NSCoding, which works well. I can do following without problem:</p>

<pre><code>let encodedChordProgression = NSKeyedArchiver.archivedDataWithRootObject(chordProgressions[1])
let decodedChordProgression = NSKeyedUnarchiver.unarchiveObjectWithData(encodedChordProgression) as! ChordProgression
NSLog("get decodedChordProgression = \(decodedChordProgression.description)")
</code></pre>

<h2>WatchConnectivity code works for NSString</h2>

<p>In iPhone:</p>

<pre><code>try WatchSessionManager.sharedManager.updateApplicationContext(["data": "mystringishere"])
</code></pre>

<p>with Watch:</p>

<pre><code>dispatch_async(dispatch_get_main_queue()) { [weak self] in
    self?.dataSourceChangedDelegates.forEach { $0.dataSourceDidUpdate(applicationContext["data"] as! NSString)}
}
</code></pre>

<p>works.</p>

<h2>My custom object with WatchConnectivity Failed</h2>

<p>However, when I switch the object to my own object, it failed by not calling the <code>dataSourceChangedDelegates</code> callback function. That is:</p>

<p>In iPhone:</p>

<pre><code>let encodedChordProgression = NSKeyedArchiver.archivedDataWithRootObject(chordProgressions[1])
try WatchSessionManager.sharedManager.updateApplicationContext(["data": encodedChordProgression])
</code></pre>

<p>with Watch:</p>

<pre><code>dispatch_async(dispatch_get_main_queue()) { [weak self] in
    self?.dataSourceChangedDelegates.forEach { $0.dataSourceDidUpdate(applicationContext["data"] as! NSData)}
}
</code></pre>

<p>and</p>

<pre><code>func dataSourceDidUpdate(encodedChordProgression: NSData) {
    let chordProgression = NSKeyedUnarchiver.unarchiveObjectWithData(encodedChordProgression) as! ChordProgression
    NSLog("get something here: \(chordProgression.description)")
}
</code></pre>

<h2>What I've tried &amp; my problem</h2>

<p>I've tried to read the <code>system.log</code> of both the iPhone app and Watch app, but I couldn't find any clue, which is the biggest problem I have now.</p>

<p>The full code is: <a href="https://github.com/heronyang/ChordBox" rel="nofollow">here</a> (checkout <code>7f2a72c6004f6580e2a38a2d7fd0ed2cef8a2b2e</code>)</p>