Post

Replies

Boosts

Views

Activity

Reply to Prevent Text Field from containing 2 decimal points in Swift
Declare that the class conforms to UITextFieldDelegate Use the func:      func textFieldDidChangeSelection(_ textField: UITextField) { } to test there are not 2 decimal points (and maybe test that you only have digits ?) Code should be like this (I assume there is only one textField in your view, otherwise you have to test that textField is the correct one): func textFieldDidChangeSelection(_ textField: UITextField) { if let typedText = textField.text { // What have we typed in ? var dotCount = 0 for c in typedText { // count dot or comma if String(c) == "." || String(c) == "," {  dotCount += 1  } } if dotCount >= 2 { // remove last typed                     textField.text = String(typedText.dropLast()) } } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21
Reply to Presentation single with code
Could you explain better what you get and what you want ? I try to formulate You click button, calling obrirAmbCodi, which opens a window finestra3 when you click again on that button, a new, similar window opens (probably stacked over previous one ?) in such a case, you would want just to display the already opened window, not create a new one. Is that correct ? If so, you could: In the class where obrirAmbCodi is, declare a var var controller: NSWindowController? test if nil ; if so instantiate     @IBAction func obrirAmbCodi(_ sender: NSButton) { if controller == nil {         let storyboard:NSStoryboard = NSStoryboard(name: "Main", bundle: nil) controller = storyboard.instantiateController(withIdentifier: "finestra3") as? NSWindowController // could be nil             controller?.showWindow(self) }     } dismiss the controller when you close window and set to nil Note: you could test if the window is open instead of testing controller
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Adding Restores Everything
The thing is I need noRepFav because I don't want duplicates in my array. There are very simple ways to achieve this with a single array. Before appending to this array, check if the item already exist. I'm confused with this code: you have at least 2 different TableViewControllers (FavouritesVC, HockeyDetailVC). Both of them have handleFavNotification. It is not clear where you delete, where you add, where it is added back.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Override info.plist value at runtime
You cannot do that. info.plist is part of bundle and cannot be changed at runtime. See details here for instance: https://stackoverflow.com/questions/40214673/setting-value-to-info-plist-file-from-swift?noredirect=1&lq=1 But why change the info.plist and not directly the appearance ? https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_macos_app
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’21
Reply to Xcode Swift Coremotion Pedometer update every step
AFAIK, answer is no. A few reference material: https://stackoverflow.com/questions/36439912/live-updates-with-cmpedometer-coremotion h t t p s : / / medium.com/simform-engineering/count-steps-with-cmpedometer-on-iwatch-94b61bc3b87e The pedometer is a higher level object on Core motion. It sets its own refresh rates and we can get updates through a closure, so it’s on its own schedule, not one we can control. Just an idea, for what it's worth. Using the actual speed and the recent ratio steps/speed, maybe you could estimate the count at the frequency you want, and display it. Then, as soon as you receive a new pedometer information, update everything. I don't know if that would be good enough or too chaotic information display.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Navigation Controller Back Button not working correctly when tapped
No, never met this problem. Could you tell: Which version of Xcode ? On simulator or device ? Which OS version in anycase. Have you changed the button programmatically, in anyway ? Are you sure you have nothing overplayed over "Back" ? Could debug view hierarchy when running to check for this ? Eventually, create the smallest possible project to reproduce and attach the full project folder here.
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21
Reply to DateComponents configuration for x months
Thanks. The explanation in doc is not very clear. But seems coherent with my understanding. And the Xcode doc for UNCalendarNotificationTrigger confirms Overview Create a UNCalendarNotificationTrigger object when you want to schedule the delivery of a local notification at the specified date and time. You specify the temporal information using an NSDateComponents object, which lets you specify only the time values that matter to you. The system uses the provided information to determine the next date and time that matches the specified information. Listing 1 creates a trigger that delivers its notification every morning at 8:30. The repeating behavior is achieved by specifying true for the repeats parameter when creating the trigger. Listing 1 Creating a trigger that repeats at a specific time var date = DateComponents() date.hour = 8 date.minute = 30 let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)   I don't know how to do directly what you want. A workaround would be to create multiple notifications, as described here: https://stackoverflow.com/questions/50027190/uncalendarnotificationtrigger-every-3rd-day
Aug ’21