I\'m trying to update this code to swift 3:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(\"keyboardWillShow:\"), name: UIKeyboar
@State var keyboardHeight: CGFloat = 0 // or @Published if one is in ViewModel: ObservableObject
private var cancellableSet: Set = []
init() {
let notificationCenter = NotificationCenter.default
notificationCenter.publisher(for: UIWindow.keyboardWillShowNotification)
.map {
guard
let info = $0.userInfo,
let keyboardFrame = info[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
else { return 0 }
return keyboardFrame.height
}
.assign(to: \.keyboardHeight, on: self)
.store(in: &cancellableSet)
notificationCenter.publisher(for: UIWindow.keyboardDidHideNotification)
.map { _ in 0 }
.assign(to: \.keyboardHeight, on: self)
.store(in: &cancellableSet)
}