Hello,
I'm trying the example from the Combine in Practice video, and I'm getting the below compile error.
Use of unresolved identifier 'CombineLatest'
I have been doing the classical things.
- clean the build folder.
- verified if there are loose or redundant connexions in the storyboard.
- close the projest and restart xcode.
- delete the project data below /Library/Developper.
Without any success.
If I jump to Jump to Definition on CombineLatest in the code I'm taken directly to the definition in the Combine file.
Any help or suggestions will be most helpfull.
Regards
Lars
Xcode : 11.4.1
OS : 10.15.5 beta2
Machine : MacMini 201
Memory : 32 GO
import UIKit
import Combine
class ViewController: UIViewController {
@Published var password: String = ""
@IBAction func passwordChanged(_ sender: UITextField) {
password = sender.text ?? ""
}
@Published var passwordAgain: String = ""
@IBAction func passwordAgainChanged(_ sender: UITextField) {
passwordAgain = sender.text ?? ""
}
var validatedPassword: AnyPublisher<String?, Never> {
return CombineLatest($password, $passwordAgain) { password, passwordAgain in
guard password == passwordAgain, password.count > 8 else {return nil }
return password
}
.map { $0 == "password1" ? nil : $0 }
.eraseToAnyPublisher()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
Codes shown in WWDC videos are sort of cenceptual examples based on a beta version of the framework, which would not work as is in many cases.
Try something like this:
var validatedPassword: AnyPublisher<String?, Never> {
return Publishers.CombineLatest($password, $passwordAgain).map { (password, passwordAgain)->String? in
guard password == passwordAgain, password.count > 8 else {return nil }
return password
}
.map { $0 == "password1" ? nil : $0 }
.eraseToAnyPublisher()
}