Post

Replies

Boosts

Views

Activity

Can't seem to get Unit Test target working when I create. Multiplatform project
In Xcode Version 16.1 Create a new Project, choose Multiplatform, App For testing system, choose XCTest and UI Tests In the project, open the newly generated template Unit test file Click either of the diamonds in the left margin (either to run the example test or the entire file) Expected Result: Code compiles and then Runs the test/tests Actual Result: Code compiles, but then never completes testing (the top status bar is stuck saying "Testing..." forever.) Am I missing something?
0
0
452
Dec ’24
Is it possible to make GeometryReader less vertically greedy?
I must be missing something here. I want to put a landscape image in a geometry reader that contains a ZStack that contains an image and an overlay centred on top of the Image. I would like the ZStack and GeoReader's sizes to be the size of Image. (ie I want geometry.size to be the size of the image, which can be used to control the offset of the overlay's position.) Unfortunately the ZStack also includes the space above the image (ie the top safeArea) and the GeometryReader also includes all the space below the Image. (so geometry.size.height is greater than the height of Image) I've gone down rabbit holes of adding other items above/below, but I don't seem to be able to prevent the GeometryReader from being vertically greedy. eg the Text(" ") above the ZStack in the VStack solves the ZStack claiming the top safe area. But adding Text(" ") below the ZStack does not prevent the GeometryReader from claiming more vertical space below the image. Any/all guidance greatly appreciated. struct ContentView: View { var body: some View { VStack { // Text(" ") GeometryReader { geometry in ZStack { Image( uiImage: .init(imageLiteralResourceName: "LandscapeSample") ) .resizable() .aspectRatio(contentMode: .fit) Text("Hello, world!") .background(.white) } .background(.red) } .background(.blue) // Text(" ") } } }
2
0
461
Jan ’25
A wrinkle converting a UIKit Document-based app to SwiftUI Document Group
The app I'm converting includes two unique document types. UI-wise they have key similarities (eg contents are password protected) But serialization/model - wise. they are different documents. I have not been able to find any documentation on options for implementing this (eg use a (abstract?) base class derived from FileDocument, with two concrete sub classes? maybe just a single subclass of FileDocument that contains model details for both file types?) Stepping back from implementation options, am I crazy for attempting to use DocumentGroup to create a single app that would need to be able to open/modify/save multiple unique document types? any/all guidance much appreciated.
Topic: UI Frameworks SubTopic: SwiftUI
0
0
68
May ’25
Can I disable a SwiftUI View from being a draggable source, but still leave it enabled as a dropDestination?
My app has a collection of Cell Views. some of the views' model objects include a Player, and others do not. I want to use drag and drop to move a player from one cell to another. I only want cells that contain a player to be valid drag sources. All cells will be valid drop destinations. When I uncomment the .disabled line both drag and drop become disabled. Is it possible to keep a view enabled as a dropDestination but disabled as a draggable source? VStack { Image("playerJersey_red") if let player = content.player { Text(player.name) } } .draggable(content) // .disabled(content.player == nil) .dropDestination(for: CellContent.self) { items, location in One thing I tried was to wrap everything in a ZStack and put a rectangle with .opacity(0.02) above the Image/Text VStack. I then left draggable modifying my VStack and moved dropDestination to the clear rectangle. This didn't work as I wasn't able to initiate a drag when tapping on the rectangle. Any other ideas or suggestions? thanks
2
0
125
2d
Can I use combine on a property in an @Observable class?
As the title suggests, I have a class marked with @Observable. Within the class I have multiple var's. When one of my var's changes (formation), I want to run an updateOrCreateContent(). I had thought I could just do this with a bit of combine, but I'm struggling to get it working... The code below has a compile error at $formation When I mark formation @Published, it generates a different compile error: "Invalid redeclaration of synthesized property '_formation'" any help appreciated thanks class LayoutModel { var players: [Player] = [] var formation: Formation = .f433 var cancellables = Set<AnyCancellable>() init(players: [Player], formation: Formation) { self.players = players self.formation = formation updateOrCreateContent() $formation.sink(receiveValue: { _ in self.updateOrCreateContent() }) .store(in: &cancellables) }
0
0
68
1d