Post

Replies

Boosts

Views

Activity

Reply to Xcode-beta project ORSOFINAL: SwiftShims & C99 PCH errors after migration from Xcode stable
I have an Xcode project that is purely Swift and SwiftUI across several app targets for different platforms. I created a different branch for Xcode 26 and I'm running on a separate Mac with the Beta builds (beta 3). When building for some targets the app builds just fine but the visionOS app target causes several errors, including the C99 error. C99 was enabled in PCH file but is currently disabled [projectname].xcodeproj/:1:1 module file /Users/[username]/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/SwiftShims-P4BGZILA3GDS9GZUHJT22AVR.pcm cannot be loaded due to a configuration mismatch with the current compilation [projectname].xcodeproj/:1:1 missing required module 'SwiftShims'
1d
Reply to Use @AppStorage with Arrays
I had to store a Set<String> in @AppStorage and ended up using the following code: extension Set: @retroactive RawRepresentable where Element == String { public init?(rawValue: String) { guard let data = rawValue.data(using: .utf8), let decoded = try? JSONDecoder().decode(Set<String>.self, from: data) else { return nil } self = decoded } public var rawValue: String { guard let data = try? JSONEncoder().encode(self), let json = String(data: data, encoding: .utf8) else { return "[]" } return json } } With that in place, I was then able to do the following: @AppStorage("tags") private var selectedTags: Set<String> = []
Topic: UI Frameworks SubTopic: SwiftUI Tags:
4w
Reply to ViewThatFits and Text Truncation
I found a work around although I still think there maybe more appropriate work arounds. I still think there is a need for a modifier to allow Text bound to long Strings, for example, to be ignored by ViewThatFits when evaluating potential subviews. The work around that I'm using is the following: ViewThatFits { // available on all platforms. VStack { } if(UIDevice.current.userInterfaceIdiom == .phone) { // iPhone only option. VStack { } } } Using this approach the smaller view is only used on iPhone in portrait mode and the other view is used on all other platforms. Without this, the smaller view in some cases was used on iPad mini when the Text view was bound to a long String. It doesn't completely solve the issue as the wrong view is still sometimes chosen in landscape on the iPhone, but at least that issue is isolated only to the iPhone. Users on the iPad etc. will always see the wider view. If you have a better solution to avoid long a String within a Text view from impacting ViewThatFits, please let me know.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’25
Reply to Core Transferable Error
While the following code should have ensured that the call to copyItem would succeed, throwing the error allowed me to see that there is still some situations were there is an existing file at the destination. As such, the new implementation below first creates a folder using a UUID, ensuring that the destination is unique every time. if FileManager.default.fileExists(atPath: destination.path) { try FileManager.default.removeItem(at: destination) } Here is the complete version of the transfer function. static func transfer(from received: ReceivedTransferredFile) throws -> Video { do { // note: it was necessary to create a folder with a uuidString to ensure that copying the file would not fail even though existing files are removed. let directory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil) let destination = directory.appendingPathComponent(received.file.lastPathComponent) if FileManager.default.fileExists(atPath: destination.path) { try FileManager.default.removeItem(at: destination) } try FileManager.default.copyItem(at: received.file, to: destination) return Video(url: destination, filename: received.file.lastPathComponent) } catch { debugPrint("error transferring file: \(error)") throw error } } While there are other approaches, the use of uuidString only has a minimal impact on the size of the temporary data and it ensures that the destination is unique.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’25
Reply to MapSelection of MapFeatures and MKMapItems
I'm the original post author, replying from my work account. Here is an example that allows for selection of MapFeatures and MKMapItems. It shows Apple Stores nearby and allows those search results (MKMapItems) to be selected, as well as the MapFeatures to be selected. The key thing that I was missing before was the the need for the .tag modifier on the Marker. This example shows how to achieve selection of MapFeatures and MKMapItems. import SwiftUI import MapKit struct ContentView: View { @State var position: MapCameraPosition = .automatic @State var selection: MapSelection<MKMapItem>? @State private var items: [MKMapItem] = [] var body: some View { VStack { Map(position: $position, selection: $selection) { ForEach(items, id: \.self) { item in Marker(item: item) .tag(MapSelection(item)) } } }.onAppear { Task { try? await search(for: "Apple Store") } } } func search(for query: String) async throws { let request = MKLocalSearch.Request() request.naturalLanguageQuery = query request.resultTypes = [.pointOfInterest, .address] Task { let search = MKLocalSearch(request: request) let response = try? await search.start() items = response?.mapItems ?? [] } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’24