Hi,
I'm just getting into using Combine with SwiftUI to update state. I have a test app I'm using to build a UI around Multipeer Networking. My Swift is a little rusty currently.
Here's some code to show the context of my problem...
Here's my controller object that for now handles the session, browser and advertiser. It's a BindableObject using a PassthroughSubject as Publisher.
class PeerDatasource: NSObject, BindableObject, MCSessionDelegate, MCNearbyServiceBrowserDelegate, MCNearbyServiceAdvertiserDelegate {
typealias PublisherType = PassthroughSubject
var didChange = PassthroughSubject<Void, Never>()
private var session: MCSession?
var peers: [MCPeerID] {
if let session = self.session {
return session.connectedPeers
}
return [MCPeerID]()
}
var browser: MCNearbyServiceBrowser?
var advertiser: MCNearbyServiceAdvertiser?
//rest of class...
}
Upon a peer changing state I call didChange like so...
func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
DispatchQueue.main.async(execute: {
self.didChange.send(())
})
}
In my Swift UI I have the following code that creates a List of PeopleCell objects in a NavigationView...
struct PeopleList : View {
@ObjectBinding var peerDatasource = PeerDatasource(peerName: "Rob")
var body: some View {
NavigationView {
List {
ForEach(peerDatasource.peers.identified(by: \.displayName) { peer in
PersonCell(peer: peer)
}
}
}.navigationBarTitle(Text("Nearby"))
}
}
The problem I have is in this last section where I get two errors I can't work out how to resolve:
1. Missing argument for parameter 'content' in call, Insert ', content: <#(Data.Element.IdentifiedValue) -> Content#>' on line 09 and..
2. Expected ')' in expression list on line 10.
Can anyone help explain what I'm doing wrong.