Post

Replies

Boosts

Views

Activity

Reply to Identifying UIKit Api's failure
suppose If there is a case where it fails due to insufficient memory. To address that point specifically: (On iOS), When memory is low, apps get memory warnings and should free resources. If that’s not enough, suspended apps will be terminated. The only situation where you will really run out of memory is if you ask for a ridiculously large allocation, and that indicates a bug in your program. (The same is also true on other platforms, except embedded systems without virtual memory. Unless you run out of virtual address space, memory allocations will always succeed even when physical RAM is exhausted; the problem is dealt with by other mechanisms, such as Linux’s “OOM Killer”. Personally, in my C++ code I assume that memory allocation cannot fail.) More generally: if the API has some way of reporting an error, try to handle it; if it doesn’t, assume that it cannot fail for valid parameters.
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’24
Reply to SwiftUI Entry Point - Proper Location In Project
I can’t really answer your questions, because the don’t make much sense. It sounds to me as if you have tried to learn Swift and SwiftUI by reading random bits of code and trying to work out what they mean by looking for connections with other languages. Sorry, that’s not going to work. Now in the SwiftUI project, I tried this... What do you actually want to happen? Presumably you want it to print “hi” at some point. When do you want it to do that? If you want it to print “hi” when a ContentView struct is created, put it in an init method.
Dec ’24
Reply to SimpleWatchConnectivity sample - modernizing it
I think you'd need to schedule a snapshot refresh if the WatchConnectivity background task updates your UI Or maybe not, according to the docs at https://developer.apple.com/documentation/watchkit/preparing-to-take-your-watchos-app-s-snapshot If your app uses the SwiftUI BackgroundTask tasks, the system automatically detects any changes to the user interface and schedules the snapshot task.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’24
Reply to SimpleWatchConnectivity sample - modernizing it
Many thanks! Here is the skeleton of what I have; any comments? In particular, should I be doing anything in the .backgroundTask(.watchConnectivity)? import Foundation; import SwiftUI; import WatchConnectivity; @Observable class Stats { var data: [String: Any] = [:]; }; struct StatsView: View { @Environment(Stats.self) private var stats; var body: some View { VStack { Text(stats.data.description) } } }; class SessionDelegate: NSObject, WCSessionDelegate { private var stats: Stats; init(stats: Stats) { self.stats = stats; } func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: (any Error)?) { // TODO check state, error, etc. stats.data = session.receivedApplicationContext; } func session(_ session: WCSession, didReceiveApplicationContext application_context: [String: Any]) { stats.data = session.receivedApplicationContext; } }; @main struct MyWatchApp: App { private var stats: Stats = Stats(); private var session_delegate: SessionDelegate; init() { assert(WCSession.isSupported(), "WCSession is not supported, hmm, when does this happen?"); session_delegate = SessionDelegate(stats: stats); WCSession.default.delegate = session_delegate; WCSession.default.activate(); } var body: some Scene { WindowGroup { StatsView() .environment(stats) } .backgroundTask(.watchConnectivity) { } } };
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’24
Reply to Overall Code Structure Of Swift Project
I’m going to mention the Swift Package Manager: https://www.swift.org/documentation/package-manager/ https://www.swift.org/getting-started/cli-swiftpm/ If you’re looking for something that’s closer to cargo run or make; make install than the full Xcode experience, this may be worth looking at. Question for the experts: to what extent is the Swift Package Manager “compatible” with Xcode? I.e. can I have a single source tree that’s usable by both? P.S. I’d be interested to hear your thoughts about C# vs. Rust vs. Swift generally.
Dec ’24
Reply to Causes of disordered dictionary in Swift
At each new for loop we get a random order of element That surprises me. Please post more code. In particular, are you calling test() on the same object each time, or are you creating a new Test object? The source for the swift dictionary is here: https://github.com/swiftlang/swift/blob/main/stdlib/public/core/Dictionary.swift It start with a lot of comments which you might like to read. In particular, at line 331: The order of key-value pairs in a dictionary is stable between mutations but is otherwise unpredictable. There are data structures that can change order between uses - for example, splay trees reorganise themselves so that recently- or frequently-used elements will be found more quickly. I don’t believe that the Swift dictionary is such a data strucutre.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’24
Reply to DPLA notification [Urgent help please]
Posts like yours appear here on the forum quite frequently, and I don't recall anyone ever reporting that they managed to save their account from termination. Now that could be because people are rude and lazy and don't bother to post when that happens. Or it could be that once "the algorithm says NO", you really cannot fix it. Or, maybe I just don't remember the stories with the happy outcomes. @MenoM3ayPP, do us all a favour and report back! Apple reported that they had terminated 428,000 developer accounts "for fraud" in 2022: https://www.apple.com/uk/newsroom/2023/05/app-store-stopped-more-than-2-billion-in-fraudulent-transactions-in-2022/ Yes, almost half a million accounts. Presumably you are one of those for 2024. Remember everyone, make sure you have another job that will pay your mortgage when Apple takes away your App Store income. Make sure you still have non-Apple skills on your CV that you can revery to quickly.
Dec ’24
Reply to New subscription renewal rate in TestFlight
the 5-minute auto-renewal for weekly subscriptions was an excellent solution. Well it might be good if you’re only testing the subscription renewal process, but if you want your beta testers to evaluate anything else they are going to be totally distracted by the constant subscription noise. Is there a way to adjust the auto-renewal timing This is what we really need. ”File a bug”, ha ha ha.
Topic: App & System Services SubTopic: StoreKit Tags:
Dec ’24