Posts

Post not yet marked as solved
1 Replies
431 Views
Here is the implementation of the broken @AppStorage. import SwiftUI struct ContentView: View {   var body: some View { Spacer() ForEach(values, id: \.self.id) { tuple in Picker("", selection: tuple.value) { ForEach(1..<15, id: \.self) { Text("Select \($0)") } } Spacer() } Spacer()   } private var values: [(id: String, value: Binding<Int>)] { return [("first", $first), ("second", $second), ("third", $third)] } @AppStorage("first") private var first = 8 @AppStorage("second") private var second = 18 @AppStorage("third") private var third = 2 } What is wrong with the code?
Posted
by .Ev.
Last updated
.
Post not yet marked as solved
2 Replies
938 Views
Dear random Apple UIKit engineer. This is a question for you. Today let's speak about keyboard notifications. In particular, UIResponder.keyboardWillShowNotification and UIResponder.keyboardWillHideNotification. While working with those, I noticed some undocumented behaviour. First, let me give you some context: extension UIViewController { func registerForKeyboardNotifications() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardNotification), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardNotification), name: UIResponder.keyboardWillHideNotification, object: nil) } /// Override this method to handle keyboard notifications. @objc func keyboardNotification(_ notification: Notification) { ... } } Eventually, I found that latter method with 3 dots has an implicit animation inside it's scope. Here is the [proof.](https://medium.com /uptech-team/why-does-uiresponder-keyboard-notification-handler-animate-10cc96bce372) Another thing I noticed, is that this property definition is perfectly valid let curve = UIView.AnimationCurve(rawValue: 7)!. The 7 btw comes from UIResponder.keyboardAnimationCurveUserInfoKey as a default value during my tests. So, the enum with 4 possible values (0...3) can be initialized with a value out of enum's cases range. Also, how can I initialize UIView.AnimationOption from 7? I will pollute my OptionSet which I feed to options parameter on UIView.animate(...) My questions: Why implicit animation is not documented and can I trust it or it's a subject to change. Why UIView.AnimationCurve(rawValue: 7)! does not crash. How can I convert UIResponder.keyboardAnimationCurveUserInfoKey's value into UIView.AnimationOption properly if I don't want to use implicit value. I don't encroach on UIKit secrets. I just need to know how to work with the API. Thank you!
Posted
by .Ev.
Last updated
.
Post not yet marked as solved
2 Replies
714 Views
I need to support diffable data source for iOS 13+ devices. But I have different unexpected behaviour with the same codebase. Code runs well on iPhone with iOS 15.1 and crashes with iPad iOS 13.1. I am aware that this API evolves and it has different behaviour with different iOS versions. But these changes are not well exposed usually. Here is the demo project, where the crash happens: https://github.com/Jeka53/diffableCollectionView Would appreciate any help regarding how API works behind the scenes. (Looks like data source doesn't like to be empty on iOS 13.1 iPad). I assume the solution will use compiler iOS version checks with different code flows for different iOS versions. The end goal in the real app is simple. Empty the collection view's snapshot before starting network calls. After data from the network was received, build the snapshot from the ground up.
Posted
by .Ev.
Last updated
.