Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
• Updating API to be more similar to Swift Dictionary - APIs.
• Swift Errors
• Swift 4.2 Support
  • Loading branch information
graphiclife committed Apr 1, 2019
1 parent 3c28616 commit ff2e467
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 296 deletions.
44 changes: 24 additions & 20 deletions KeyClip.xcodeproj/project.pbxproj
Expand Up @@ -360,7 +360,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0800;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "Shinichiro Aska";
TargetAttributes = {
38E53E0E1D880BF800D7F626 = {
Expand All @@ -374,8 +374,6 @@
};
38E53E251D880C1300D7F626 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = ERYSSE5R77;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.Keychain = {
enabled = 1;
Expand Down Expand Up @@ -408,7 +406,7 @@
};
buildConfigurationList = 6A6127191A299E6400C18E1D /* Build configuration list for PBXProject "KeyClip" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -610,7 +608,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "pw.aska.TestApp-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -633,7 +630,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "pw.aska.TestApp-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -646,18 +642,15 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_ENTITLEMENTS = "TestApp Mac/TestApp Mac.entitlements";
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = ERYSSE5R77;
INFOPLIST_FILE = "TestApp Mac/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "pw.aska.TestApp-Mac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -670,38 +663,44 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_ENTITLEMENTS = "TestApp Mac/TestApp Mac.entitlements";
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = ERYSSE5R77;
INFOPLIST_FILE = "TestApp Mac/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "pw.aska.TestApp-Mac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
6A6127331A299E6400C18E1D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -730,6 +729,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -740,18 +740,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -771,6 +780,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -781,6 +791,7 @@
6A6127361A299E6400C18E1D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
Expand All @@ -797,13 +808,13 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
6A6127371A299E6400C18E1D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
Expand All @@ -821,7 +832,6 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -841,7 +851,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestApp iOS.app/TestApp iOS";
};
name = Debug;
Expand All @@ -859,7 +868,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestApp iOS.app/TestApp iOS";
};
name = Release;
Expand All @@ -886,7 +894,6 @@
PRODUCT_NAME = "$(PROJECT_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -910,7 +917,6 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -930,7 +936,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "pw.aska.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestApp Mac.app/Contents/MacOS/TestApp Mac";
};
name = Debug;
Expand All @@ -949,7 +954,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestApp Mac.app/Contents/MacOS/TestApp Mac";
};
name = Release;
Expand Down
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -79,15 +79,6 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6AB293031A509297009B628E"
BuildableName = "KeyClip Mac Tests.xctest"
BlueprintName = "KeyClip Mac Tests"
ReferencedContainer = "container:KeyClip.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
3 changes: 1 addition & 2 deletions KeyClip/Builder.swift
Expand Up @@ -9,8 +9,7 @@
import Foundation

public extension KeyClip {
public class Builder {

class Builder {
var accessGroup: String?
var service: String = Bundle.main.bundleIdentifier ?? "pw.aska.KeyClip"
var accessible: String = kSecAttrAccessibleAfterFirstUnlock as String
Expand Down
62 changes: 23 additions & 39 deletions KeyClip/KeyClip.swift
Expand Up @@ -10,66 +10,50 @@ import Foundation
import Security

open class KeyClip {

// MARK: Types

fileprivate struct Static {
fileprivate static let instance = KeyClip.Builder().build()
fileprivate static var printError = false
}

open class var printError: Bool {
return Static.printError
}
fileprivate static let shared = KeyClip.Builder().build()

// MARK: Public Methods

open class func exists(_ key: String, failure: ((NSError) -> Void)? = nil) -> Bool {
return Static.instance.exists(key, failure: failure)
}

open class func save(_ key: String, data: Data, failure: ((NSError) -> Void)? = nil) -> Bool {
return Static.instance.save(key, data: data, failure: failure)
}

open class func save(_ key: String, string: String, failure: ((NSError) -> Void)? = nil) -> Bool {
return Static.instance.save(key, string: string, failure: failure)
open class func exists(_ key: String) throws -> Bool {
return try KeyClip.shared.exists(key)
}

open class func save(_ key: String, dictionary: NSDictionary, failure: ((NSError) -> Void)? = nil) -> Bool {
return Static.instance.save(key, dictionary: dictionary, failure: failure)
open class func save(data: Data, forKey key: String) throws {
return try KeyClip.shared.save(data: data, forKey: key)
}

open class func load(_ key: String, failure: ((NSError) -> Void)? = nil) -> Data? {
return Static.instance.load(key, failure: failure)
open class func save(string: String, forKey key: String) throws {
return try KeyClip.shared.save(string: string, forKey: key)
}

open class func load(_ key: String, failure: ((NSError) -> Void)? = nil) -> NSDictionary? {
return Static.instance.load(key, failure: failure)
open class func save(dictionary: [AnyHashable: Any], forKey key: String) throws {
return try KeyClip.shared.save(dictionary: dictionary, forKey: key)
}

open class func load(_ key: String, failure: ((NSError) -> Void)? = nil) -> String? {
return Static.instance.load(key, failure: failure)
open class func data(forKey key: String) throws -> Data? {
return try KeyClip.shared.data(forKey: key)
}

open class func load<T>(_ key: String, success: (NSDictionary) -> T, failure: ((NSError) -> Void)?) -> T? {
return Static.instance.load(key, success: success, failure: failure)
open class func dictionary(forKey key: String) throws -> [AnyHashable: Any]? {
return try KeyClip.shared.dictionary(forKey: key)
}

open class func load<T>(_ key: String, success: (NSDictionary) -> T) -> T? {
return Static.instance.load(key, success: success, failure: nil)
open class func string(forKey key: String) throws -> String? {
return try KeyClip.shared.string(forKey:key)
}

open class func delete(_ key: String, failure: ((NSError) -> Void)? = nil) -> Bool {
return Static.instance.delete(key, failure: failure)
open class func load<T>(_ key: String, success: ([AnyHashable: Any]) -> T) throws -> T? {
return try KeyClip.shared.load(key, success: success)
}

open class func clear(_ failure: ((NSError) -> Void)? = nil) -> Bool {
return Static.instance.clear(failure)
@discardableResult
open class func delete(_ key: String) throws -> Bool {
return try KeyClip.shared.delete(key)
}

open class func printError(_ printError: Bool) {
Static.printError = printError
@discardableResult
open class func clear() throws -> Bool {
return try KeyClip.shared.clear()
}

// MARK: Debug Methods
Expand Down

0 comments on commit ff2e467

Please sign in to comment.