The following code does not work in an Xcode Playgrounds or the Swift Playgrounds App on iOS oder macOS.
But the same code works when used in an app.
Does anyone know how to get the notifications running in a Playground?
import GameController
import Combine
import SwiftUI
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
var cancellables = Set<AnyCancellable>()
NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidConnect)
.subscribe(on:DispatchQueue.global())
.print()
.receive(on: DispatchQueue.main)
.sink { notification in
print(notification)
}.store(in: &cancellables)
let disConnect = NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidDisconnect)
.print()
.subscribe(on:DispatchQueue.global())
.receive(on: DispatchQueue.main)
.sink { value in
print(value)
}.store(in: &cancellables)
Post
Replies
Boosts
Views
Activity
In my TestApp I run the following code, to calculate every pixel of a bitmap concurrently:
private func generate() async {
for x in 0 ..< bitmap.width{
for y in 0 ..< bitmap.height{
let result = await Task.detached(priority:.userInitiated){
return iterate(x,y)
}.value
displayResult(result)
}
}
}
This works and does not give any warnings or runtime issues.
After watching the WWDC talk "Visualize and optimize Swift concurrency" I used instruments to visualize the Tasks:
The number of active tasks continuously raises until 2740 and stays constant at this value even after all 64000 pixels have been calculated and displayed.
What am I doing wrong?
With
struct ContentView: View {
var body: some View {
Rectangle().fill(ImagePaint(image: Image(systemName:"circle.fill").renderingMode(.template),
sourceRect: CGRect(origin: CGPoint.zero, size:CGSize(width: 100, height: 100)),
scale: 0.009)).foregroundColor(.red)
}
}
I could draw a rectangle filled with small circles before iOS 15 (last year's update). Since then this does not work any more and I only get "white on white" circles.
Searching on Google for a solution only yields very few examples using ImagePaint at all and all of them are from before iOS 15.
How can I get the desired result working again?
I know how to install gestures on an object in ARView like this:
let worldAnchor = AnchorEntity(world: [0,0,0])
arView.scene.addAnchor(worldAnchor)
worldAnchor.addChild(myObject)
myObject.generateCollisionShapes(recursive: true)
arView.installGestures(for: myObject)
Unfortunately this does not behave very intuitive. I would like to have the same rotation and scale behaviour like when previewing a .reality file in Xcode oder Quicklook.
How do I achieve this?