Skip to content

Commit

Permalink
update as per swift 4 changes to protocol behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbnjmn committed Sep 27, 2017
1 parent 33986fa commit 3b865e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions RapidA11y/Rapid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import UIKit

public protocol RapidAccessible {
associatedtype Control: RapidControlIdentifiable
static func rapidControlsInformation() -> [RapidControlInformation]
var accessibilityControls: [Control] { get }
func rapidAccessibilityControls() -> [NSObject]
}

public protocol RapidIdentifiable {
associatedtype Control: RapidControlIdentifiable
func accessibilityControls() -> [Control]
func applyAccessibility()
}

Expand Down
8 changes: 5 additions & 3 deletions RapidA11y/UIViewController+Rapid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import UIKit
extension UIViewController: RapidIdentifiable {
public typealias Control = NSObject

open var accessibilityControls: [Control] {
open func accessibilityControls() -> [Control] {
// Override this in your view controllers
// put actual references to UIControls in your views
return []
Expand All @@ -36,11 +36,13 @@ extension UIViewController: RapidIdentifiable {
let selfType = type(of: accessibleSelf)
view.accessibilityIdentifier = "\(selfType)\(RapidControlInformation.viewIdentifierSuffix)"
let controlsInformation: [RapidControlInformation] = selfType.rapidControlsInformation()
guard controlsInformation.count == accessibilityControls.count else {
let controls: [NSObject] = accessibleSelf.rapidAccessibilityControls()
guard controlsInformation.count == controls.count else {
assertionFailure("Mismatch on number of controls given to Rapid")
return
}
_ = accessibilityControls.enumerated().map { index, control in

_ = controls.enumerated().map { index, control in
control.applyProperties(index, classOverride: controlsInformation[index].type)
}
}
Expand Down
2 changes: 1 addition & 1 deletion RapidDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ViewController: UIViewController, RapidAccessible {
}
}

public override var accessibilityControls: [NSObject] {
public func rapidAccessibilityControls() -> [NSObject] {
return [buttonA, buttonB, buttonC, buttonD]
}

Expand Down

0 comments on commit 3b865e8

Please sign in to comment.