I’m on Xcode 16.2 and working a simulator for iOS 18.2. Beforehand, I used to be on Xcode 15.x and working iOS 17.4 sims. This downside didn’t happen for me on iOS 17.4. Pattern code is as follows:
import SwiftUI
import PhotosUI
struct ContentView: View {
@StateObject var imagePicker2 = ImagePicker()
var physique: some View {
ScrollView {
VStack {
Picture(systemName: "globe")
.imageScale(.giant)
.foregroundStyle(.tint)
Textual content("Hiya, world!")
.background(Coloration.orange)
.padding(.backside, 75)
PhotosPicker(choice: $imagePicker2.imageSelection, matching: .photographs, photoLibrary: .shared()) {
Label("", systemImage: "photograph")
}
.font(.system(dimension: 55))
.padding(.backside, 55)
if let picture = imagePicker2.picture {
HStack {
picture
.resizable()
.body(width:75, peak:75)
.scaledToFit()
.overlay(Rectangle().stroke(Coloration.teal, lineWidth: 2))
}
}
}
.padding()
}
}
}
import SwiftUI
import PhotosUI
@MainActor
class ImagePicker: ObservableObject {
@Revealed var unableToLoad: Bool = false
@Revealed var picture: Picture?
@Revealed var myUIImage: UIImage?
@Revealed var imageSelection: PhotosPickerItem? {
didSet {
unableToLoad = false
if let imageSelection {
//.. attempt to convert photosPickerItem imageSelection right into a uiImage
Process {
strive await setImage(from: imageSelection)
}
}
}
}
func setImage(from imageSelection: PhotosPickerItem?) async throws {
do {
if let information = strive await imageSelection?.loadTransferable(kind: Information.self) {
if let uiImage = UIImage(information: information) {
self.picture = Picture(uiImage: uiImage)
self.myUIImage = uiImage
}
}
} catch {
print(error.localizedDescription)
unableToLoad = true
}
}
}
The picture hundreds on the UI however I get “[ERROR] Couldn’t create a bookmark: NSError: Cocoa 4097 “connection to service named com.apple.FileProvider” within the log each time I select a brand new photograph. To date, I have never had an precise crash however others have indicated that relying on what they’re doing code-wise, that some have crashed. Is that this an iOS 18.x bug? Ideas?