Post

Replies

Boosts

Views

Activity

Reply to why do I get this error
The error message should be self explanatory? In SwiftUI, you can not just write arbitrary code, when a View is expected. Remember that you are declaring a UI. Try replacing your "for" loop with this SwiftUI code: ForEach(cities, id: \.self) { city in Text("City: \(city)") }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to SwiftUI opacity animation fails in Gesture's onEnded method
Interestingly, if I add another modifier to the first Rectangle, the fade-in works! Rectangle() .fill( fade ? .red : .blue) .frame(width: 100, height: 100, alignment: .center) .opacity(fade ? 0 : 1) SwiftUI can only animate viewModifiers for Views that are already on-screen. I think what is happening is that when the opacity is set to 0, SwiftUI removes that view from the screen... ...so it's re-appearance (on setting opacity to 1) is not animated. As a test, try fading out, but not right to 0: .opacity(fade ? 0.1 : 1) This seems to work.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Problems updating a variable
You are declaring "tagUID" in a class, so you should not be using the @State property wrapper (which is for SwiftUI). Try removing the "@State"... just use: var tagUID = "UID" Or since your NFCReader is an ObservableObject, you may mean: @Published var tagUID = "UID"
Jan ’22
Reply to Swift: How to add 47 Bool filter to json List
Have you considered rewriting it as a method that tests each Bool individually, and returns the overall Bool result? Perhaps something like... func include() -> Bool { if !filters.showhjertestarterOnly || havneplan.hjertestarter { return true } if !filters.showpaabroerneOnly || havneplan.paabroerne { return true } /// And so on, through your 47 Bools... return false }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Swift: How to add 47 Bool filter to json List
I don't know how to solve your issue, but perhaps this clue will help... In SwiftUI, a ViewBuilder is limited to a maximum of 10 Views. It looks like there may be a similar limit to filters? I found your code a bit confusing (json doesn't seem to have any relevance), but I suspect there may be a more elegant solution. Would you like to post a bit more about what you are trying to achieve, and how (and why)?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to SwiftUI NavigationLink with action in List
It might be cleaner to have the action take place in the view you are navigating to, using .onAppear?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Looking for Advice: Adding a Mac App to an established iOS app
Generally, you would add a new Target to the iOS project. Then you can share code that is common to both targets, and have other code files that are target-specific. In shared code files, it is possible to mark code as applying only to a specific platform.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to SwiftUI How to pass a CoreData object to an other view
Just pass the Preview a Timer... struct TimerRow_Previews: PreviewProvider { static var previews: some View { TimerRow(timer: Timer()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to why do I get this error
The error message should be self explanatory? In SwiftUI, you can not just write arbitrary code, when a View is expected. Remember that you are declaring a UI. Try replacing your "for" loop with this SwiftUI code: ForEach(cities, id: \.self) { city in Text("City: \(city)") }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Type 'CameraPreview' does not conform to protocol 'UIViewRepresentable'
We can't do much with a screenshot of a tiny sample of your code, and truncated error messages! Please post more code, in a code block, using "Paste & Match Style" (to preserve formatting). Also post the error messages, in full.
Replies
Boosts
Views
Activity
Jan ’22
Reply to SwiftUI opacity animation fails in Gesture's onEnded method
Interestingly, if I add another modifier to the first Rectangle, the fade-in works! Rectangle() .fill( fade ? .red : .blue) .frame(width: 100, height: 100, alignment: .center) .opacity(fade ? 0 : 1) SwiftUI can only animate viewModifiers for Views that are already on-screen. I think what is happening is that when the opacity is set to 0, SwiftUI removes that view from the screen... ...so it's re-appearance (on setting opacity to 1) is not animated. As a test, try fading out, but not right to 0: .opacity(fade ? 0.1 : 1) This seems to work.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to xcode12 spritekit image shown as red X
Did that fix it for you, @MrMajorThorburn?
Topic: Graphics & Games SubTopic: SpriteKit Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Problems updating a variable
You are declaring "tagUID" in a class, so you should not be using the @State property wrapper (which is for SwiftUI). Try removing the "@State"... just use: var tagUID = "UID" Or since your NFCReader is an ObservableObject, you may mean: @Published var tagUID = "UID"
Replies
Boosts
Views
Activity
Jan ’22
Reply to How to turn on feature in Xcode Editor
This is called the "Minimap". The menu for this in on an icon at the top-right of Xcode... (the middle of the three lower buttons, in the screenshot.)
Replies
Boosts
Views
Activity
Jan ’22
Reply to How to delete a question posted in this forum?
No. (At least, not for users of the Forum)
Replies
Boosts
Views
Activity
Jan ’22
Reply to OS 13.1.2 can't detect on Mac Monterey 12.1 and Xcode 13.2.1
{Comment removed}
Replies
Boosts
Views
Activity
Jan ’22
Reply to When you reboot the full screen Xcode, the top menu disappears.
It's not just Xcode. This is now a system setting, for full-screen apps. System Preferences > Dock & Menu Bar > Automatically hide and show the menu bar in full screen
Replies
Boosts
Views
Activity
Jan ’22
Reply to How to manage view when model the same but different views?
MVVM, where: Model is value types (structs) Views are value types (SwiftUI Views) ViewModel is a reference type (a class), so it can be passed around the app, and an ObservableObject (so Views can respond to changes)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Swift: How to add 47 Bool filter to json List
Have you considered rewriting it as a method that tests each Bool individually, and returns the overall Bool result? Perhaps something like... func include() -> Bool { if !filters.showhjertestarterOnly || havneplan.hjertestarter { return true } if !filters.showpaabroerneOnly || havneplan.paabroerne { return true } /// And so on, through your 47 Bools... return false }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Swift: How to add 47 Bool filter to json List
I don't know how to solve your issue, but perhaps this clue will help... In SwiftUI, a ViewBuilder is limited to a maximum of 10 Views. It looks like there may be a similar limit to filters? I found your code a bit confusing (json doesn't seem to have any relevance), but I suspect there may be a more elegant solution. Would you like to post a bit more about what you are trying to achieve, and how (and why)?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22