Posts

Post not yet marked as solved
1 Replies
767 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
358 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.3k 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
791 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
421 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
.
Post not yet marked as solved
0 Replies
354 Views
The Timer on WatchKit doesn't execute the lblTimer.setText("(currentTime)") properly when it is there in the function called when the timer fires. What should I do to fix this problem? The label is just static and should be updated very often. Does the watchOS simulator have a bug?Also, I tried the Timer from watckKit and that didn't work either.Here's the sample code where the lblTimer.setText doesn't execute on the screen:@objc func fire() { print(countDown) if (countDown <= 0.0) { timer?.invalidate() speechSynthesizer?.speak(AVSpeechUtterance(string: "You ran out of time! Next question!")) countDown = 30.0 lblTimer.setText("30.0") } else { countDown -= 0.01 let numberOfPlaces = 2.0 let multiplier: Float = Float(pow(10.0, numberOfPlaces)) let num: Float = countDown let rounded = round(num * multiplier) / multiplier lblTimer.setText("Time: \(rounded)") print(rounded) } }
Posted Last updated
.