Skip to content

Commit

Permalink
Merge pull request #5 from michaelbabiy/migration/swift-5
Browse files Browse the repository at this point in the history
* Migrate to Swift 5.
  • Loading branch information
michaelbabiy authored Mar 29, 2019
2 parents 17c5f37 + f56a10c commit 115bc91
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
12 changes: 6 additions & 6 deletions Example/Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@
TargetAttributes = {
1C41F552203D3A160034017C = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1010;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
TestTargetID = 1C579606202BB0DD008F939A;
};
1C579606202BB0DD008F939A = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1010;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.Keychain = {
Expand Down Expand Up @@ -415,7 +415,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.alaskaairlines.KeychainTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
Expand All @@ -431,7 +431,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.alaskaairlines.KeychainTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
Expand Down Expand Up @@ -560,7 +560,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.alaskaairlines.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -577,7 +577,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.alaskaairlines.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
7 changes: 4 additions & 3 deletions Framework/Keychain.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
TargetAttributes = {
1C5795F2202BAF8E008F939A = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 0920;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
Expand All @@ -248,6 +248,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 1C5795E9202BAF8E008F939A;
productRefGroup = 1C5795F4202BAF8E008F939A /* Products */;
Expand Down Expand Up @@ -431,7 +432,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -454,7 +455,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.alaskaairlines.Keychain;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

internal extension CFString {
/// Convenience variable for returning C string as Swift string.
internal var string: String {
var string: String {
return self as String
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

public extension Keychain {
/// List of supported access options for configuring **Keychain**.
public enum Access {
enum Access {
/// Will configure **Keychain** to be specific to each app.
case appSpecific(serviceName: String)

Expand All @@ -31,7 +31,7 @@ public extension Keychain {

internal extension Keychain.Access {
/// Configuration data for the **Keychain** instance.
internal var configuration: Keychain.Configuration {
var configuration: Keychain.Configuration {
switch self {
case .appSpecific(let serviceName):
return Keychain.Configuration(serviceName: serviceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

internal extension Keychain {
/// A type that represents configuration object for the **Keychain** instance.
internal struct Configuration {
struct Configuration {
/// The access group if any.
///
/// - Note:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

internal extension Keychain {
/// Responsible for saving, deleting, and searching the **Keychain**.
internal struct Manager {
struct Manager {
/// The **Keychain** configuration data derived from **Keychain.Access** type.
private let configuration: Keychain.Configuration

Expand All @@ -38,7 +38,7 @@ internal extension Keychain.Manager {
/// Deletes item from the **Keychain**.
///
/// For documentation see: Keychain.delete()
internal func delete(_ item: KeychainItem) throws {
func delete(_ item: KeychainItem) throws {
let query = try item.query(using: configuration).CFDictionary
let status = SecItemDelete(query)

Expand All @@ -49,14 +49,14 @@ internal extension Keychain.Manager {
/// Deletes all items of specified type.
///
/// For documentation see: Keychain.deleteAll()
internal func deleteAll<T: KeychainItem>(ofType type: T.Type) throws {
func deleteAll<T: KeychainItem>(ofType type: T.Type) throws {
try items(ofType: type)?.forEach { try delete($0) }
}

/// Saves item to the **Keychain**.
///
/// For documentation see: Keychain.save()
internal func save(_ item: KeychainItem) throws {
func save(_ item: KeychainItem) throws {
// Try deleting previously saved item object matching this item query.
try delete(item)

Expand All @@ -71,14 +71,14 @@ internal extension Keychain.Manager {
/// Returns an item for specified account and service group using **idKey**.
///
/// For documentation see: Keychain.item()
internal func item<T: KeychainItem>(ofType type: T.Type, idKey: String) throws -> T? {
func item<T: KeychainItem>(ofType type: T.Type, idKey: String) throws -> T? {
return try items(ofType: type)?.filter { $0.idKey == idKey }.first
}

/// Returns an array of items for specified account and service group.
///
/// For documentation see: Keychain.items()
internal func items<T: KeychainItem>(ofType type: T.Type) throws -> [T]? {
func items<T: KeychainItem>(ofType type: T.Type) throws -> [T]? {
let query = try type.query(using: configuration)

var result: AnyObject?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import Foundation

public extension Keychain {
/// List of supported storage options for **Keychain**.
public enum Storage {
enum Storage {
/// Item will be stored as encrypted, generic passwords.
case genericPassword
}
}

internal extension Keychain.Storage {
/// C string value for a given Storage case.
internal var kSecClass: CFString {
var kSecClass: CFString {
switch self {
case .genericPassword:
return kSecClassGenericPassword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal extension KeychainItem {
/// - configuration: The configuration of the **Keychain**.
///
/// - Returns: The **KeychainQuery** object.
internal func query(using configuration: Keychain.Configuration) throws -> KeychainQuery {
func query(using configuration: Keychain.Configuration) throws -> KeychainQuery {
var query = KeychainQuery()
query[kSecClass.string] = Self.storage.kSecClass
query[kSecAttrSynchronizable.string] = Self.isSynchronizable.object
Expand All @@ -47,7 +47,7 @@ internal extension KeychainItem {
/// - configuration: The configuration of the **Keychain**.
///
/// - Returns: The **KeychainQuery** object.
internal static func query(using configuration: Keychain.Configuration) throws -> KeychainQuery {
static func query(using configuration: Keychain.Configuration) throws -> KeychainQuery {
var query = KeychainQuery()
query[kSecClass.string] = Self.storage.kSecClass
query[kSecAttrSynchronizable.string] = Self.isSynchronizable.object
Expand Down
10 changes: 5 additions & 5 deletions Framework/Keychain/Keychain/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public extension Keychain {
/// - item: The item to delete.
///
/// - Throws: **KeychainError.unhandled** containing **OSStatus** code.
public func delete(_ item: KeychainItem) throws {
func delete(_ item: KeychainItem) throws {
try manager.delete(item)
}

Expand All @@ -61,7 +61,7 @@ public extension Keychain {
/// - type: A generic type of the item.
///
/// - Throws: **KeychainError.unhandled** containing **OSStatus** code.
public func deleteAll<T: KeychainItem>(ofType type: T.Type) throws {
func deleteAll<T: KeychainItem>(ofType type: T.Type) throws {
try manager.deleteAll(ofType: type)
}

Expand Down Expand Up @@ -102,7 +102,7 @@ public extension Keychain {
/// - item: The item to save.
///
/// - Throws: **KeychainError** if the operation fails.
public func save(_ item: KeychainItem) throws {
func save(_ item: KeychainItem) throws {
try manager.save(item)
}

Expand All @@ -115,7 +115,7 @@ public extension Keychain {
/// - Throws: **KeychainError** if the operation fails.
///
/// - Returns: A newly created item of T.Type if data is found for specified **idKey**, nil otherwise.
public func item<T: KeychainItem>(ofType type: T.Type, idKey: String) throws -> T? {
func item<T: KeychainItem>(ofType type: T.Type, idKey: String) throws -> T? {
return try manager.item(ofType: type, idKey: idKey)
}

Expand All @@ -127,7 +127,7 @@ public extension Keychain {
/// - Throws: **KeychainError** if the operation fails.
///
/// - Returns: A newly created items array of T.Type if data is found, nil otherwise.
public func items<T: KeychainItem>(ofType type: T.Type) throws -> [T]? {
func items<T: KeychainItem>(ofType type: T.Type) throws -> [T]? {
return try manager.items(ofType: type)
}
}

0 comments on commit 115bc91

Please sign in to comment.