Post

Replies

Boosts

Views

Activity

Reply to Creating Multiple Bodies
You need to hide it. I found a useful extension here: https://stackoverflow.com/questions/56490250/dynamically-hiding-view-in-swiftui If you prefer, could write another extension with isVisible ; but usual API is for hiding. Now, your code becomes: extension View { /// Hide or show the view based on a boolean value. @ViewBuilder func isHidden(_ hidden: Bool, remove: Bool = false) - some View { if hidden { if !remove { self.hidden() } } else { self } } } struct ContentView: View { let exampleVariable = "Example" func exampleFunc() { print("Example") } var body: some View { Text("Hello") secondBody .isHidden(stepNum = 4) // Condition to hide is opposite to condition to show } var secondBody: some View { Text("World") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to How to limit my numbers in Swift
That is close to the other question you asked. You could have a func: func trimHealthPoints(healthPts: Int) -> Int { var newHealthPts : Int newHealthPts = mint(healthPts, 100) newHealthPts = max(healthPts, 0) return newHealthPts } Then in the place where you change the health points, you will have something like: player.hp += 10 // or player.hp -= 10 Then call player.hp += 10 player.hp = trimHealthPoints(player.hp) Another way is to create an extension for Int extension Int { 		var trimmed: Int { 				var val : Int = self 				val = Swift.min(val, 100) // Swift prefix needed in extension 				val = Swift.max(val, 0) 				return val 		} } then use as follows player.hp += 10 player.hp = player.hp.trimmed Don't forget to close the thread if solved.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Multiline Large title
how to implement such multiline large titles like in AppStore Do you mean the navigation title ? Have a look here for a detailed solution: https://stackoverflow.com/questions/47901318/how-to-set-multi-line-large-title-in-navigation-bar-new-feature-of-ios-11
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to Crash in app window resizing code
Hard to say without seeing code. Could you show it (please show the whole class). 'The window has been marked as needing another Layout Window pass, but it has already had more Layout Window passes than there are views in the window.' Looks like you are entering an infinite loop, and system crashes when the number of passes exceed the number of views in the window
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’21
Reply to Cannot find "self" in scope & Consecutive declarations on a line must be separated by ";".
Isn't SELF supposed to be pointing to GestureManager class? Yes it is… But … let rightSwipe = UISwipeGestureRecognizer(target: self.vc, action: #selector(respondToSwipeGesture(_:))) rightSwipe.direction = .right let leftSwipe = UISwipeGestureRecognizer(target: self.vc, action: #selector(respondToSwipeGesture(_:))) leftSwipe.direction = .left This code should be inside a func (like viewDidLoad), not free floating in the class, where it is looked at as a declaration. So you should have: override func viewDidLoad() { super.viewDidLoad() let rightSwipe = UISwipeGestureRecognizer(target: self.vc, action: #selector(respondToSwipeGesture(_:))) rightSwipe.direction = .right let leftSwipe = UISwipeGestureRecognizer(target: self.vc, action: #selector(respondToSwipeGesture(_:))) leftSwipe.direction = .left }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to How to stop uiview animate ?
I see 2 solutions at least: remove all animation for the object declare a new animation with zero duration. removing all animations will leave the view in the state where it is when animation stops. So, you have to restore the star you want. You could also read this https://stackoverflow.com/questions/13991465/stop-an-auto-reverse-infinite-repeat-uiview-animation-with-a-bool-completion
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Is it possible to Push/Present a ViewController on Swipe Down?
If you are in a navigation stack, swipe down is used to dismiss the present view. You can't use it. In IB: if you replace in the vc the segue kind from 'Present as popover' to 'Present Modally' or 'Show (push)', that should work. Your code raises several questions: Why do you need the appDelegate ? where do you use this int(vc: UIViewController) Message: could you close the other threads you have opened if answer is correct ?
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to NSSavePanel Error
Your question is not clear. You say: Note: I did add code for using the NSSavePanel to ensure the program could write directly to a file. That code worked as expected. The the program can write to a file. Which code is this ? Which is the code that doesn't work. The message seems clear: Open your app's entitlements Do you have an entry in the plist: com.apple.security.files.user-selected.read-write Is it set to true (1) ?
Topic: UI Frameworks SubTopic: AppKit Tags:
Apr ’21
Reply to Crash in app window resizing code
Hard to see what is causing the possible recursion. So, I would comment out some parts and see if the problem occurs (of course app will not work perfectly during this, but it is just to find cause of crash. Comment all out: from line 7 to 52 It should not crash ! uncomment lines 7 to 33 does it crash ? uncomment lines 34 to 50 does it crash ? uncomment lines 34 to 50 does it crash ? uncomment lines 51 to 52 does it crash ?
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’21