Post

Replies

Boosts

Views

Activity

Reply to How to code, in SwiftUI, for Notifications
Generally, SwiftUI is designed to work well with Combine. You can try something like this: struct ContentView: View { 		@State var accessibilityIsOn: Bool = false 		var body: some View { 				Text("This can be some complex View") 						.padding() 						.onReceive(NotificationCenter.default.publisher(for: UIAccessibility.voiceOverStatusDidChangeNotification)) { _ in 								self.accessibilityIsOn = UIAccessibility.isVoiceOverRunning 						} 		} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to Unable to install XCode on High Sierra 10.13.6
What version of Xcode are you trying to install? Xcode wiki - https://en.wikipedia.org/wiki/Xcode The maximum version of Xcode for macOS High Sierra Version 10.13.6 is Xcode 10.1, which you cannot use for building App Store apps. You have two options: Get Xcode 10.1 from More Downloads page - https://developer.apple.com/download/more/ and use it for studying. Upgrade your Mac to 10.15.4 or later (you may need to get a recent Mac which supports this version of macOS) and install the latest version of Xcode.
Dec ’20
Reply to Data chunking while handling streaming APIs
wether that chunking behaviour can be somehow prevented NO. That chunking is dependent both network environment and implementation details. You cannot make control over them. if not what would be the alternative to avoid having to handle buffering and appending bytes? No way. Buffering is the only option if you want to use intermediate results. You should better not think how to avoid, but better think how to do it better.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to Is there a way to use SIMD in Swift for better performance? (Question includes test code).
my testing down to a couple of brief XCTests Seems XCTest is not a good tool to measure micro performance. With this simple code: import Foundation import simd class MyClass { &#9;&#9;func measure1(code: ()->Void) -> Double { &#9;&#9;&#9;&#9;let start = clock_gettime_nsec_np(CLOCK_UPTIME_RAW)         code() &#9;&#9;&#9;&#9;let end = clock_gettime_nsec_np(CLOCK_UPTIME_RAW) &#9;&#9;&#9;&#9;let time = Double(end - start) / 1_000_000_000 &#9;&#9;&#9;&#9;return time &#9;&#9;} &#9;&#9;func measure(code: ()->Void) { &#9;&#9;&#9;&#9;var times: [Double] = Array(repeating: 0, count: 10) &#9;&#9;&#9;&#9;for i in times.indices { &#9;&#9;&#9;&#9;&#9;&#9;let t = measure1(code: code) &#9;&#9;&#9;&#9;&#9;&#9;times[i] = t &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;let avg = times.reduce(0, +)/Double(times.count)         print("average: \(String(format: "%.6f", avg)), values: \(times)") &#9;&#9;} &#9;&#9;func testPerformance_double() { &#9;&#9;&#9;&#9;//...Exactly the same as shown &#9;&#9;} &#9;&#9; &#9;&#9;func testPerformance_simd() { &#9;&#9;&#9;&#9;//...Exactly the same as shown &#9;&#9;} &#9;&#9; } let myObj = MyClass() print("testPerformance_double:") myObj.testPerformance_double() print("testPerformance_simd:") myObj.testPerformance_simd() The output: (Tested on Mac mini (2018), Xcode 12.3, macOS Command Line Tool project, Release settings.) testPerformance_double: xL: 0.6408629334044746, xR: 0.735714601868435, increment: 0.05068415313623026 average: 0.000156, values: [0.00023855, 0.000140175, 0.000211979, 0.000193554, 0.000178274, 0.000118627, 0.000157364, 0.000136575, 9.3264e-05, 9.3267e-05] last result: 35599.67430242713 testPerformance_simd: vL.x: 0.2631681036829726, vL.y: 0.026889765245537545, increment: 0.04897156513471709 average: 0.000156, values: [0.000269612, 0.000122409, 0.000192792, 0.000141103, 0.000124708, 0.00012638, 0.000124496, 0.000211614, 0.000122489, 0.000122688] last result: SIMD2<Double>(15474.766375371206, 40414.973240285304) (I have chosen one interesting result from a few tries, but no significant differences in all other tries.) I'm afraid your code is too simple to measure micro performance, Swift compiler would reduce many parts of code inside iteration. Performance improvement is a very interesting topic, but you may need some better ways to explore.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to Help with crash on iOS 14 only
 I have looked for everything modifying the UI and cannot find any place we modify the UI in the background thread. Many sort of issues may happen in multi-threaded contexts. You may need to check all thread-unsafe operations done in the background thread. Not only UI modification.
Topic: App & System Services SubTopic: Core OS Tags:
Dec ’20
Reply to Swift - Async calls in loop
the loop basically "pauses" until I fetch every detail information of the iterated object, add it into the dataSource Array and then continues with the next one Do you really need the "pauses"? If your dataAccessService accepts multiple API calls simultaneously, you can send multiple requests simultaneously and construct the result when the last data is received.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to Is there a way to use SIMD in Swift for better performance? (Question includes test code).
The SIMD average time is around 85% of the regular average - is that about what would be expected? It depends on many things. In your case, you use 2d vector operation which executes 2 scalar operations simultaneously. So, in an ideal best efficiency, you can expect 50%, are you OK with this? I too expected a little better than 85%, but I do not think it's too bad. With detailed examination of the generated codes, it could be a little better. But I recommend you to explore other Accelerate features if you want to improve the performance significantly,
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to Swift - Async calls in loop
I just don't know how to construct the result with each response of the sent requests. Thanks for clarification. Then using DispatchGroup may be a good choice. Two more things to clarify: Does your dataAccessService calls completionHandler always in the main thread? (To make your code thread-safe, this is a big issue.) What happens in case of communication error in fetchUserById? (To use DispatchGroup properly, you cannot ignore error handling.)
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to Opening an NSViewController as a Sheet
It is not clear how sheets of macOS are managed in SwiftUI. In my test project (exactly the same code as shown), the sheet had a size 700 x 200. I'm not sure if this works for you, but you can try setting the content size of the sheet window. &#9;&#9;override func viewWillAppear() { &#9;&#9;&#9;&#9;super.viewWillAppear() &#9;&#9;&#9;&#9;self.view.window?.setContentSize(CGSize(width: 200, height: 150)) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;messageLabel.stringValue = message &#9;&#9;}
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20