Post

Replies

Boosts

Views

Activity

Behaviour of .onAppear/ .onDisappear inside ScrollView
In the code snippet below, .onAppear is triggered on app launch for the 1st Text view. It fires again for the 2nd Text view when scrolled to be visible. Scrolling back to the 1st does not fire .onAppear. .onDisappear is not triggered at all, neither for the 1st Text view after scrolling to the 2nd nor vice versa. Is this intended behavior? Any ideas how to trigger .onAppear/ .onDisappear when repeatedly scrolling the views to be visible/ invisible? I'm using iPadOS 16.1 and Swift Playgrounds 4.2. import SwiftUI struct ContentView: View {     var body: some View {         ScrollView(.horizontal, showsIndicators: false) {             LazyHStack {                 Text("1st")                     .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)                     .onAppear(perform: { print("1st appeared") })                     .onDisappear(perform: { print("1st disappeared") })                 Text("2nd")                     .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)                     .onAppear(perform: { print("2nd appeared") })                     .onDisappear(perform: { print("2nd disappeared") })             }         }     } }
1
0
883
Nov ’22
Settings.bundle does not appear in Settings App
I have two apps, both made on iPad with Swift Playgrounds 4. The newer one was made with the latest release of SP4 and thus uses Swift 5.6, the other uses Swift 5.5 because it was made with a former version of SP4. iPadOS is 15.7. Both apps make use of a Settings.bundle and both use the same code to register. @main struct MyApp: App { init() { if !UserDefaults.standard.bool(forKey: "launchedBefore") { registerDefaultSettings() let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] let build = Bundle.main.infoDictionary?["CFBundleVersion"] let versionInfo = "\(version!) (\(build!))" UserDefaults.standard.set( versionInfo, forKey: "versionInfo") UserDefaults.standard.set(true, forKey: "launchedBefore") } } var body: some Scene { WindowGroup { ContentView() } } } private func registerDefaultSettings() { guard let settingsBundle = Bundle.main.url(forResource: "Root.plist", withExtension: nil), let settings = NSDictionary(contentsOf: settingsBundle), let keyValues = settings.object(forKey: "PreferenceSpecifiers") as? [[String: AnyObject]] else { return } var defaultSettings = [String : AnyObject]() for keyValue in keyValues { if let key = keyValue["Key"] as? String, let value = keyValue["DefaultValue"] { defaultSettings[key] = value } } UserDefaults.standard.register(defaults: defaultSettings) } The settings of the 5.5 app appear in the Settings App whereas the settings of the 5.6 do not. If I move the Settings.bundle folder from 5.6. to 5.5, the settings for 5.6 appear in 5.5 thus the file structure and contents seem to be syntactically ok). There was one obvious difference when setting up Settings.bundle in 5.6: SP4 requested to set defaultLocalization in Package.swift. How do I get the 5.6 Settings.bundle to appear in the Settings App?
1
0
1.3k
Oct ’22
Task does not run when main defined in a type
Using Swift on Windows 5.6 this code works: struct Dummy { } @main extension Dummy { static func main() { _ = Task { print("in task in main") } print("in main") print("in main") print("in main") print("in main") print("in main") print("in main") } } This code does not run the task: @main struct Dummy { static func main() { _ = Task { print("in task in main") } print("in main") print("in main") print("in main") print("in main") print("in main") print("in main") } } Is it a bug or my fault?
5
0
821
Sep ’22
Swift Playgrounds 4 apparently uses debug build configuration
Hi there, I found my simple ray tracer using concurrency on 8 cores of an A12 processor in my iPad quite slow compared to the same code running on Windows on only 2 cores. The latter was a release build and took a second the former 16 seconds. Using debug build on Windows yields 36 seconds. I tried a hack in Package.swift and injected an unsafeFlag -O with .when(configuration: .debug) but it crashed compilation whereas other flags (e.g. -Onone) don't. I thus assume a bug in SP4 or compilation for production was intentionally not foreseen. Can someone tell me if I'm right - or even better - how to get SP4 compile for production? Regards, Jürgen.
1
0
773
Feb ’22