Posts

Post not yet marked as solved
1 Replies
1.5k Views
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.")
Posted Last updated
.
Post not yet marked as solved
5 Replies
786 Views
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?
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.8k Views
Are there any Apple or non-Apple examples of using SwiftUI with OAuth libraries (for Twitter access) on Github with MacOS instead of the ones already available for iOS?Thanks!
Posted Last updated
.
Post not yet marked as solved
0 Replies
955 Views
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) } }
Posted Last updated
.
Post not yet marked as solved
4 Replies
663 Views
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)
Posted Last updated
.