diff --git a/.swift-version b/.swift-version index 7d5c902..bf77d54 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.1 +4.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index d2fc532..1d5f636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ### Features * [Add fullKeyboardAccess feature on macOS](https://github.com/chrs1885/Capable/issues/26) +### Enhancements +* [Swift 4.2 and Xcode 10 support](https://github.com/chrs1885/Capable/pull/28) + ## Version 0.6.0 ### Enhancements diff --git a/Capable.podspec b/Capable.podspec index e282146..1f0ff11 100644 --- a/Capable.podspec +++ b/Capable.podspec @@ -12,7 +12,7 @@ Capable lets you easily keep track of accessibility settings used by your app us s.author = { 'Christoph Wendt' => 'christoph.wendt@me.com' } s.source = { :git => 'https://github.com/chrs1885/Capable.git', :tag => s.version } s.documentation_url = 'http://htmlpreview.github.io/?https://github.com/chrs1885/Capable/blob/0.6.0/Documentation/index.html' - s.swift_version = '4.1' + s.swift_version = '4.2' s.source_files = 'Source/**/*.swift' s.framework = 'Foundation' diff --git a/Capable.xcodeproj/project.pbxproj b/Capable.xcodeproj/project.pbxproj index 8ac5a34..158a18c 100644 --- a/Capable.xcodeproj/project.pbxproj +++ b/Capable.xcodeproj/project.pbxproj @@ -445,11 +445,12 @@ TargetAttributes = { 83DA75E72065167600303D8F = { CreatedOnToolsVersion = 9.2; - LastSwiftMigration = 0920; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; 83DA75F02065167600303D8F = { CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; }; @@ -737,7 +738,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 10.0; WATCHOS_DEPLOYMENT_TARGET = 4.0; @@ -765,7 +766,7 @@ SDKROOT = ""; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 10.0; WATCHOS_DEPLOYMENT_TARGET = 4.0; @@ -800,7 +801,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 10.0; WATCHOS_DEPLOYMENT_TARGET = 4.0; @@ -831,7 +832,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 10.0; WATCHOS_DEPLOYMENT_TARGET = 4.0; diff --git a/Capable.xcodeproj/xcshareddata/xcschemes/Capable.xcscheme b/Capable.xcodeproj/xcshareddata/xcschemes/Capable.xcscheme index dc7e80f..36f8e73 100644 --- a/Capable.xcodeproj/xcshareddata/xcschemes/Capable.xcscheme +++ b/Capable.xcodeproj/xcshareddata/xcschemes/Capable.xcscheme @@ -1,6 +1,6 @@ Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } @@ -41,4 +41,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } - diff --git a/Example/Source/watchOS/Extension/FontRowController.swift b/Example/Source/watchOS/Extension/FontRowController.swift index 085ec51..489b43a 100644 --- a/Example/Source/watchOS/Extension/FontRowController.swift +++ b/Example/Source/watchOS/Extension/FontRowController.swift @@ -16,7 +16,7 @@ class FontRowController: NSObject { var font: UIFont? { didSet { guard let font = font else { return } - fontLabel.setAttributedText(NSAttributedString(string: FontsConstants.defaultText, attributes: [NSAttributedStringKey.font: font])) + fontLabel.setAttributedText(NSAttributedString(string: FontsConstants.defaultText, attributes: [NSAttributedString.Key.font: font])) } } diff --git a/Source/Features/Capable.swift b/Source/Features/Capable.swift index 1bab365..7a8da4a 100644 --- a/Source/Features/Capable.swift +++ b/Source/Features/Capable.swift @@ -27,7 +27,7 @@ public struct Capable { - Parameters: - features: An optional array containing the features of interest. This will default to all features available on the current platform. */ - public init(withFeatures features: [CapableFeature] = CapableFeature.allValues()) { + public init(withFeatures features: [CapableFeature] = CapableFeature.allCases) { let featureStatusesProvider = FeatureStatusesProvider() let statusesModule = FeatureStatuses(withFeatures: features, featureStatusesProvider: featureStatusesProvider) let notificationsModule = FeatureNotifications(featureStatusesProvider: featureStatusesProvider, features: features) diff --git a/Source/Features/Models/CapableFeature.swift b/Source/Features/Models/CapableFeature.swift index 6875b21..36806bb 100644 --- a/Source/Features/Models/CapableFeature.swift +++ b/Source/Features/Models/CapableFeature.swift @@ -6,7 +6,7 @@ // /// An enum specifying all features available on the current platform. -public enum CapableFeature: String { +public enum CapableFeature: String, CaseIterable { #if os(iOS) /// Menu that helps people with motor skill impairments to do certain actions or gestures by using a single tap. @@ -77,60 +77,6 @@ public enum CapableFeature: String { /// The screen reader available on Apple platforms. case voiceOver - /** - Returns an array containing all `CapableFaeture` types available on the current platform. - - - Returns: An array containing all `CapableFaeture` types available on the current platform. - */ - public static func allValues() -> [CapableFeature] { - #if os(iOS) - return [ - .assistiveTouch, - .boldText, - .closedCaptioning, - .darkerSystemColors, - .grayscale, - .guidedAccess, - .invertColors, - .largerText, - .monoAudio, - .reduceMotion, - .reduceTransparency, - .shakeToUndo, - .speakScreen, - .speakSelection, - .switchControl, - .voiceOver] - #elseif os(tvOS) - return [ - .boldText, - .closedCaptioning, - .grayscale, - .invertColors, - .monoAudio, - .reduceMotion, - .reduceTransparency, - .switchControl, - .voiceOver] - #elseif os(watchOS) - return [ - .boldText, - .largerText, - .reduceMotion, - .voiceOver] - #elseif os(OSX) - return [ - .differentiateWithoutColor, - .fullKeyboardAccess, - .increaseContrast, - .invertColors, - .reduceMotion, - .reduceTransparency, - .switchControl, - .voiceOver] - #endif - } - /** Iterates through a given list of feature types and returns an array containing the feature names as strings. diff --git a/Source/Features/Notifications/Notifications.swift b/Source/Features/Notifications/Notifications.swift index dcc2393..a2a766e 100644 --- a/Source/Features/Notifications/Notifications.swift +++ b/Source/Features/Notifications/Notifications.swift @@ -36,56 +36,56 @@ extension Notifications { func enableNotifications(forFeatures features: [CapableFeature]) { #if os(iOS) if features.contains(.assistiveTouch) { - addObserver(for: .UIAccessibilityAssistiveTouchStatusDidChange, selector: #selector(self.assistiveTouchStatusChanged)) + addObserver(for: UIAccessibility.assistiveTouchStatusDidChangeNotification, selector: #selector(self.assistiveTouchStatusChanged)) } if features.contains(.darkerSystemColors) { - addObserver(for: .UIAccessibilityDarkerSystemColorsStatusDidChange, selector: #selector(self.darkerSystemColorsStatusChanged)) + addObserver(for: UIAccessibility.darkerSystemColorsStatusDidChangeNotification, selector: #selector(self.darkerSystemColorsStatusChanged)) } if features.contains(.guidedAccess) { - addObserver(for: .UIAccessibilityGuidedAccessStatusDidChange, selector: #selector(self.guidedAccessStatusChanged)) + addObserver(for: UIAccessibility.guidedAccessStatusDidChangeNotification, selector: #selector(self.guidedAccessStatusChanged)) } if features.contains(.largerText) { - addObserver(for: .UIContentSizeCategoryDidChange, selector: #selector(self.largerTextStatusChanged)) + addObserver(for: UIContentSizeCategory.didChangeNotification, selector: #selector(self.largerTextStatusChanged)) } if features.contains(.shakeToUndo) { - addObserver(for: .UIAccessibilityShakeToUndoDidChange, selector: #selector(self.shakeToUndoStatusChanged)) + addObserver(for: UIAccessibility.shakeToUndoDidChangeNotification, selector: #selector(self.shakeToUndoStatusChanged)) } if features.contains(.speakScreen) { - addObserver(for: .UIAccessibilitySpeakScreenStatusDidChange, selector: #selector(self.speakScreenStatusChanged)) + addObserver(for: UIAccessibility.speakScreenStatusDidChangeNotification, selector: #selector(self.speakScreenStatusChanged)) } if features.contains(.speakSelection) { - addObserver(for: .UIAccessibilitySpeakSelectionStatusDidChange, selector: #selector(self.speakSelectionStatusChanged)) + addObserver(for: UIAccessibility.speakSelectionStatusDidChangeNotification, selector: #selector(self.speakSelectionStatusChanged)) } #endif #if os(iOS) || os(tvOS) if features.contains(.boldText) { - addObserver(for: .UIAccessibilityBoldTextStatusDidChange, selector: #selector(self.boldTextStatusChanged)) + addObserver(for: UIAccessibility.boldTextStatusDidChangeNotification, selector: #selector(self.boldTextStatusChanged)) } if features.contains(.closedCaptioning) { - addObserver(for: .UIAccessibilityClosedCaptioningStatusDidChange, selector: #selector(self.closedCaptioningStatusChanged)) + addObserver(for: UIAccessibility.closedCaptioningStatusDidChangeNotification, selector: #selector(self.closedCaptioningStatusChanged)) } if features.contains(.grayscale) { - addObserver(for: .UIAccessibilityGrayscaleStatusDidChange, selector: #selector(self.grayscaleStatusChanged)) + addObserver(for: UIAccessibility.grayscaleStatusDidChangeNotification, selector: #selector(self.grayscaleStatusChanged)) } if features.contains(.invertColors) { - addObserver(for: .UIAccessibilityInvertColorsStatusDidChange, selector: #selector(self.invertColorsStatusChanged)) + addObserver(for: UIAccessibility.invertColorsStatusDidChangeNotification, selector: #selector(self.invertColorsStatusChanged)) } if features.contains(.monoAudio) { - addObserver(for: .UIAccessibilityMonoAudioStatusDidChange, selector: #selector(self.monoAudioStatusChanged)) + addObserver(for: UIAccessibility.monoAudioStatusDidChangeNotification, selector: #selector(self.monoAudioStatusChanged)) } if features.contains(.switchControl) { - addObserver(for: .UIAccessibilitySwitchControlStatusDidChange, selector: #selector(self.switchControlStatusChanged)) + addObserver(for: UIAccessibility.switchControlStatusDidChangeNotification, selector: #selector(self.switchControlStatusChanged)) } if features.contains(.reduceMotion) { - addObserver(for: .UIAccessibilityReduceMotionStatusDidChange, selector: #selector(self.reduceMotionStatusChanged)) + addObserver(for: UIAccessibility.reduceMotionStatusDidChangeNotification, selector: #selector(self.reduceMotionStatusChanged)) } if features.contains(.reduceTransparency) { - addObserver(for: .UIAccessibilityReduceTransparencyStatusDidChange, selector: #selector(self.reduceTransparencyStatusChanged)) + addObserver(for: UIAccessibility.reduceTransparencyStatusDidChangeNotification, selector: #selector(self.reduceTransparencyStatusChanged)) } if features.contains(.voiceOver) { if #available(iOS 11.0, tvOS 11.0, *) { - addObserver(for: .UIAccessibilityVoiceOverStatusDidChange, selector: #selector(self.voiceOverStatusChanged)) + addObserver(for: UIAccessibility.voiceOverStatusDidChangeNotification, selector: #selector(self.voiceOverStatusChanged)) } else { addObserver(for: Notification.Name(UIAccessibilityVoiceOverStatusChanged), selector: #selector(self.voiceOverStatusChanged)) } diff --git a/Source/Features/Statuses/FeatureStatusesProvider.swift b/Source/Features/Statuses/FeatureStatusesProvider.swift index 257a209..b231b81 100644 --- a/Source/Features/Statuses/FeatureStatusesProvider.swift +++ b/Source/Features/Statuses/FeatureStatusesProvider.swift @@ -21,15 +21,15 @@ class FeatureStatusesProvider: FeatureStatusesProviderProtocol { #if os(iOS) var isAssistiveTouchEnabled: Bool { - return UIAccessibilityIsAssistiveTouchRunning() + return UIAccessibility.isAssistiveTouchRunning } var isDarkerSystemColorsEnabled: Bool { - return UIAccessibilityDarkerSystemColorsEnabled() + return UIAccessibility.isDarkerSystemColorsEnabled } var isGuidedAccessEnabled: Bool { - return UIAccessibilityIsGuidedAccessEnabled() + return UIAccessibility.isGuidedAccessEnabled } var largerTextCatagory: UIContentSizeCategory { @@ -37,65 +37,65 @@ class FeatureStatusesProvider: FeatureStatusesProviderProtocol { } var isShakeToUndoEnabled: Bool { - return UIAccessibilityIsShakeToUndoEnabled() + return UIAccessibility.isShakeToUndoEnabled } var isSpeakScreenEnabled: Bool { - return UIAccessibilityIsSpeakScreenEnabled() + return UIAccessibility.isSpeakScreenEnabled } var isSpeakSelectionEnabled: Bool { - return UIAccessibilityIsSpeakSelectionEnabled() + return UIAccessibility.isSpeakSelectionEnabled } #endif #if os(iOS) || os(tvOS) var isBoldTextEnabled: Bool { - return UIAccessibilityIsBoldTextEnabled() + return UIAccessibility.isBoldTextEnabled } var isClosedCaptioningEnabled: Bool { - return UIAccessibilityIsClosedCaptioningEnabled() + return UIAccessibility.isClosedCaptioningEnabled } var isGrayscaleEnabled: Bool { - return UIAccessibilityIsGrayscaleEnabled() + return UIAccessibility.isGrayscaleEnabled } var isInvertColorsEnabled: Bool { - return UIAccessibilityIsInvertColorsEnabled() + return UIAccessibility.isInvertColorsEnabled } var isMonoAudioEnabled: Bool { - return UIAccessibilityIsMonoAudioEnabled() + return UIAccessibility.isMonoAudioEnabled } var isReduceMotionEnabled: Bool { - return UIAccessibilityIsReduceMotionEnabled() + return UIAccessibility.isReduceMotionEnabled } var isReduceTransparencyEnabled: Bool { - return UIAccessibilityIsReduceTransparencyEnabled() + return UIAccessibility.isReduceTransparencyEnabled } var isSwitchControlEnabled: Bool { - return UIAccessibilityIsSwitchControlRunning() + return UIAccessibility.isSwitchControlRunning } var isVoiceOverEnabled: Bool { - return UIAccessibilityIsVoiceOverRunning() + return UIAccessibility.isVoiceOverRunning } #endif #if os(watchOS) var isBoldTextEnabled: Bool { - let referenceFont = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) + let referenceFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body) let isBoldText = referenceFont.fontName.localizedCaseInsensitiveContains("bold") return isBoldText } var largerTextCatagory: String { - let referenceFontSize = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body).pointSize + let referenceFontSize = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body).pointSize return referenceFontSize.contentSizeString } diff --git a/Source/Features/Statuses/FeatureStatusesProviderProtocol.swift b/Source/Features/Statuses/FeatureStatusesProviderProtocol.swift index fd8351a..535f8dc 100644 --- a/Source/Features/Statuses/FeatureStatusesProviderProtocol.swift +++ b/Source/Features/Statuses/FeatureStatusesProviderProtocol.swift @@ -40,7 +40,7 @@ protocol FeatureStatusesProviderProtocol { #if os(OSX) var isDifferentiateWithoutColorEnabled: Bool { get } var isFullKeyboardAccessEnabled: Bool { get } - var isIncreaseContrastEnabled: Bool { get } + var isIncreaseContrastEnabled: Bool { get } #endif #if os(watchOS) diff --git a/Tests/Features/CapablePerfTests.swift b/Tests/Features/CapablePerfTests.swift index a558c6f..76892e2 100644 --- a/Tests/Features/CapablePerfTests.swift +++ b/Tests/Features/CapablePerfTests.swift @@ -15,7 +15,7 @@ class CapablePerfTests: XCTestCase { override func setUp() { super.setUp() - sut = Capable(withFeatures: CapableFeature.allValues()) + sut = Capable(withFeatures: CapableFeature.allCases) } func testStatusMapPerformance() { diff --git a/Tests/Features/CapableTests.swift b/Tests/Features/CapableTests.swift index 5bef843..7627a74 100644 --- a/Tests/Features/CapableTests.swift +++ b/Tests/Features/CapableTests.swift @@ -69,7 +69,7 @@ class CapableTests: QuickSpec { } it("registeres all features") { - expect(sut!.features).to(equal(CapableFeature.allValues())) + expect(sut!.features).to(equal(CapableFeature.allCases)) } } diff --git a/Tests/Features/FeatureNotificationsTests.swift b/Tests/Features/FeatureNotificationsTests.swift index 9bf1c71..fe16557 100644 --- a/Tests/Features/FeatureNotificationsTests.swift +++ b/Tests/Features/FeatureNotificationsTests.swift @@ -65,14 +65,14 @@ class FeatureNotificationsTests: QuickSpec { #if os(iOS) || os(tvOS) - let placeholderNotification = NSNotification(name: .UIAccessibilitySpeakScreenStatusDidChange, object: nil) + let placeholderNotification = NSNotification(name: UIAccessibility.speakScreenStatusDidChangeNotification, object: nil) context("after initialization with all features available") { var sut: FeatureNotifications? var testFeatures: [CapableFeature]? beforeEach { - testFeatures = CapableFeature.allValues() + testFeatures = CapableFeature.allCases sut = FeatureNotifications(featureStatusesProvider: featureStatusesProviderMock!, features: testFeatures!, notificationCenter: notificationCenterMock!) } diff --git a/Tests/Features/FeatureStatusesTests.swift b/Tests/Features/FeatureStatusesTests.swift index 6d62919..0ca26e6 100644 --- a/Tests/Features/FeatureStatusesTests.swift +++ b/Tests/Features/FeatureStatusesTests.swift @@ -25,7 +25,7 @@ class FeatureStatusesTests: QuickSpec { var testFeatures: [CapableFeature]? beforeEach { - testFeatures = CapableFeature.allValues() + testFeatures = CapableFeature.allCases sut = FeatureStatuses(withFeatures: testFeatures!, featureStatusesProvider: featureStatusesProviderMock!) } diff --git a/Tests/Features/HandicapNotificationsTests.swift b/Tests/Features/HandicapNotificationsTests.swift index afd8dc0..4e752b6 100644 --- a/Tests/Features/HandicapNotificationsTests.swift +++ b/Tests/Features/HandicapNotificationsTests.swift @@ -70,7 +70,7 @@ class HandicapNotificationsTests: QuickSpec { #if os(iOS) || os(tvOS) - let placeholderNotification = NSNotification(name: .UIAccessibilitySpeakScreenStatusDidChange, object: nil) + let placeholderNotification = NSNotification(name: UIAccessibility.speakScreenStatusDidChangeNotification, object: nil) context("after initialization with two Handicaps containing the same feature") { var sut: HandicapNotifications? diff --git a/Tests/Features/Mocks/NotificationCenterMock.swift b/Tests/Features/Mocks/NotificationCenterMock.swift index 82e008b..5948023 100644 --- a/Tests/Features/Mocks/NotificationCenterMock.swift +++ b/Tests/Features/Mocks/NotificationCenterMock.swift @@ -7,6 +7,10 @@ #if os(iOS) || os(tvOS) || os(OSX) +#if os(iOS) || os(tvOS) +import UIKit +#endif + @testable import Capable class NotificationCenterMock: NotificationCenter { @@ -28,7 +32,7 @@ class NotificationCenterMock: NotificationCenter { func hasRegisteredNotification(forFeature feature: CapableFeature) -> Bool { #if os(iOS) if feature == .largerText { - return self.observedNotifications.contains(.UIContentSizeCategoryDidChange) + return self.observedNotifications.contains(UIContentSizeCategory.didChangeNotification) } #endif @@ -46,7 +50,7 @@ class NotificationCenterMock: NotificationCenter { #if os(iOS) if feature == .largerText { - return notificationNames.contains(.UIContentSizeCategoryDidChange) + return notificationNames.contains(UIContentSizeCategory.didChangeNotification) } #endif