Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update swift5 #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ objc version :https://github.com/yuantiku/YTKKeyValueStore
## Requirements

- iOS 9.0+
- Xcode 8.0
- Swift 3.0
- Xcode 10.0
- Swift 5.0

## Usage

Expand Down Expand Up @@ -72,7 +72,7 @@ arrayValue : return Array<AnyObject>?

Update Cartfile to include the following:
```
github "sgxiang/YTKKeyValueStore_Swift" ~> 0.4.2
github "sgxiang/YTKKeyValueStore_Swift" ~> 0.5.0
```

Run `carthage update` and [add the appropriate framework][Carthage Usage].
Expand All @@ -86,7 +86,7 @@ Update Podfile to include the following:
```ruby
use_frameworks!

pod 'YTKKeyValueStore_Swift', '~> 0.4.2'
pod 'YTKKeyValueStore_Swift', '~> 0.5.0'
```

Run `pod install`
Expand Down
2 changes: 1 addition & 1 deletion Vendor/SQLite.swift
Submodule SQLite.swift updated from 5e771a to 691fc8
31 changes: 25 additions & 6 deletions YTKKeyValueStore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = sgxiang;
TargetAttributes = {
1A5891A41A8B4F6200155614 = {
Expand All @@ -277,10 +277,11 @@
};
buildConfigurationList = 1A58919F1A8B4F6200155614 /* Build configuration list for PBXProject "YTKKeyValueStore" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 1A58919B1A8B4F6200155614;
productRefGroup = 1A5891A61A8B4F6200155614 /* Products */;
Expand Down Expand Up @@ -410,14 +411,22 @@
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 @@ -461,14 +470,22 @@
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 @@ -515,7 +532,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -536,7 +553,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.sgxiang.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -552,10 +569,11 @@
"$(inherited)",
);
INFOPLIST_FILE = YTKKeyValueStoreTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sgxiang.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -567,10 +585,11 @@
"$(inherited)",
);
INFOPLIST_FILE = YTKKeyValueStoreTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sgxiang.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion YTKKeyValueStore/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.4.2</string>
<string>0.5.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
12 changes: 6 additions & 6 deletions YTKKeyValueStore/YTKConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import UIKit
import SQLite

internal let YTKDEBUG = true
public let YTKDEBUG = true

internal let PATH_OF_DOCUMENT : String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
public let PATH_OF_DOCUMENT : String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

internal let DEFAULT_DB_NAME = "database_swift.sqlite3"
public let DEFAULT_DB_NAME = "database_swift.sqlite3"

internal let ID = Expression<String>("id")
internal let JSON = Expression<String>("json")
internal let CREATEDTIME = Expression<Date>("createdTime")
public let ID = Expression<String>("id")
public let JSON = Expression<String>("json")
public let CREATEDTIME = Expression<Date>("createdTime")
12 changes: 6 additions & 6 deletions YTKKeyValueStore/YTKKeyValueStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ public class YTKKeyValueStore{

private var db : Connection?

private init(dbPath : String!) {
private init(dbPath : String) {
db = try! Connection(dbPath)
}

convenience public init(_ dbName : String! = DEFAULT_DB_NAME , path : String! = PATH_OF_DOCUMENT) throws{
convenience public init(_ dbName : String = DEFAULT_DB_NAME , path : String = PATH_OF_DOCUMENT) throws{

self.init(dbPath:"\(path!)/\(dbName!)")
self.init(dbPath:"\(path)/\(dbName)")

guard db != nil else{
throw YTKError.dbConnectionError
}

}

public subscript (tableName : String!) -> YTKTable{
public subscript (tableName : String) -> YTKTable{
return YTKTable(db: self.db, tableName)
}

public func createTable(tableName:String!) throws{
public func createTable(tableName:String) throws{

guard YTKTable.checkTableName(tableName) else{
throw YTKError.nameFormatError
Expand All @@ -50,7 +50,7 @@ public class YTKKeyValueStore{

}

public func dropTable(tableName:String!) throws{
public func dropTable(tableName:String) throws{

guard YTKTable.checkTableName(tableName) else{
throw YTKError.nameFormatError
Expand Down
2 changes: 1 addition & 1 deletion YTKKeyValueStore/YTKSetter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ precedencegroup MultiplicationPrecedence {
higherThan: AdditionPrecedence
}

public func <- (objectId: String!, object: Any!) -> YTKSetter{
public func <- (objectId: String!, object: Any) -> YTKSetter{
return YTKSetter(objectId , object)
}
20 changes: 10 additions & 10 deletions YTKKeyValueStore/YTKTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct YTKTable{
internal let db : Connection?
internal let tableHandle : Table?

internal init(db : Connection?, _ tableName : String!){
internal init(db : Connection?, _ tableName : String){
if YTKTable.checkTableName(tableName){
self.db = db
self.name = tableName
Expand All @@ -42,7 +42,7 @@ public struct YTKTable{
}
}

internal static func checkTableName(_ tableName : String!)->Bool{
internal static func checkTableName(_ tableName : String)->Bool{
if tableName.contains(" "){
print("table name : \(tableName) format error")
return false
Expand Down Expand Up @@ -74,7 +74,7 @@ public struct YTKTable{

}

public func deletePreLike(_ objectId : String!) throws -> Int{
public func deletePreLike(_ objectId : String) throws -> Int{

do{
let changes = try db?.run(tableHandle!.filter(ID.like("\(objectId)%")).delete()) ?? 0
Expand All @@ -89,7 +89,7 @@ public struct YTKTable{
case string,number,object
}

fileprivate static func valueWithType(_ object : AnyObject!)->YTKKeyValueType{
fileprivate static func valueWithType(_ object : AnyObject)->YTKKeyValueType{
if object is String{
return .string
}else if (object as? NSNumber) != nil{
Expand All @@ -111,14 +111,14 @@ public struct YTKTable{
if filter.makeIterator().next() == nil{
do{
try db?.run( tableHandle!.insert(ID <- set.objectId,JSON <- jsonString,CREATEDTIME <- Date()) )
print("[insert] id : \(set.objectId) jsonString : \(set.jsonString!)")
print("[insert] id : \(set.objectId!) jsonString : \(set.jsonString!)")
}catch let error{
throw error
}
}else{
do{
try db?.run(query.update(JSON <- jsonString,CREATEDTIME <- Date()))
print("[update] id : \(set.objectId) jsonString : \(set.jsonString!)")
print("[update] id : \(set.objectId!) jsonString : \(set.jsonString!)")
}catch let error{
throw error
}
Expand All @@ -130,7 +130,7 @@ public struct YTKTable{

}

public func get( _ objectId : String! ) throws -> YTKObject?{
public func get( _ objectId : String ) throws -> YTKObject?{
do{
if let item = try self.getItem(objectId){
return item.itemObject
Expand All @@ -141,14 +141,14 @@ public struct YTKTable{
return nil
}

public func getItem(_ objectId :String!) throws ->YTKItem?{
public func getItem(_ objectId :String) throws ->YTKItem?{
do{
if let filter = try db?.prepare( tableHandle!.filter(ID == objectId).limit(1) ){
for v in filter{
var item = YTKItem()
item.itemId = objectId
item.itemObject = YTKObject(value: v[JSON] as AnyObject )
item.createdTime = v.get(CREATEDTIME)
item.createdTime = try? v.get(CREATEDTIME)
return item
}
}
Expand All @@ -167,7 +167,7 @@ public struct YTKTable{
var item = YTKItem()
item.itemId = vs[ID]
item.itemObject = YTKObject(value:vs[JSON] as AnyObject)
item.createdTime = vs.get(CREATEDTIME)
item.createdTime = try? vs.get(CREATEDTIME)
result.append(item)
}
}
Expand Down
6 changes: 3 additions & 3 deletions YTKKeyValueStore_Swift.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = "YTKKeyValueStore_Swift"
s.version = "0.4.2"
s.version = "0.5.0"
s.summary = "A simple Key-Value storage tool, using Sqlite as backend."
s.homepage = "https://github.com/sgxiang/YTKKeyValueStore_Swift"
s.license = "MIT"
s.author = { "sgxiang" => "[email protected]" }
s.platform = :ios, '9.0'
s.source = { :git => "https://github.com/sgxiang/YTKKeyValueStore_Swift.git", :tag => "0.4.2" }
s.source = { :git => "https://github.com/sgxiang/YTKKeyValueStore_Swift.git", :tag => "0.5.0" }
s.source_files = "YTKKeyValueStore/*.swift"
s.requires_arc = true
s.module_name = 'YTKKeyValueStore'
s.dependency "SQLite.swift", "~> 0.11.3"
s.dependency "SQLite.swift", "~> 0.12.0"
end