Search code examples
iphonexcodecore-dataios-simulatorapple-watch

Testing Core Data in Watch extension on the simulator


I'm creating an apple watch app. I have created my shared framework, and the app extension. It all actually works pretty well, but when I try to query objects from my Core Data DB, i get only empty arrays.

I have already created the app groups, and made sure the DB is being saved. I just don't get any objects, or errors. However, i'm not even sure if this is testable in the simulator, since the phone AND the watch simulator don't run at the same time. I still don't have a physical watch to test so simulator is my only option.

How can I test querying CD objects from my apple watch extension? Thanks!


Solution

  • Here is a trick for testing both the watch and the phone on the simulator. As you pointed out, they cannot be debugged at the same time, but you can switch.

    Run the phone target, then run the watch app (the phone target will terminate). Now start the phone target manually from the simulator's springboard. You are now looking at the debugging information of the watch.

    To switch back and forth between the two running targets' debug output, go to Xcode and choose the desired process from the menu:

    Debug > Attach to Process > (wait a second or so for the processes to populate) > Your target (which should be listed on top under the heading "Likely Targets").