I have set up an iPhone app in Xcode and added a Cocoa-Touch iOS framework to handle the data as per apple's suggestion.
Basically, I've done everything in this tutorial:
http://www.telerik.com/blogs/send-data-to-apple-watch-with-core-data-and-telerik-ui-for-ios-in-swift
On the iPhone side it works fine calling the functions however if I try to call the exact same functions, I get this horrible error:
fatal error: unexpectedly found nil while unwrapping an Optional value
After doing some commenting out and running of the code line by line I have determined this is the offending line (same line is in both data handling functions):
var entity = NSEntityDescription.entityForName("ChartDataEntity", inManagedObjectContext: self.managedObjectContext!)
Any help or ideas appreciated!
I figured out what the issue was. I had added the files from the framework to the targets of the iphone app and also the watchkit extension, which Apple advises is not allowed anyway and they'll block your app from the store if you try to do it: https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html
Anyway if you come across this what you need to do is untick the targets (both the data model and the swift file):
From here:
So only your framework is ticked as a target. Now my watch app works with CoreData! That was a painful couple of days...