Post

Replies

Boosts

Views

Activity

Reply to Can't compile asset catalog when including iMessage App Icon asset
I have a similar issue with the app icons for an Apple Watch app. I have two targets: App target (iOS and macOS) Watch Target and two separate Asset catalogs for the targets. In App target I have the AppIcon as all sizes (macOS, iOS and watchOS). In Watch target I have AppIcon as single size (1024x1024, watchOS only) (That's what I believe https://developer.apple.com/tutorials/swiftui/creating-a-watchos-app have on step 7.) When building the app for a real iOS device using Run in Xcode the Watch target build fails with "Command CompileAssetCatalog failed with a nonzero exit code" with this approach. Removing the watchOS single size 1024x1024 image from it's Asset catalog in AppIcon without removing the AppIcon set and still have the watchOS single size (but without image, just empty) fixes the issue and the build succeeds. I'm using Xcode Cloud, and building with the image in the watchOS Asset catalog doesn't fail, and you can sue the build for TestFlight, but trying with archive fails with the same error as running the project in Xcode. Xcode 15.4 macOS 14.3.1
Jan ’25
Reply to Storyboard target in Beta
If you still want to have story board launch screen I had this exact same issue but managed to solve it by only accepting iOS in Copy Bundle Resources, see this image I made to demonstrate: (modified the image from https://developer.apple.com/documentation/xcode/customizing-the-build-phases-of-a-target) EDIT: I found this thread with the same solution: https://stackoverflow.com/questions/72853807/is-it-possible-to-skip-launchscreen-storyboard-file-when-running-a-multiplatform
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’24
Reply to MapProxy conversion from screen to coords is wrong on macOS
I have tried: import MapKit import SwiftUI private let rectWidth: Double = 80 private struct MarkerData { let coordinate: CLLocationCoordinate2D let screenPoint: CGPoint var touchableRect: CGRect { .init(x: screenPoint.x - rectWidth / 2, y: screenPoint.y - rectWidth / 2, width: rectWidth, height: rectWidth) } } struct ContentView: View { @State private var cameraPosition: MapCameraPosition = .automatic @State private var modes: MapInteractionModes = [.all] @State private var isMarkerDragging = false @State private var markerData: MarkerData? var body: some View { GeometryReader { geometryProxy in MapReader { mapProxy in Map(position: $cameraPosition, interactionModes: modes) { if let markerData { Marker("Start", coordinate: markerData.coordinate) } } .onTapGesture { screenCoordinate in self.markerData = mapProxy.markerData(screenCoordinate: screenCoordinate, geometryProxy: geometryProxy) } .highPriorityGesture(DragGesture(minimumDistance: 1) .onChanged { drag in guard let markerData else { return } if isMarkerDragging { } else if markerData.touchableRect.contains(drag.startLocation) { isMarkerDragging = true setMapInteraction(enabled: false) } else { return } self.markerData = mapProxy.markerData(screenCoordinate: drag.location, geometryProxy: geometryProxy) } .onEnded { drag in setMapInteraction(enabled: true) isMarkerDragging = false } ) .onMapCameraChange { guard let markerData else { return } self.markerData = mapProxy.markerData(coordinate: markerData.coordinate, geometryProxy: geometryProxy) } } } } private func setMapInteraction(enabled: Bool) { if enabled { modes = .all } else { modes = [] } } } private extension MapProxy { func markerData(screenCoordinate: CGPoint, geometryProxy: GeometryProxy) -> MarkerData? { guard let coordinate = convert(screenCoordinate, from: .local) else { return nil } return .init(coordinate: coordinate, screenPoint: screenCoordinate) } func markerData(coordinate: CLLocationCoordinate2D, geometryProxy: GeometryProxy) -> MarkerData? { guard let point = convert(coordinate, to: .local) else { return nil } return .init(coordinate: coordinate, screenPoint: point) } } by user nightwill from this question at StackOverflow: https://stackoverflow.com/questions/77354568/swiftui-mapkit-drag-annotation and I noticed that on macOS 14.3.1 and Xcode 15 the touchable rect is under the marker most of the time, except when the only window in the app is the map and the app is in full screen. You can check the touchable rect by implementing this in the code from nightwill (I implemented it after onMapCameraChange in the code above): .overlay { if let markerData { Rectangle() .stroke(Color.red, lineWidth: 2) .frame(width: rectWidth, height: rectWidth) .position(x: markerData.screenPoint.x, y: markerData.screenPoint.y) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’24
Reply to Using the SwiftUI Canvas
Hi! Did you solve it? Question number 1: I have unfortunately no idea how to do that, I think you need to play around with PencilKit from UIKit and then implementing custom drag gestures for Swift to determine that you want to scroll or paint. However, this should be possible because Apple's own Freeform app can do such. Question number 2: Did you mean something like this? (before you draw this will have drawn some line on the screen, because you pass lines as a parameter to the draw view) ContentView(lines: [ Line(points: [ CGPoint(x: 12, y: 426), CGPoint(x: 12, y: 65) ], color: .black), Line(points: [ CGPoint(x: 122, y: 412), CGPoint(x: 425, y: 212) ], color: .black), Line(points: [ CGPoint(x: 553, y: 2), CGPoint(x: 1, y: 23) ], color: .black) ], selectedColor: .black)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24
Reply to Using the SwiftUI Canvas
Hi! I tried your code! For me, no line was drawn with the ScrollView, so I tried replacing the ScrollView([.horizontal, .vertical]) with a VStack and then you could draw! The code that worked: struct Line { var points: [CGPoint] var color: Color } struct ContentView: View { @State var lines: [Line] = [] @State var selectedColor: Color = Color.black var body: some View { VStack { Canvas { ctx, size in for line in lines { var path = Path() path.addLines(line.points) ctx.stroke(path, with: .color(line.color), style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round)) } }.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local) .onChanged({ value in let position = value.location if value.translation == .zero { lines.append(Line(points: [position], color: selectedColor)) } else { guard let lastIndex = lines.indices.last else { return } lines[lastIndex].points.append(position) } }) ) } } } However, I am uncertain why the scrollview didn't work. Have a great day!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to Can't call another view out of a scrollview
Hi! To go to another view in SwiftUI, you can use NavigationStack! You also have to use NavigationLink(destination: AnotherView()) and then wrap the label in it (the Text). This way the text element becomes pressable, and when pressed, it'll take you to the next view, AnotherView()!. struct ContentView: View { var body: some View { NavigationStack { //<-- Wrap your whole view into NavigationStack to enable the navigation to subviews ScrollView{ VStack { ForEach(0..<14) {value in NavigationLink(destination: AnotherView(), label: { //<-- Wrap your content in a NavigationLink Text("Test \(value)") .padding(.vertical) }) //<-- Closing bracket to NavigationLink } } } } //<-- Closing bracket to NavigationStack } } struct AnotherView: View { var body: some View { Text("Another View") } } The reason this doesn't work is you can't call a view from not in your view body and expect SwiftUI to show the view. The compiler throws a warning that says: "Result of AnotherView() initialiser is unused": .onTapGesture { print("scrollview-item tapped") AnotherView() //<-- Result of AnotherView() initialiser is unused } Also, NavigationStack has to be used to enable navigation. Without NavigationStack and only using NavigationLink, the NavigationLink won't work. Have a great day!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to ignoresSafeArea working on preview but not simulator
Weird, I tried your code and it worked in the simulator (iOS 17.2, Xcode 15.1). One thing I thought about was that if you have any view in your RandomTestingFeaturesApp.swift file that fights with your ContentView. Like if you have this code: struct TestApp: App { var body: some Scene { WindowGroup { ContentView() .padding() // <- padding which limits contentview to not reach all safe area } } } struct ContentView: View { let mainColor = Color.green var body: some View { ZStack { mainColor.ignoresSafeArea(.all) Text("Hello world!") .padding() } } } With and without padding in the TestApp app struct: To sum, please check your main app struct in the RandomTestingFeaturesApp.swift file, and have a great day!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to Error using SwiftData and WindowGroup
Hi, I experimented a little and thought why not taking { $0.id == detailID } directly instead of wrapping it in a string { $0.id == "($detailID)" } because I managed to find this error from your code: "Referencing operator function '==' on 'StringProtocol' requires that 'UUID' conform to 'StringProtocol'". (instead of the unhelpful "Failed to produce.." error). However, I am not 100 percent sure this will fix, but I hope you can try it. Have a great day!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24