Post

Replies

Boosts

Views

Activity

Reply to swift mac swift app fails to show image view crashes on first run
Have narrowed down problem. When first run, there is no image, and have user open a local file. I then create and save the bookmark for that, so on subsequent run, can access files based on user having already done so. If I call the function to save bookmark, it saves successfully, but when gets to image view, fails to display the image but program continues to run as if all is well. And on next run it retrieves bookmark and opens file and all works fine. IF I DON'T save bookmark, the program goes on to work and displays image all is well. But on next run of course, fails since there is no bookmark saved. Here is function that saves bookmark: func saveBookmarkForSelectedURL(fileURL: URL?) -> Bool {         print("enter saveBookmarkForSelectedURL (String(describing: fileURL))")         do {             if let selectedURL =  fileURL {                 // Create a security-scoped bookmark                 // "Returns bookmark data for the URL, created with specified options and resource values."                 // Return Value: Type: Data - A bookmark for the URL.                 let bookmarkData = try selectedURL.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)                 // get an instance of UserDefaults                 let userDefaults = UserDefaults.standard                 //  store the newly-created bookmark in UserDefaults                 // accessible with a meaningful key; user defaults supports storing                 // and fetching the Data/NSData types                 userDefaults.set(bookmarkData, forKey: "PermanentFileBookmark")                 // creating the bookmark did not throw an error, so return positive                 print("just stored bookmark (bookmarkData)")                 return true             } else {                 print("ERROR: You cannot bookmark a URL that is nil")                 return false             }         } catch let error {             print("Could not create a bookmark because: ", error)             return false  }     } // end func saveBookmarkForSelectedURL()
Topic: UI Frameworks SubTopic: AppKit Tags:
Jun ’22
Reply to swift mac swift app fails to show image view crashes on first run
Yes, using UserDefaults directly and after the saving of persistent url. Yes have @main. Here is the PictureWindowApp.swift: import SwiftUI @main struct PictureWindowApp: App {     @ObservedObject var appState = AppState()          var body: some Scene {         WindowGroup {             ContentView(appState: appState)                 .edgesIgnoringSafeArea(.all)                 .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification), perform: { _ in                     NSApp.mainWindow?.standardWindowButton(.zoomButton)?.isHidden = true                     NSApp.mainWindow?.standardWindowButton(.closeButton)?.isHidden = true                     NSApp.mainWindow?.standardWindowButton(.miniaturizeButton)?.isHidden = true                 })         }         .windowStyle(.hiddenTitleBar)         .windowToolbarStyle(UnifiedCompactWindowToolbarStyle())         .commands {             PictureWindowCommands(appState: appState)         }     } }
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’22
Reply to swift mac swift app fails to show image view crashes on first run
Have narrowed down problem. When first run, there is no image, and have user open a local file. I then create and save the bookmark for that, so on subsequent run, can access files based on user having already done so. If I call the function to save bookmark, it saves successfully, but when gets to image view, fails to display the image but program continues to run as if all is well. And on next run it retrieves bookmark and opens file and all works fine. IF I DON'T save bookmark, the program goes on to work and displays image all is well. But on next run of course, fails since there is no bookmark saved. Here is function that saves bookmark: func saveBookmarkForSelectedURL(fileURL: URL?) -> Bool {         print("enter saveBookmarkForSelectedURL (String(describing: fileURL))")         do {             if let selectedURL =  fileURL {                 // Create a security-scoped bookmark                 // "Returns bookmark data for the URL, created with specified options and resource values."                 // Return Value: Type: Data - A bookmark for the URL.                 let bookmarkData = try selectedURL.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)                 // get an instance of UserDefaults                 let userDefaults = UserDefaults.standard                 //  store the newly-created bookmark in UserDefaults                 // accessible with a meaningful key; user defaults supports storing                 // and fetching the Data/NSData types                 userDefaults.set(bookmarkData, forKey: "PermanentFileBookmark")                 // creating the bookmark did not throw an error, so return positive                 print("just stored bookmark (bookmarkData)")                 return true             } else {                 print("ERROR: You cannot bookmark a URL that is nil")                 return false             }         } catch let error {             print("Could not create a bookmark because: ", error)             return false  }     } // end func saveBookmarkForSelectedURL()
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to swift mac swift app fails to show image view crashes on first run
I have submitted a stripped down version, ImageTest(101) thru Feedback Assistant, along with a copy of the app and crash report.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to swift mac swift app fails to show image view crashes on first run
The other symptom is that despite all the prep that is successful, the Image() in contentView fails to open a window and show the image that was opened/loaded. I am in process of stripping app, have a test version that is somewhat smaller called ImageTest with same symptoms.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to swift mac swift app fails to show image view crashes on first run
Will attach top portion of that file, declarations and init here.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to swift mac swift app fails to show image view crashes on first run
Yes, using UserDefaults directly and after the saving of persistent url. Yes have @main. Here is the PictureWindowApp.swift: import SwiftUI @main struct PictureWindowApp: App {     @ObservedObject var appState = AppState()          var body: some Scene {         WindowGroup {             ContentView(appState: appState)                 .edgesIgnoringSafeArea(.all)                 .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification), perform: { _ in                     NSApp.mainWindow?.standardWindowButton(.zoomButton)?.isHidden = true                     NSApp.mainWindow?.standardWindowButton(.closeButton)?.isHidden = true                     NSApp.mainWindow?.standardWindowButton(.miniaturizeButton)?.isHidden = true                 })         }         .windowStyle(.hiddenTitleBar)         .windowToolbarStyle(UnifiedCompactWindowToolbarStyle())         .commands {             PictureWindowCommands(appState: appState)         }     } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to swift mac swift app fails to show image view crashes on first run
Yep, sandbox entitlements for user selected file and picture folder. There isn't choice of user selected directory.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to Receiving this error 'EXC_BREAKPOINT (code=1, subcode=0x1051904b8)' when trying to use a PhotoPicker.
Did you figure this out? I am having a very similar problem, also on M1. It is also driving me crazy. I tried to copy your code snippets to reproduce yours, but not enough there.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to Receiving this error 'EXC_BREAKPOINT (code=1, subcode=0x1051904b8)' when trying to use a PhotoPicker.
Did you ever solve this, I am struggling with almost exact issue. I have an Image display in ContentView very similar to yours!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’22