swiftui – Are there any complete examples of a watchOS companion app with an iOS app utilizing SwiftData and Xcode?

0
16
swiftui – Are there any complete examples of a watchOS companion app with an iOS app utilizing SwiftData and Xcode?


For the final couple of weeks I’ve been looking across the web for a complete instance of App Teams, watchOS companion apps, and WCSession. Oddly, there are nearly no detailed movies, articles, not even boards that delve deep into these subjects. It might be that what I’m on the lookout for is a bit particular, however I am certain that many have requested about this similar query as nicely.

To make clear, I am not on the lookout for sure web sites that go over these subjects seperate of their context. I am on the lookout for one thing extra particular to my wants and probably to numerous different people who find themselves on the lookout for one thing that particular as nicely. I am going to present some instance code to assist those that want to write the reply.

Edited: The instance I might give is an individual having the ability to add their worker title and wage from their iPhone. That knowledge can then be seen on their Apple Watch. Odd instance. however it will get the purpose throughout.

import SwiftData

@Mannequin
class Individual {
    var title: String
    var age: Int
    
    init(title: String, age: Int) {
        self.title = title
        self.age = age
    }
}

@Mannequin
class Worker {
    var jobTitle: String
    var wage: Double
    var individual: Individual // Relationship
    
    init(jobTitle: String, wage: Double, individual: Individual) {
        self.jobTitle = jobTitle
        self.wage = wage
        self.individual = individual
    }
}

Here is a Swift file with WCSession for the Apple Watch with what I consider is important.

import Basis
import WatchConnectivity

class WatchToiOSConnector: NSObject, WCSessionDelegate, ObservableObject {

var session: WCSession

init(session: WCSession) {
    self.session = session
    tremendous.init()
    session.delegate = self
    session.activate()
}

func session(_ session: WCSession, activationDidCompleteWithactivationState: WCSessionActivationState, error: (any Error)?) {
   
}

func SendNeedListToiPhone() {
        
    }
    
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here