 import XCTest
 
 class TextFieldEventsRecorder {
-  var textDidBeginEditing = false
-  var textDidChange = false
-  var textDidEndEditing = false
-  var editingDidBegin = false
-  var editingChanged = false
-  var editingDidEndOnExit = false
-  var editingDidEnd = false
-
-  func registerActionBlock() -> GREYActionBlock {
+  private var textDidBeginEditing = false
+  private var textDidChange = false
+  private var textDidEndEditing = false
+  private var editingDidBegin = false
+  private var editingChanged = false
+  private var editingDidEndOnExit = false
+  private var editingDidEnd = false
+
+  func registerActionBlock() -> GREYAction {
     NotificationCenter.default.addObserver(self,
                                            selector: #selector(textDidBeginEditingHandler),
-                                           name: NSNotification.Name.UITextFieldTextDidBeginEditing,
+                                           name: .UITextFieldTextDidBeginEditing,
                                            object: nil)
     NotificationCenter.default.addObserver(self,
                                            selector: #selector(textDidChangeHandler),
-                                           name: NSNotification.Name.UITextFieldTextDidChange,
+                                           name: .UITextFieldTextDidChange,
                                            object: nil)
     NotificationCenter.default.addObserver(self,
                                            selector: #selector(textDidEndEditingHandler),
-                                           name: NSNotification.Name.UITextFieldTextDidEndEditing,
+                                           name: .UITextFieldTextDidEndEditing,
                                            object: nil)
     return GREYActionBlock.action(withName: "Register to editing events") {
-      (element: Any?, errorOrNil: UnsafeMutablePointer<NSError?>?) -> Bool in
-      let element:UIControl = element as! UIControl
-      element.addTarget(self,
-                        action: #selector(self.editingDidBeginHandler), for: .editingDidBegin)
-      element.addTarget(self,
-                        action: #selector(self.editingChangedHandler), for: .editingChanged)
+      (element, errorOrNil) in
+      let element = element as! UIControl
+      element.addTarget(self,
+                        action: #selector(self.editingDidBeginHandler),
+                        for: .editingDidBegin)
+      element.addTarget(self,
+                        action: #selector(self.editingChangedHandler),
+                        for: .editingChanged)
       element.addTarget(self,
                         action: #selector(self.editingDidEndOnExitHandler),
                         for: .editingDidEndOnExit)
       element.addTarget(self,
-                        action: #selector(self.editingDidEndHandler), for: .editingDidEnd)
+                        action: #selector(self.editingDidEndHandler),
+                        for: .editingDidEnd)
       return true
     }
   }

  }

  func testStepperActionWithCondition() {
    self.openTestView("Basic Views")
    var stepperValue = 51.0
    // Without the parameter using the value of the wait action, a warning should be seen.
    _ = GREYCondition.init(name: "conditionWithAction", block: {
      stepperValue += 1
      EarlGrey.select(elementWithMatcher: grey_kindOfClass(UIStepper.self))
        .perform(grey_setStepperValue(stepperValue))
      return stepperValue == 55
    }).waitWithTimeout(seconds: 10.0)
    EarlGrey.select(elementWithMatcher: grey_kindOfClass(UIStepper.self))
      .assert(with: grey_stepperValue(55))
  }

  func openTestView(_ name: String) {
    var errorOrNil : NSError?
    EarlGrey.select(elementWithMatcher: grey_accessibilityLabel(name))
      .perform(grey_tap(), error: &errorOrNil)
    if ((errorOrNil == nil)) {
      return
    }
    EarlGrey.select(elementWithMatcher: grey_kindOfClass(UITableView.self))

  }

  func testTypingWithError() {
    openTestView("Typing Views")
    EarlGrey.select(elementWithMatcher: grey_accessibilityID("TypingTextField"))
      .perform(grey_typeText("Sample Swift Test"))
      .assert(grey_text("Sample Swift Test"))
