From 0cf8c2c9708bbc89cdb0dcb38517737678320925 Mon Sep 17 00:00:00 2001 From: zhengyuqi Date: Sun, 9 Dec 2018 14:55:05 +0800 Subject: [PATCH] Convert to Swift 4.2.1 --- Package.swift | 34 ++++++++++++------------- Source/Pjango/DB/PCDataBase.swift | 10 ++++---- Source/Pjango/DB/PCFileDBDataBase.swift | 6 ++--- Source/Pjango/Model/PCModel.swift | 4 +-- Source/Pjango/Plugin/PCPlugin.swift | 2 +- Source/Pjango/View/PCView.swift | 4 +-- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Package.swift b/Package.swift index 8e56389..d193578 100644 --- a/Package.swift +++ b/Package.swift @@ -1,25 +1,25 @@ +// swift-tools-version:4.2 +// The swift-tools-version declares the minimum version of Swift required to build this package. + import PackageDescription -#if os(OSX) -let package = Package( - name: "Pjango", - targets: [], - dependencies: [ - .Package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", majorVersion: 3, minor: 0), - .Package(url: "https://github.com/PerfectlySoft/Perfect-Mustache.git", majorVersion: 3, minor: 0), - .Package(url: "https://github.com/enums/SwiftyJSON.git", majorVersion: 4), - ] -) -#else let package = Package( name: "Pjango", - targets: [], + products: [ + .library( + name: "Pjango", + targets: ["Pjango"]), + ], dependencies: [ - .Package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", majorVersion: 2, minor: 0), - .Package(url: "https://github.com/PerfectlySoft/Perfect-Mustache.git", majorVersion: 2, minor: 0), - .Package(url: "https://github.com/enums/SwiftyJSON.git", majorVersion: 4), - ] + .package(url:"https://github.com/PerfectlySoft/Perfect-HTTPServer.git" , from: "3.0.19"), + .package(url:"https://github.com/PerfectlySoft/Perfect-Mustache.git" , from: "3.0.2"), + .package(url:"https://github.com/enums/Pjango-SwiftyJSON" , from: "1.0.0"), + ], + targets: [ + .target( + name: "Pjango", + dependencies: ["PerfectHTTPServer", "PerfectMustache", "SwiftyJSON"]) + ] ) -#endif diff --git a/Source/Pjango/DB/PCDataBase.swift b/Source/Pjango/DB/PCDataBase.swift index 577e305..2aaba45 100644 --- a/Source/Pjango/DB/PCDataBase.swift +++ b/Source/Pjango/DB/PCDataBase.swift @@ -22,17 +22,17 @@ open class PCDataBase { return nil } - open let config: PCDataBaseConfig + public let config: PCDataBaseConfig open var state: PCDataBaseState - open let _pjango_core_database_lock = NSLock.init() + public let _pjango_core_database_lock = NSLock.init() public init(config: PCDataBaseConfig) { self.config = config self.state = .inited } - open static var empty: PCDataBase { + public static var empty: PCDataBase { let database = PCDataBase.init(config: PCDataBaseConfig.init()) database.state = .empty return database @@ -151,7 +151,7 @@ open class PCDataBase { @discardableResult open func insertModel(_ model: PCModel) -> Bool { - let record = model._pjango_core_model_fields.flatMap { (field) -> String? in + let record = model._pjango_core_model_fields.compactMap { (field) -> String? in switch field.type { case .string: return field.strValue case .int: return "\(field.intValue)" @@ -174,7 +174,7 @@ open class PCDataBase { guard let id = model._pjango_core_model_id else { return false } - let updateStr = model._pjango_core_model_fields_key.flatMap { (key) -> String? in + let updateStr = model._pjango_core_model_fields_key.compactMap { (key) -> String? in guard let type = model._pjango_core_model_fields_type[key], let value = model._pjango_core_model_get_filed_data(key: key) else { return nil } diff --git a/Source/Pjango/DB/PCFileDBDataBase.swift b/Source/Pjango/DB/PCFileDBDataBase.swift index b30d39d..90ebd72 100644 --- a/Source/Pjango/DB/PCFileDBDataBase.swift +++ b/Source/Pjango/DB/PCFileDBDataBase.swift @@ -118,7 +118,7 @@ open class PCFileDBDataBase: PCDataBase { @discardableResult open override func insertModel(_ model: PCModel) -> Bool { - var record = model._pjango_core_model_fields.flatMap { (field) -> String? in + var record = model._pjango_core_model_fields.compactMap { (field) -> String? in switch field.type { case .string: return field.strValue case .int: return "\(field.intValue)" @@ -147,7 +147,7 @@ open class PCFileDBDataBase: PCDataBase { guard let id = model._pjango_core_model_id else { return false } - let updateStr = model._pjango_core_model_fields_key.flatMap { (key) -> String? in + let updateStr = model._pjango_core_model_fields_key.compactMap { (key) -> String? in guard let type = model._pjango_core_model_fields_type[key], let value = model._pjango_core_model_get_filed_data(key: key) else { return nil } @@ -215,7 +215,7 @@ open class PCFileDBDataBase: PCDataBase { "objs": [[String]]() ]) } else { - json = JSON.parse(str) + json = JSON.init(parseJSON: str) } guard let jsonArray = json["objs"].array else { return nil diff --git a/Source/Pjango/Model/PCModel.swift b/Source/Pjango/Model/PCModel.swift index 29fdaaf..0d172fb 100644 --- a/Source/Pjango/Model/PCModel.swift +++ b/Source/Pjango/Model/PCModel.swift @@ -111,7 +111,7 @@ open class PCModel: PCObject, PCViewable { _pjango_core_model_cache_time[_pjango_core_class_name] = nowTime.timeIntervalSince1970 records = recordsFromDB } - return records.flatMap { record in + return records.compactMap { record in var record = record let idStr = record.removeFirst() guard let id = Int64(idStr) else { @@ -146,7 +146,7 @@ open class PCModel: PCObject, PCViewable { } } - open static var meta: PCMetaModel { + public static var meta: PCMetaModel { return self.init() } diff --git a/Source/Pjango/Plugin/PCPlugin.swift b/Source/Pjango/Plugin/PCPlugin.swift index 4248535..7083273 100644 --- a/Source/Pjango/Plugin/PCPlugin.swift +++ b/Source/Pjango/Plugin/PCPlugin.swift @@ -13,7 +13,7 @@ public typealias PCMetaPlugin = PCPlugin open class PCPlugin: PCObject, PCRunable { - open static var meta: PCMetaPlugin { + public static var meta: PCMetaPlugin { return self.init() } diff --git a/Source/Pjango/View/PCView.swift b/Source/Pjango/View/PCView.swift index bd4f0e6..6636cf2 100644 --- a/Source/Pjango/View/PCView.swift +++ b/Source/Pjango/View/PCView.swift @@ -23,7 +23,7 @@ open class PCView: PCObject { return viewParam ?? PCViewParam() } - open static var meta: PCView { + public static var meta: PCView { return self.init() } @@ -39,7 +39,7 @@ open class PCView: PCObject { open weak var currentRequest: HTTPRequest? = nil - open static func asHandle() -> PCUrlHandle { + public static func asHandle() -> PCUrlHandle { let handle: RequestHandler = { req, res in let view = self.init() view.currentRequest = req