Skip to content

Commit

Permalink
Remove state in favor of dispatch_once
Browse files Browse the repository at this point in the history
  • Loading branch information
sberrevoets committed May 19, 2016
1 parent 24cd99e commit 9b75848
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Source/AlertController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit

private var kDidAssignFirstResponderToken: dispatch_once_t = 0
/**
The alert controller's style.
Expand Down Expand Up @@ -118,7 +119,6 @@ public class AlertController: UIViewController {

@IBOutlet private var alertView: AlertControllerView! = AlertView()
private lazy var transitionDelegate: Transition = Transition(alertStyle: self.preferredStyle)
private var didAssignFirstResponder = false

// MARK: - Initialization

Expand Down Expand Up @@ -235,9 +235,10 @@ public class AlertController: UIViewController {
// Explanation of why the first responder is set here:
// http://stackoverflow.com/a/19580888/751268

if self.behaviors?.contains(.AutomaticallyFocusTextField) == true && !self.didAssignFirstResponder {
self.textFields?.first?.becomeFirstResponder()
self.didAssignFirstResponder = true
if self.behaviors?.contains(.AutomaticallyFocusTextField) == true {
dispatch_once(&kDidAssignFirstResponderToken) {
self.textFields?.first?.becomeFirstResponder()
}
}
}

Expand Down

0 comments on commit 9b75848

Please sign in to comment.