Post

Replies

Boosts

Views

Activity

How do you run AVSpeechSynthesizer from command-line Swift on MacOS?
This code doesn't work. What should I do when it stops prematurely? import Foundation import AVFoundation print("Hello, World!") var synthesizer = AVSpeechSynthesizer() let utterance = AVSpeechUtterance(string: "Hello World!") utterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.speech.synthesis.voice.samantha.premium") utterance.rate = 0.5 synthesizer.speak(utterance) print("Done.")
1
0
1.8k
Jan ’21
The Slider value doesn't connect to the animation
The State variable that is used for the stiffness.@State private var stiffnessAmount: CGFloat = 1The Slider here sets the value, range, and step size.Slider(value: $stiffnessAmount, in: 1...10, step: 1)Text with modifier for the animation doesn't change its stiffnessAmount even though the Slider above: Text("Look here!") .animation( Animation.interpolatingSpring(stiffness: Double(stiffnessAmount), damping: 0) .repeatCount(Int(animationCount), autoreverses: false) )I changed the value using the Slider during runtime and then animation stiffness doesn't change.Why is it not working?
5
0
1k
May ’20
MapKit in SwiftUI on iOS with Catalyst
I have the following snippet of SwiftUI code using MapKit for iOS using MacOS Catalyst mode. The output of the code shows a large white box with the MapKit but that is not shown in the MacOS version using Cocoa with NS instead of UI. What is the problem?import SwiftUI import MapKit struct ContentView: View { @State var date = Date() var body: some View { HStack { NavigationView { MapView() .edgesIgnoringSafeArea(.all) } VStack(alignment: .leading) { ... } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } struct MapView: UIViewRepresentable { typealias NSViewType = MKMapView // 1. func makeUIView(context: UIViewRepresentableContext<MapView>) -> MKMapView { MKMapView(frame: .zero) } // 2. func updateUIView(_ uiView: MKMapView, context: UIViewRepresentableContext<MapView>) { // 3. let location = CLLocationCoordinate2D(latitude: 30.0, longitude: 0.0) // 4. let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) let region = MKCoordinateRegion(center: location, span: span) uiView.setRegion(region, animated: true) // 5. let annotation = MKPointAnnotation() annotation.coordinate = location annotation.title = "Big Ben" annotation.subtitle = "London" uiView.addAnnotation(annotation) } }
0
0
1.1k
Apr ’20
What is the purpose of functions being first-class types in Swift 5+?
What is the purpose of functions being first-class types in Swift 5+?Where does this usage occur and in what hypothetical scenarios?The following example from The Swift Programming Language book on iBooks as follows:func makeIncrementer() -> ((Int) -> Int) { func addOne(number: Int) -> Int { return 1 + number } return addOne } var increment = makeIncrementer() increment(7)
4
0
822
Dec ’19