Question for swift developers about watchKit

App Development & Programming

Hello there,
I am a very new swift developer, just learning the ropes. Forgive me for this question that may seem simple, but is really confusing me.
I'm currently developing a watch OS (only) app. There are 2 targets in my build: the WatchKit app and WatchKit extension.
I'm developing in Swift UI, however Swift UI doesn't allow for detecting shake so I'm resorting to UIKit and bridging the 2 views.
I have set up a view in UIKit that can handle detecting shakes (in my WatchKit app portion, since that's where storyboard components must go). But now I am finding it impossible to communicate with that from the WatchKit extension side (since that's where program logic needs to go).
Can someone walk me through how to set up a WKInterfaceObject (which seems to be how you're supposed to do this)? I cannot for the life of me figure it out. thanks!



Submitted by Weather Gods (Scott) on Sunday, January 17, 2021

Hi Techluver,

Haven't done this myself but I did find an example project which seems to indicate the shape detection goes in the extension.

For Weather Gods we just have the UI in the UI part and the extension acts as the controller handling input from the user and outputting data to the screen from our weather models.

Not sure what the goal is but I think you can detect the shake in the controller and then update your UI accordingly.

Submitted by techluver on Monday, January 18, 2021

In reply to by Weather Gods (Scott)

I did see this example. I appreciate the help.
The issue is that my layout is written in swift UI. The shake detection, however, must fit in the UIKit portion.
Since UIKit storyboards aren't very accessible, (the drag and drop and things like that), I had to learn swift UI from the get, which means I'm super unfamiliar with getting UIKit views to play nicely with Swift UI.
Would it be possible for us to connect offline for maybe having you look at my code? I know this is a lot to ask, but I'm not sure what I'm doing anymore. I'm willing to pay a little for your time, but I just can't seem to find anyone who's dealt with the watch stuff before.
Thank you so much.

Submitted by Weather Gods (Scott) on Monday, January 18, 2021

Of course, no need for payment, happy to help a fellow developer.

Do you have the project in Github?

I really appreciate this. I've been messing around, and I can get it to compile, but it can't detect shakes, and I have absolutely no idea why.
I don't have a project in GitHub, but I'm happy to e-mail you the project source. (It's a free app anyway, so sending source files around doesn't bother me.)
Where should I send it?