Post

Replies

Boosts

Views

Activity

Reply to Why is the struct type UUID not sendable?
UUID does not conform to Sendable (even though it is a struct, but some of its components may be mutable ?) Conforms to: CustomReflectable CustomStringConvertible Decodable Encodable Equatable Hashable ReferenceConvertible Hence, S does not conform either. See example in Proposal: SE-0302 https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md // error: MyNSPerson cannot conform to Sendable due to NSMutableString member. // note: add '@unchecked' if you know what you're doing. struct MyNSPerson : Sendable { var name: NSMutableString var age: Int }
Topic: App & System Services SubTopic: General Tags:
Aug ’21
Reply to Fetch Width and Height From UIView
In the code you posted, you do not define a frame for viewView. Hence 0,0 I did some formatting: let View1: UIView = { let viewView = UIView() viewView.translatesAutoresizingMaskIntoConstraints = false viewView.contentMode = .scaleAspectFit print(UserDefaults.standard.bool(forKey: "backgroundColourSelected")) if UserDefaults.standard.bool(forKey: "backgroundColourSelected") { viewView.backgroundColor = self.viewColor } else { viewView.backgroundColor = .white } viewView.clipsToBounds = true return viewView }() Try and replace let viewView = UIView() by something like: let viewView = UIView(frame: CGRect(x: 64, y: 0, width: 256, height: 128))
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Need Help Transfer Data From Button
gotta figure out why the name is not being transferred over.  There may be several reasons: segue.identifier is not the expected one segue.destination is not of the expected class the name you pass is empty. You should add several prints at each step of prepare to check for this. If you want more precise help, you should post the complete code of the class.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Animate sizeToFit
Could you detail what you get and what you expect ? AFAIU, animation works by layering an image "capture" over the view to animate and then apply the animation on this layer. Thus, I don't think it will change the font size, but scale the image. I don't think sizeToFit is appropriate here. May have a look at using transform: https://stackoverflow.com/questions/14494566/animating-uilabel-font-size-change
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Animate sizeToFit
So I understand you want to animate (through NSAnimation), the change of the label's text in a MacOS app ? And the change occurs only abruptly (probably after the 4 seconds) ? It would help to see or reproduce exactly what you get. Could you post the complete code the the class ?
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Need Help Transfer Data From Button
Thanks for posting code. But we need to know: what do you get as result of print (are they fired ?):             print("this is the segue destination: \(segue.destination)")             print("name being transferred is \(selectedNameInCell)") how did you define "hs" segue, very precisely: from where (cell ? VC itself ?) did you do a clean build folder after removing one of the duplicates ? Could you also add a print : override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { if let cell = tableView.cellForRow(at: indexPath) as? FavCell { selectedNameInCell = cell.name.text print("selectedNameInCell", selectedNameInCell) } return indexPath }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to [Swift] How to properly subclass UITextfield and work with its delegate
Your init is not correct. You miss call to super. required override init(frame: CGRect) {           super.init(frame: frame) delegate = self } why do you add required ? What is the compiler error you get where // CAN'T DO THIS!!! You should also need the init(coder): required init?(coder: NSCoder) { super.init(coder: coder) delegate = self } With this, textFieldDidBeginEditing works as expected.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Animate sizeToFit
What I understand from what you show: the change of text should be done in the completion handler of the animation but it will not be possible to animate the sizeToFit stated otherwise, the change from "oldText" to "long, long text" cannot be animated the way you want ; the animation is an image "morphing" animation, not a text substitution. In your case, as sizeToFit is not a property for animation, the delay is not applied ! Test the following and see difference: prints after 4 seconds now. @IBAction func animate2LabelAction(_ sender: NSButton) { self.labelForAnimation.stringValue = "short text" NSAnimationContext.runAnimationGroup({ (context) in context.duration = 4.0 // labelForAnimation.animator().sizeToFit() labelForAnimation.animator().alphaValue = 0.5 // This is animatable }, completionHandler: { print("Completion") } ) } Or add label change in completion: @IBAction func animate2LabelAction(_ sender: NSButton) { self.labelForAnimation.stringValue = "short text" NSAnimationContext.runAnimationGroup({ (context) in context.duration = 4.0 // labelForAnimation.animator().sizeToFit() labelForAnimation.animator().alphaValue = 0.5 }, completionHandler: { self.labelForAnimation.stringValue = "long, long text" print("Completion") } ) }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Animate sizeToFit
You can probably try something to get an approaching result. In the IBAction, create a hidden TextField, with same font as label1. Compute initialWidth, the original width of final text in this textField. https://stackoverflow.com/questions/19128797/calculating-uilabel-text-size If initialWidth is larger than label1Width (label1), then apply the animation, with the following compute let scaleRatio = initialWidth / label1Width in the animation, apply a transform with this scale factor in the completion handler, set the finalText in label1 and sizeToFit()
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to [Swift] How to properly subclass UITextfield and work with its delegate
Thanks for feedback. Don't forget to close the thread. As for your next question : the ViewController code which uses MyTextField to also have a UITextFieldDelegate:  class ViewController: UIViewController, UITextFieldDelegate { override func viewDidLoad() { let myTF = MyTextField( .... ) myTF.delegate = self }    func textFieldDidBeginEditing(_ textField: UITextField) {     print("XXXXX"). // This is printed instead of "Inside subclassed textfield" within the subclass.   }  So, if the subclassed textfield's delegate is set to self within the calling code (ViewController in this case), the textFieldDidBeginEditing() inside the subclass is never called. In general, is there a way to trigger textFieldDidBeginEditing() in both the calling code as well as the one inside the subclass? Sequence happens as follows: in viewDidLoad, all subviews are loaded. hence the subclassed textfield's delegate is set to itself  but then, you execute code in viewDidLoad and override the delegate to be the class (ViewController) So only this one will be triggered I do not know of direct mechanism to achieve what you want. And if that was possible, that could make debugging a bit hard. What you could do: remove the delegate declaration in ViewController for myTF in the MyTextField subclass, post a new notification in textFieldDidBeginEditing make ViewController class subscribe to this notification and handle it.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to MacOS Monterey 12 Beta 5 - KASAN
Could you explain what you mean ?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Fetch Width and Height From UIView
Doesn't viewView.frame.size or View1.frame.size give you what you are looking for ? Note: you should take care of your var naming: should start with lowerCase as view1 get explicit names (viewView is not very much)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Xcode Issue
Which version of XCode ? Could you show the complete playGround code ?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Why is the struct type UUID not sendable?
UUID does not conform to Sendable (even though it is a struct, but some of its components may be mutable ?) Conforms to: CustomReflectable CustomStringConvertible Decodable Encodable Equatable Hashable ReferenceConvertible Hence, S does not conform either. See example in Proposal: SE-0302 https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md // error: MyNSPerson cannot conform to Sendable due to NSMutableString member. // note: add '@unchecked' if you know what you're doing. struct MyNSPerson : Sendable { var name: NSMutableString var age: Int }
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Fetch Width and Height From UIView
In the code you posted, you do not define a frame for viewView. Hence 0,0 I did some formatting: let View1: UIView = { let viewView = UIView() viewView.translatesAutoresizingMaskIntoConstraints = false viewView.contentMode = .scaleAspectFit print(UserDefaults.standard.bool(forKey: "backgroundColourSelected")) if UserDefaults.standard.bool(forKey: "backgroundColourSelected") { viewView.backgroundColor = self.viewColor } else { viewView.backgroundColor = .white } viewView.clipsToBounds = true return viewView }() Try and replace let viewView = UIView() by something like: let viewView = UIView(frame: CGRect(x: 64, y: 0, width: 256, height: 128))
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Xcode Issue
Are you in manual or automatic mode ? Click on the arrow at the bottom and select automatic. What do you get ? You may also check Themes and font colors in XCode preferences:
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Need Help Transfer Data From Button
gotta figure out why the name is not being transferred over.  There may be several reasons: segue.identifier is not the expected one segue.destination is not of the expected class the name you pass is empty. You should add several prints at each step of prepare to check for this. If you want more precise help, you should post the complete code of the class.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Animate sizeToFit
Could you detail what you get and what you expect ? AFAIU, animation works by layering an image "capture" over the view to animate and then apply the animation on this layer. Thus, I don't think it will change the font size, but scale the image. I don't think sizeToFit is appropriate here. May have a look at using transform: https://stackoverflow.com/questions/14494566/animating-uilabel-font-size-change
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Animate sizeToFit
So I understand you want to animate (through NSAnimation), the change of the label's text in a MacOS app ? And the change occurs only abruptly (probably after the 4 seconds) ? It would help to see or reproduce exactly what you get. Could you post the complete code the the class ?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Need Help Transfer Data From Button
Thanks for posting code. But we need to know: what do you get as result of print (are they fired ?):             print("this is the segue destination: \(segue.destination)")             print("name being transferred is \(selectedNameInCell)") how did you define "hs" segue, very precisely: from where (cell ? VC itself ?) did you do a clean build folder after removing one of the duplicates ? Could you also add a print : override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { if let cell = tableView.cellForRow(at: indexPath) as? FavCell { selectedNameInCell = cell.name.text print("selectedNameInCell", selectedNameInCell) } return indexPath }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to [Swift] How to properly subclass UITextfield and work with its delegate
Your init is not correct. You miss call to super. required override init(frame: CGRect) {           super.init(frame: frame) delegate = self } why do you add required ? What is the compiler error you get where // CAN'T DO THIS!!! You should also need the init(coder): required init?(coder: NSCoder) { super.init(coder: coder) delegate = self } With this, textFieldDidBeginEditing works as expected.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Can i turn a touchesCancelled onto touchesEnded?
In another thread I advised you to call the same code in cancel as in ended. Did you try that ? It is the same answer to this new question.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Animate sizeToFit
What I understand from what you show: the change of text should be done in the completion handler of the animation but it will not be possible to animate the sizeToFit stated otherwise, the change from "oldText" to "long, long text" cannot be animated the way you want ; the animation is an image "morphing" animation, not a text substitution. In your case, as sizeToFit is not a property for animation, the delay is not applied ! Test the following and see difference: prints after 4 seconds now. @IBAction func animate2LabelAction(_ sender: NSButton) { self.labelForAnimation.stringValue = "short text" NSAnimationContext.runAnimationGroup({ (context) in context.duration = 4.0 // labelForAnimation.animator().sizeToFit() labelForAnimation.animator().alphaValue = 0.5 // This is animatable }, completionHandler: { print("Completion") } ) } Or add label change in completion: @IBAction func animate2LabelAction(_ sender: NSButton) { self.labelForAnimation.stringValue = "short text" NSAnimationContext.runAnimationGroup({ (context) in context.duration = 4.0 // labelForAnimation.animator().sizeToFit() labelForAnimation.animator().alphaValue = 0.5 }, completionHandler: { self.labelForAnimation.stringValue = "long, long text" print("Completion") } ) }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Animate sizeToFit
You can probably try something to get an approaching result. In the IBAction, create a hidden TextField, with same font as label1. Compute initialWidth, the original width of final text in this textField. https://stackoverflow.com/questions/19128797/calculating-uilabel-text-size If initialWidth is larger than label1Width (label1), then apply the animation, with the following compute let scaleRatio = initialWidth / label1Width in the animation, apply a transform with this scale factor in the completion handler, set the finalText in label1 and sizeToFit()
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to [Swift] How to properly subclass UITextfield and work with its delegate
Thanks for feedback. Don't forget to close the thread. As for your next question : the ViewController code which uses MyTextField to also have a UITextFieldDelegate:  class ViewController: UIViewController, UITextFieldDelegate { override func viewDidLoad() { let myTF = MyTextField( .... ) myTF.delegate = self }    func textFieldDidBeginEditing(_ textField: UITextField) {     print("XXXXX"). // This is printed instead of "Inside subclassed textfield" within the subclass.   }  So, if the subclassed textfield's delegate is set to self within the calling code (ViewController in this case), the textFieldDidBeginEditing() inside the subclass is never called. In general, is there a way to trigger textFieldDidBeginEditing() in both the calling code as well as the one inside the subclass? Sequence happens as follows: in viewDidLoad, all subviews are loaded. hence the subclassed textfield's delegate is set to itself  but then, you execute code in viewDidLoad and override the delegate to be the class (ViewController) So only this one will be triggered I do not know of direct mechanism to achieve what you want. And if that was possible, that could make debugging a bit hard. What you could do: remove the delegate declaration in ViewController for myTF in the MyTextField subclass, post a new notification in textFieldDidBeginEditing make ViewController class subscribe to this notification and handle it.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21