Hi,
I couldn't find how to make a BLEActor as it has to conform to NSObject in order to be a CBCentralManagerDelegate, so I made that into a class BLEManager. Then I want my BLEActor to own an instance of that class, and I made a protocol with for instance "func bluetooth(isConnected: Bool)". However, Xcode tells me having BLEActor conform to my protocol implementing that function breaks actor isolation. I thought that'd be good seeing that the object is owned by the actor. Seeing that the BLEManager can disconnect at any time, what would be a good pattern for it to tell my BLEActor about that? And likewise, what is a good pattern for my actor to inform the view models that are interested that a bluetooth connection is active or not?
Post
Replies
Boosts
Views
Activity
I have this SwiftUI code that builds a large UI view that's too big to fit on screen, so I've put it in a 2D scrollview. While this example is a grid, let's assume the content fills just as much but the items are more randomly placed.
When the view appears, I want it to start with having one of these items centered, in the case below the item with ID "(25,25)". This compiles fine, and looks fine by the docs, and runs, but does not scroll to the ZStack with ID "(25,25)".
Why does it not scroll to this ZStack?
The code was tested with both iOS 14 and iOS 15b1.
var body: some View {
ScrollViewReader { scrollView in
ScrollView([.horizontal, .vertical]) {
VStack(alignment: .leading, spacing: 0) {
ForEach(0..<50) { y in
HStack(alignment: .center, spacing: 0) {
ForEach(0..<50) { x in
ZStack {
Circle()
.frame(width: 35, height: 35)
.foregroundColor(.blue.opacity(0.5))
Text("(\(x),\(y)")
.font(.system(size: 8))
}
.id("(\(x),\(y))")
.offset(x: CGFloat(x * 25), y: CGFloat(y * 25))
}
}
}
}
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
scrollView.scrollTo("(25,25)")
}
}
}
}
In "Meet async/await in Swift", around 23.38, we see that we in SwiftUI can do a
.onAppear {
async {
self.image = try? await self.viewModel.fetchThumbnail(for: post.id)
}
}
However, we also hear in this session that an async function can be called on one thread and resumed on another. In the code above, we update UI state, and thus self.image must be updated on the main thread. What on this slide ensures that it is actually returned to the main thread?
Hi, I read that there was announced a Motion API for AirPods Pro with iOS 14. Could someone point me to the docs for that?