Post

Replies

Boosts

Views

Activity

Reply to How do I connect a control to a method programmatically? - Develop In Swift Fundamentals - Programmatic Actions
I looked at the book. On page 272, they add the IBAction by control-drag. They do not declare an IBOutlet here, because they don't need it yet (just need the IBAction) On page 287, they now need to reference the button, hence they have created the IBOutlet and connected it to the button in IB. « In order to connect the button to a method programmatically, you’ll need a reference to the button in code. Use Interface Builder to create an IBOutlet for the button.» You can do it, either by control drag from the button to the code and select IBOutlet (similar to what they explain for IBAction and to what is explained on page 282. or declare IBOutlet in code and control- drag to the button in IB to connect it: That is what they assume Page 287: In the book, they do not create the button programmatically. In fact, they create it in IB. If you declare an IBOutlet, you have to connect to the object in IB. Otherwise when you reference the button, you get the crash Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value. However, if you really wanted to create the button completely programmatically, you must not declare an IBOutlet, just a var. So change code as follows: class ViewController: UIViewController { @IBOutlet var toggle: UISwitch! // you may have to do as with button @IBOutlet var slider: UISlider! // you may have to do as with button    var button: UIButton! // -- No IBOutlet override func viewDidLoad() { super.viewDidLoad()   button = UIButton(frame: CGRect(x: 80, y: 30, width: 100, height: 30)) // -- Create the button button.setTitle("My button", for: UIControl.State.normal) // Select a better title button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside) view.addSubview(button) // -- so that button appears in view - could also write self.view to make it clearer } Note: when you connect the button from IB to its IBOutlet, that is somehow the code for initialising button is added automatically when the VC is loaded from storyboard.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Can I make my app fully dark?
As you noticed, it is technically possible, with several options: https://stackoverflow.com/questions/56537855/is-it-possible-to-opt-out-of-dark-mode-on-ios-13 It is not totally clear if it is authorized to disable light mode, even though there does not seem to be restrictions in Apple Guidelines, except a recommendation to support both. https://stackoverflow.com/questions/58816289/will-apple-reject-my-app-if-i-force-light-mode-on-my-app So the safest is probably to design the app directly with the colors you want in each view.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Unbalanced calls to begin/end appearance transitions for...
In UserDefaults.standard.set(downloadUrl, forKey: "profile_picture_url") let vc = self?.storyboard?.instantiateViewController(identifier: "tabBarVC") as! TabBarViewController vc.modalPresentationStyle = .fullScreen self?.present(vc, animated: true) Note: why optional chaining self? and not just self. Did you try to present in the main thread ? let vc = self.storyboard?.instantiateViewController(identifier: "tabBarVC") as! TabBarViewController vc.modalPresentationStyle = .fullScreen DispatchQueue.main.async { self.present(vc, animated: true) }
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to How to determine point on phone screen where a user is looking at, by using data from ARKit FaceAnchor
 but haven't been able to get it to work correctly. Could you explain: what you get how far it is from what you expect in which use case ? (e.g., when user is not looking straight ahead) the code where you compute from lookAtPoint to point on screen I would try to : 1. get the device coordinates in world coordinates (using ARConfiguration.WorldAlignment.gravity) 2. find the face coordinates in the world coordinates (with ARFaceAnchor.transform property) you have lookAtPoint which gives the direction in face coordinates transforming with 1 and 2, you should get the point looked at in device coordinates. This threads links to some useful resources https://developer.apple.com/forums/thread/118048
Topic: App & System Services SubTopic: Core OS Tags:
Mar ’21
Reply to enumeratingSubviewsCount error
Could you show the code that crashes ? I found a reference to the same issu (that's in french)e: https ://forum.macbidouille. com/index.php?showtopic=418944&st=0&p=4357981&#entry4357981 It seems to be linked to /System/Library/PreferencePanes/Dock.prefPane Note: Why would you have to add so many levels of subviews ? 2 to the 6th power is 64.
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’21
Reply to How to read property list (binary format) if the iOS fails to load it via NSPropertyListSerialization
I hope you will find useful information here. It notably details Binary plist structure. https ://medium. com/@karaiskc/understanding-apples-binary-property-list-format-281e6da00dbd Have you tried to read the binary in a text editor ? Note: the article dates 2018, so not iOS 14. So there may have been some changes, but I assume (hope) it has remained essentially the same. Good luck. Thanks to feedback.
Topic: App & System Services SubTopic: General Tags:
Mar ’21
Reply to IOS 14.4.1 not working w/BMWX32020
That's not a question for the forum (no one here has the power to change iOS or your BMW software). Note: did you test in another car ? You'd better either: wait for a new iOS release contact Apple Support file a bug report. Good luck. And don't forget to close the thread once done.
Topic: App & System Services SubTopic: Core OS Tags:
Mar ’21