├── .gitignore ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Example.xcscheme ├── Example.xcworkspace │ └── contents.xcworkspacedata ├── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── CustomDAO.swift │ ├── CustomModel+DAO.swift │ ├── CustomModel.swift │ ├── DateTransform.swift │ ├── Info.plist │ ├── NestModel+Map.swift │ ├── NestModel.swift │ └── ViewController.swift ├── ExampleTests │ ├── ExampleTests.swift │ └── Info.plist ├── Podfile ├── Podfile.lock └── Pods │ ├── Local Podspecs │ ├── ModelAdapter.podspec.json │ └── ModelAdaptor.podspec.json │ ├── Manifest.lock │ ├── ObjectMapper │ ├── LICENSE │ ├── README-CN.md │ └── Sources │ │ ├── CodableTransform.swift │ │ ├── CustomDateFormatTransform.swift │ │ ├── DataTransform.swift │ │ ├── DateFormatterTransform.swift │ │ ├── DateTransform.swift │ │ ├── DictionaryTransform.swift │ │ ├── EnumOperators.swift │ │ ├── EnumTransform.swift │ │ ├── FromJSON.swift │ │ ├── HexColorTransform.swift │ │ ├── ISO8601DateTransform.swift │ │ ├── ImmutableMappable.swift │ │ ├── IntegerOperators.swift │ │ ├── Map.swift │ │ ├── MapError.swift │ │ ├── Mappable.swift │ │ ├── Mapper.swift │ │ ├── NSDecimalNumberTransform.swift │ │ ├── Operators.swift │ │ ├── ToJSON.swift │ │ ├── TransformOf.swift │ │ ├── TransformOperators.swift │ │ ├── TransformType.swift │ │ └── URLTransform.swift │ ├── Pods.xcodeproj │ └── project.pbxproj │ ├── SQLite.swift │ ├── LICENSE.txt │ ├── README.md │ └── Sources │ │ ├── SQLite │ │ ├── Core │ │ │ ├── Blob.swift │ │ │ ├── Connection.swift │ │ │ ├── Errors.swift │ │ │ ├── Statement.swift │ │ │ └── Value.swift │ │ ├── Extensions │ │ │ ├── FTS4.swift │ │ │ ├── FTS5.swift │ │ │ └── RTree.swift │ │ ├── Foundation.swift │ │ ├── Helpers.swift │ │ ├── SQLite.h │ │ └── Typed │ │ │ ├── AggregateFunctions.swift │ │ │ ├── Coding.swift │ │ │ ├── Collation.swift │ │ │ ├── CoreFunctions.swift │ │ │ ├── CustomFunctions.swift │ │ │ ├── DateAndTimeFunctions.swift │ │ │ ├── Expression.swift │ │ │ ├── Operators.swift │ │ │ ├── Query.swift │ │ │ ├── Schema.swift │ │ │ └── Setter.swift │ │ └── SQLiteObjc │ │ ├── SQLiteObjc.m │ │ ├── fts3_tokenizer.h │ │ └── include │ │ └── SQLiteObjc.h │ ├── SQLiteValueExtension │ ├── LICENSE │ ├── README-CN.md │ └── Sources │ │ └── SQLiteValueExtension.swift │ └── Target Support Files │ ├── ModelAdapter │ ├── ModelAdapter-Info.plist │ ├── ModelAdapter-dummy.m │ ├── ModelAdapter-prefix.pch │ ├── ModelAdapter-umbrella.h │ ├── ModelAdapter.debug.xcconfig │ ├── ModelAdapter.modulemap │ └── ModelAdapter.release.xcconfig │ ├── ObjectMapper │ ├── ObjectMapper-Info.plist │ ├── ObjectMapper-dummy.m │ ├── ObjectMapper-prefix.pch │ ├── ObjectMapper-umbrella.h │ ├── ObjectMapper.debug.xcconfig │ ├── ObjectMapper.modulemap │ └── ObjectMapper.release.xcconfig │ ├── Pods-Example │ ├── Pods-Example-Info.plist │ ├── Pods-Example-acknowledgements.markdown │ ├── Pods-Example-acknowledgements.plist │ ├── Pods-Example-dummy.m │ ├── Pods-Example-frameworks-Debug-input-files.xcfilelist │ ├── Pods-Example-frameworks-Debug-output-files.xcfilelist │ ├── Pods-Example-frameworks-Release-input-files.xcfilelist │ ├── Pods-Example-frameworks-Release-output-files.xcfilelist │ ├── Pods-Example-frameworks.sh │ ├── Pods-Example-umbrella.h │ ├── Pods-Example.debug.xcconfig │ ├── Pods-Example.modulemap │ └── Pods-Example.release.xcconfig │ ├── SQLite.swift │ ├── SQLite.swift-Info.plist │ ├── SQLite.swift-dummy.m │ ├── SQLite.swift-prefix.pch │ ├── SQLite.swift-umbrella.h │ ├── SQLite.swift.debug.xcconfig │ ├── SQLite.swift.modulemap │ └── SQLite.swift.release.xcconfig │ └── SQLiteValueExtension │ ├── SQLiteValueExtension-Info.plist │ ├── SQLiteValueExtension-dummy.m │ ├── SQLiteValueExtension-prefix.pch │ ├── SQLiteValueExtension-umbrella.h │ ├── SQLiteValueExtension.debug.xcconfig │ ├── SQLiteValueExtension.modulemap │ └── SQLiteValueExtension.release.xcconfig ├── LICENSE ├── ModelAdapter.podspec ├── ModelAdapter.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── ModelAdapter └── ModelAdapter.h ├── README.md └── Sources ├── Core ├── Defines.swift ├── Field.swift └── KeyManager.swift └── Storage ├── ModelAdapterDAO.swift └── StorageWrappedProtocol.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | IDEWorkspaceChecks.plist 92 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 68 | 69 | 70 | 71 | 77 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Example/Example.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by jiaxin on 2020/6/14. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Example/Example/CustomDAO.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomDAO.swift 3 | // Example 4 | // 5 | // Created by jiaxin on 2020/6/15. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ModelAdapter 11 | import SQLite 12 | 13 | class CustomDAO: ModelAdapterDAO { 14 | typealias Entity = CustomModel 15 | var connection: Connection = try! Connection("\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/db.sqlite3") 16 | var table: Table = Table("user") 17 | 18 | required init() { 19 | } 20 | 21 | func customUpdate(entity: Entity) throws { 22 | let statement = table.update(entity.$nickName.expression <- "自定义更新") 23 | try connection.run(statement) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Example/Example/CustomModel+DAO.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomModel+DAO.swift 3 | // Example 4 | // 5 | // Created by jiaxin on 2020/7/2. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SQLite 11 | import ModelAdapter 12 | 13 | //因为SQLite和ObjectMapper都有<-操作符,为了避免冲突,数据库存储自定义部分就单独创建一个文件。 14 | extension CustomModel: ModelAdapterModelCustomStorage { 15 | static let customSetExpression = Expression("custom_set") 16 | 17 | /* 18 | //如果是数据库表单创建之后新增的自定义属性,就通过addColumnStatements方法创建Field。 19 | func addColumnStatements(table: Table) -> [String]? { 20 | return [table.addColumn(CustomModel.customSetExpression)] 21 | } 22 | */ 23 | func createColumn(tableBuilder: TableBuilder) { 24 | tableBuilder.column(CustomModel.customSetExpression) 25 | } 26 | func setters() -> [Setter] { 27 | guard let set = customSet else { 28 | return [] 29 | } 30 | guard let data = try? JSONSerialization.data(withJSONObject: Array(set), options: []) else { 31 | return [] 32 | } 33 | return [CustomModel.customSetExpression <- String(data: data, encoding: .utf8)] 34 | } 35 | mutating func update(with row: Row) { 36 | guard let string = row[CustomModel.customSetExpression] else { 37 | return 38 | } 39 | let data = Data(string.utf8) 40 | guard let stringArray = try? JSONSerialization.jsonObject(with: data, options: []) as? [String] else { 41 | return 42 | } 43 | self.customSet = Set(stringArray) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Example/Example/CustomModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomModel.swift 3 | // Example 4 | // 5 | // Created by jiaxin on 2020/6/14. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ModelAdapter 11 | import ObjectMapper 12 | import SQLiteValueExtension 13 | 14 | struct CustomModel: ModelAdapterModel, Mappable { 15 | @Field(key: "accountID_key", primaryKey: true) 16 | var accountID: String = "" 17 | @FieldOptional(key: "nick_name") 18 | var nickName: String? 19 | @Field 20 | var amount: Double = 6 21 | @FieldOptional 22 | var phone: String? 23 | @FieldOptional 24 | var gender: Gender? 25 | @FieldOptional(key: "birthday") 26 | var birthday: Date? 27 | //`Array.Element`、`Dictionary.Key`、`Dictionary.Value`和自定义数据类型遵从`SQLiteValueStorable`协议,就可以通过`SQLite.swift`存储到数据库。 28 | @Field 29 | var nest: NestModel = NestModel(JSON: [String : Any]())! 30 | @Field 31 | var nests: [NestModel] = [NestModel]() 32 | @FieldOptional 33 | var customDict: [String: NestModel]? 34 | @FieldOptional 35 | var customDictInt: [Int : NestModel]? 36 | @FieldOptional 37 | var customDictAarray: [String: [NestModel]]? 38 | 39 | //如果值类型没有遵从`SQLiteValueStorable`,就不能使用@Field。需要遵从`ModelAdapterModelCustomStorage`协议,然后自己处理数据的存储流程。 40 | var customSet: Set? = nil 41 | 42 | init() { 43 | initFieldExpressions() 44 | } 45 | init?(map: Map) { 46 | self.init() 47 | } 48 | mutating func mapping(map: Map) { 49 | accountID <- map["accountID_key"] 50 | nickName <- map["nick_name"] 51 | amount <- map["amount"] 52 | phone <- map["phone"] 53 | gender <- map["gender"] 54 | birthday <- (map["birthday_coding"], DateTransform()) 55 | nest <- map["nest"] 56 | nests <- map["nests"] 57 | customDict <- map["custom_dict"] 58 | customDictAarray <- map["custom_dict_array"] 59 | customDictInt <- map["custom_dict_int"] 60 | customSet <- map["custom_set"] 61 | } 62 | } 63 | 64 | enum Gender: String, SQLiteValueStorable { 65 | case unknow = "UnKnown" 66 | case female = "Female" 67 | case male = "Male" 68 | 69 | static func fromStringValue(_ stringValue: String) -> Gender { 70 | return Gender(rawValue: stringValue) ?? .unknow 71 | } 72 | var stringValue: String { 73 | return rawValue 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Example/Example/DateTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DateTransform.swift 3 | // Example 4 | // 5 | // Created by jiaxin on 2020/6/14. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ObjectMapper 11 | 12 | class DateTransform: TransformType { 13 | public typealias Object = Date 14 | public typealias JSON = String 15 | 16 | public init() {} 17 | 18 | open func transformFromJSON(_ value: Any?) -> Date? { 19 | if let timeInt = value as? Double { 20 | return Date(timeIntervalSince1970: TimeInterval(timeInt)) 21 | } 22 | 23 | if let timeStr = value as? String { 24 | let dateFormatter = DateFormatter() 25 | dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" 26 | return dateFormatter.date(from: timeStr) 27 | } 28 | 29 | return nil 30 | } 31 | 32 | open func transformToJSON(_ value: Date?) -> String? { 33 | if let date = value { 34 | let dateFormatter = DateFormatter() 35 | dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" 36 | return dateFormatter.string(from: date) 37 | } 38 | return nil 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/Example/NestModel+Map.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NestModel+Ex.swift 3 | // Example 4 | // 5 | // Created by tony on 2021/10/20. 6 | // Copyright © 2021 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ObjectMapper 11 | 12 | extension NestModel: Mappable { 13 | 14 | init?(map: Map) { 15 | self.init() 16 | } 17 | mutating func mapping(map: Map) { 18 | nestName <- map["nest_name"] 19 | nestAge <- map["age"] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example/Example/NestModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NestModel.swift 3 | // Example 4 | // 5 | // Created by tony on 2021/10/20. 6 | // Copyright © 2021 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ModelAdapter 11 | import SQLiteValueExtension 12 | import SQLite 13 | 14 | struct NestModel: ModelAdapterModel, SQLiteValueStorable { 15 | @FieldOptional(key: "nest_name") 16 | var nestName: String? 17 | @Field(key: "age") 18 | var nestAge: Int = 0 19 | 20 | init() { 21 | initFieldExpressions() 22 | } 23 | 24 | static func fromStringValue(_ stringValue: String) -> NestModel { 25 | return NestModel(JSONString: stringValue) ?? NestModel(JSON: [String : Any]())! 26 | } 27 | var stringValue: String { 28 | return toJSONString() ?? "" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by jiaxin on 2020/6/14. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SQLite 11 | import ModelAdapter 12 | import ObjectMapper 13 | 14 | class ViewController: UIViewController { 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | let model = createModel() 20 | print(model) 21 | let dao = CustomDAO() 22 | dao.createTable() 23 | try? dao.insert(entity: model) 24 | model.nickName = "更新后" 25 | //需要导入SQLite,下面==操作符才能正确识别 26 | try? dao.update(entity: model, model.$nickName.expression == "昵称") 27 | 28 | if let queryAll = try? dao.queryAll() { 29 | print(queryAll) 30 | } 31 | } 32 | 33 | func createModel() -> CustomModel { 34 | let jsonDict = [ 35 | "accountID_key" : UUID().uuidString, 36 | "nick_name" : "昵称", 37 | "amount" : Double(100), 38 | "phone" : "123123123", 39 | "gender" : Gender.male, 40 | "avatar_key" : "avatar", 41 | "birthday_coding" : "2020-08-08 06:06:06", 42 | "nest" : ["nest_name" : "嵌套名字", "age" : 123], 43 | "nests" : [["nest_name" : "嵌套名字", "age" : 123]], 44 | "custom_dict" : ["custom1" : ["nest_name" : "嵌套名字", "age" : 123]], 45 | "custom_dict_array" : ["custom1" : [["nest_name" : "嵌套名字", "age" : 123]]], 46 | "custom_dict_int" : [1 : ["nest_name" : "嵌套名字", "age" : 123]], 47 | "custom_set" : Set.init(["1", "2", "3"]) 48 | ] as [String : Any] 49 | return CustomModel(JSON: jsonDict)! 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Example/ExampleTests/ExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleTests.swift 3 | // ExampleTests 4 | // 5 | // Created by jiaxin on 2021/4/15. 6 | // Copyright © 2021 jiaxin. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import ModelAdapter 11 | import SQLite 12 | 13 | class ExampleTests: XCTestCase { 14 | 15 | override class func setUp() { 16 | let dao = CustomDAO() 17 | dao.createTable() 18 | } 19 | 20 | override func setUpWithError() throws { 21 | // Put setup code here. This method is called before the invocation of each test method in the class. 22 | let dao = CustomDAO() 23 | try? dao.deleteAll() 24 | } 25 | 26 | override func tearDownWithError() throws { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | } 29 | 30 | func testInsertSingle() throws { 31 | let dao = CustomDAO() 32 | let model = createModel() 33 | try? dao.insert(entity: model) 34 | let all = try? dao.queryAll() 35 | XCTAssert(all?.count == 1) 36 | } 37 | 38 | func testInsertArray() throws { 39 | let dao = CustomDAO() 40 | let model = createModel() 41 | try? dao.insert(entities: [model, model]) 42 | let all = try? dao.queryAll() 43 | XCTAssert(all?.count == 2) 44 | } 45 | 46 | func testDelete() throws { 47 | let dao = CustomDAO() 48 | let model = createModel() 49 | try? dao.insert(entity: model) 50 | model.nickName = "new nick" 51 | try? dao.insert(entity: model) 52 | try? dao.delete(model.$nickName.expression == "昵称") 53 | let all = try? dao.queryAll() 54 | XCTAssert(all?.count == 1) 55 | XCTAssert(all?.first?.nickName == "new nick") 56 | } 57 | 58 | func testUpdate() throws { 59 | // This is an example of a functional test case. 60 | // Use XCTAssert and related functions to verify your tests produce the correct results. 61 | let dao = CustomDAO() 62 | let model = createModel() 63 | try? dao.insert(entity: model) 64 | model.nickName = "更新后" 65 | try? dao.update(entity: model, model.$nickName.expression == "昵称") 66 | let all = try? dao.queryAll() 67 | XCTAssert(all?.last?.nickName == "更新后", "Update failed!") 68 | } 69 | 70 | func testQuery() throws { 71 | let dao = CustomDAO() 72 | let model = createModel() 73 | try? dao.insert(entity: model) 74 | model.nickName = "new nick" 75 | try? dao.insert(entity: model) 76 | 77 | let target1 = try? dao.query(model.$nickName.expression == "new nick") 78 | XCTAssert(target1?.nickName == "new nick") 79 | 80 | let target2 = try? dao.query(model.$nickName.expression == "昵称") 81 | XCTAssert(target2?.nickName == "昵称") 82 | } 83 | 84 | func createModel() -> CustomModel { 85 | let jsonDict = [ 86 | "accountID_key" : UUID().uuidString, 87 | "userName" : "用户名", 88 | "nick_name" : "昵称", 89 | "amount" : Double(100), 90 | "phone" : "123123123", 91 | "gender" : Gender.male, 92 | "avatar_key" : "avatar", 93 | "birthday_coding" : "2020-08-08 06:06:06", 94 | "level" : 10, 95 | "registerDate" : "2020-08-08 06:06:06", 96 | "has_money" : true, 97 | "nest" : ["nest_name" : "嵌套名字", "age" : 123], 98 | "nests" : [["nest_name" : "嵌套名字", "age" : 123]], 99 | "custom_dict" : ["custom1" : ["nest_name" : "嵌套名字", "age" : 123]], 100 | "custom_dict_array" : ["custom1" : [["nest_name" : "嵌套名字", "age" : 123]]], 101 | "custom_dict_int" : [1 : ["nest_name" : "嵌套名字", "age" : 123]], 102 | "custom_set" : ["1", "2", "3"] 103 | ] as [String : Any] 104 | return CustomModel(JSON: jsonDict)! 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Example/ExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | platform :ios, '9.0' 3 | 4 | target 'Example' do 5 | # Comment the next line if you don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for Example 9 | pod 'ModelAdapter', :path => '../../ModelAdapter' 10 | pod 'ObjectMapper' 11 | 12 | end 13 | -------------------------------------------------------------------------------- /Example/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - ModelAdapter (0.0.5): 3 | - SQLite.swift 4 | - SQLiteValueExtension (~> 0.0.7) 5 | - ObjectMapper (4.2.0) 6 | - SQLite.swift (0.13.0): 7 | - SQLite.swift/standard (= 0.13.0) 8 | - SQLite.swift/standard (0.13.0) 9 | - SQLiteValueExtension (0.0.7): 10 | - SQLite.swift 11 | 12 | DEPENDENCIES: 13 | - ModelAdapter (from `../../ModelAdapter`) 14 | - ObjectMapper 15 | 16 | SPEC REPOS: 17 | trunk: 18 | - ObjectMapper 19 | - SQLite.swift 20 | - SQLiteValueExtension 21 | 22 | EXTERNAL SOURCES: 23 | ModelAdapter: 24 | :path: "../../ModelAdapter" 25 | 26 | SPEC CHECKSUMS: 27 | ModelAdapter: d57b9ba6b3571a11e6bb13fbfe1b6265c5b4cb59 28 | ObjectMapper: 1eb41f610210777375fa806bf161dc39fb832b81 29 | SQLite.swift: 8add701609fd0ef78d097dcc75d20a9782e6f5fc 30 | SQLiteValueExtension: 743b16c035639bd219168e2fe0ab131b22378794 31 | 32 | PODFILE CHECKSUM: 9476876cf52c6d4a61effb55decad8177d06a1b8 33 | 34 | COCOAPODS: 1.10.2 35 | -------------------------------------------------------------------------------- /Example/Pods/Local Podspecs/ModelAdapter.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ModelAdapter", 3 | "version": "0.0.5", 4 | "summary": "ModelAdapter", 5 | "homepage": "https://github.com/pujiaxin33/ModelAdapter", 6 | "license": "MIT", 7 | "authors": { 8 | "pujiaxin33": "317437084@qq.com" 9 | }, 10 | "platforms": { 11 | "ios": "9.0" 12 | }, 13 | "swift_versions": "5.0", 14 | "source": { 15 | "git": "https://github.com/pujiaxin33/ModelAdapter.git", 16 | "tag": "0.0.5" 17 | }, 18 | "frameworks": "UIKit", 19 | "source_files": [ 20 | "Sources", 21 | "Sources/**/*.{swift}" 22 | ], 23 | "requires_arc": true, 24 | "dependencies": { 25 | "SQLite.swift": [ 26 | 27 | ], 28 | "SQLiteValueExtension": [ 29 | "~> 0.0.7" 30 | ] 31 | }, 32 | "swift_version": "5.0" 33 | } 34 | -------------------------------------------------------------------------------- /Example/Pods/Local Podspecs/ModelAdaptor.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ModelAdaptor", 3 | "version": "0.0.4", 4 | "summary": "ModelAdaptor", 5 | "homepage": "https://github.com/pujiaxin33/ModelAdaptor", 6 | "license": "MIT", 7 | "authors": { 8 | "pujiaxin33": "317437084@qq.com" 9 | }, 10 | "platforms": { 11 | "ios": "9.0" 12 | }, 13 | "swift_versions": "5.1", 14 | "source": { 15 | "git": "https://github.com/pujiaxin33/ModelAdaptor.git", 16 | "tag": "0.0.4" 17 | }, 18 | "frameworks": "UIKit", 19 | "source_files": [ 20 | "Sources", 21 | "Sources/**/*.{swift}" 22 | ], 23 | "requires_arc": true, 24 | "dependencies": { 25 | "SQLite.swift": [ 26 | 27 | ], 28 | "SQLiteValueExtension": [ 29 | 30 | ] 31 | }, 32 | "swift_version": "5.1" 33 | } 34 | -------------------------------------------------------------------------------- /Example/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - ModelAdapter (0.0.5): 3 | - SQLite.swift 4 | - SQLiteValueExtension (~> 0.0.7) 5 | - ObjectMapper (4.2.0) 6 | - SQLite.swift (0.13.0): 7 | - SQLite.swift/standard (= 0.13.0) 8 | - SQLite.swift/standard (0.13.0) 9 | - SQLiteValueExtension (0.0.7): 10 | - SQLite.swift 11 | 12 | DEPENDENCIES: 13 | - ModelAdapter (from `../../ModelAdapter`) 14 | - ObjectMapper 15 | 16 | SPEC REPOS: 17 | trunk: 18 | - ObjectMapper 19 | - SQLite.swift 20 | - SQLiteValueExtension 21 | 22 | EXTERNAL SOURCES: 23 | ModelAdapter: 24 | :path: "../../ModelAdapter" 25 | 26 | SPEC CHECKSUMS: 27 | ModelAdapter: d57b9ba6b3571a11e6bb13fbfe1b6265c5b4cb59 28 | ObjectMapper: 1eb41f610210777375fa806bf161dc39fb832b81 29 | SQLite.swift: 8add701609fd0ef78d097dcc75d20a9782e6f5fc 30 | SQLiteValueExtension: 743b16c035639bd219168e2fe0ab131b22378794 31 | 32 | PODFILE CHECKSUM: 9476876cf52c6d4a61effb55decad8177d06a1b8 33 | 34 | COCOAPODS: 1.10.2 35 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2014 Hearst 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/CodableTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CodableTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Jari Kalinainen on 10/10/2018. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | /// Transforms JSON dictionary to Codable type T and back 32 | open class CodableTransform: TransformType { 33 | 34 | public typealias Object = T 35 | public typealias JSON = Any 36 | 37 | public init() {} 38 | 39 | open func transformFromJSON(_ value: Any?) -> Object? { 40 | var _data: Data? = nil 41 | switch value { 42 | case let dict as [String : Any]: 43 | _data = try? JSONSerialization.data(withJSONObject: dict, options: []) 44 | case let array as [[String : Any]]: 45 | _data = try? JSONSerialization.data(withJSONObject: array, options: []) 46 | default: 47 | _data = nil 48 | } 49 | guard let data = _data else { return nil } 50 | 51 | do { 52 | let decoder = JSONDecoder() 53 | let item = try decoder.decode(T.self, from: data) 54 | return item 55 | } catch { 56 | return nil 57 | } 58 | } 59 | 60 | open func transformToJSON(_ value: T?) -> JSON? { 61 | guard let item = value else { 62 | return nil 63 | } 64 | do { 65 | let encoder = JSONEncoder() 66 | let data = try encoder.encode(item) 67 | let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) 68 | return dictionary 69 | } catch { 70 | return nil 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/CustomDateFormatTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomDateFormatTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Dan McCracken on 3/8/15. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | open class CustomDateFormatTransform: DateFormatterTransform { 32 | 33 | public init(formatString: String) { 34 | let formatter = DateFormatter() 35 | formatter.locale = Locale(identifier: "en_US_POSIX") 36 | formatter.dateFormat = formatString 37 | 38 | super.init(dateFormatter: formatter) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/DataTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DataTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Yagrushkin, Evgeny on 8/30/16. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | open class DataTransform: TransformType { 32 | public typealias Object = Data 33 | public typealias JSON = String 34 | 35 | public init() {} 36 | 37 | open func transformFromJSON(_ value: Any?) -> Data? { 38 | guard let string = value as? String else{ 39 | return nil 40 | } 41 | return Data(base64Encoded: string) 42 | } 43 | 44 | open func transformToJSON(_ value: Data?) -> String? { 45 | guard let data = value else{ 46 | return nil 47 | } 48 | return data.base64EncodedString() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/DateFormatterTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DateFormatterTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 2015-03-09. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | open class DateFormatterTransform: TransformType { 32 | public typealias Object = Date 33 | public typealias JSON = String 34 | 35 | public let dateFormatter: DateFormatter 36 | 37 | public init(dateFormatter: DateFormatter) { 38 | self.dateFormatter = dateFormatter 39 | } 40 | 41 | open func transformFromJSON(_ value: Any?) -> Date? { 42 | if let dateString = value as? String { 43 | return dateFormatter.date(from: dateString) 44 | } 45 | return nil 46 | } 47 | 48 | open func transformToJSON(_ value: Date?) -> String? { 49 | if let date = value { 50 | return dateFormatter.string(from: date) 51 | } 52 | return nil 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/DateTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DateTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 2014-10-13. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | open class DateTransform: TransformType { 32 | public typealias Object = Date 33 | public typealias JSON = Double 34 | 35 | public enum Unit: TimeInterval { 36 | case seconds = 1 37 | case milliseconds = 1_000 38 | 39 | func addScale(to interval: TimeInterval) -> TimeInterval { 40 | return interval * rawValue 41 | } 42 | 43 | func removeScale(from interval: TimeInterval) -> TimeInterval { 44 | return interval / rawValue 45 | } 46 | } 47 | 48 | private let unit: Unit 49 | 50 | public init(unit: Unit = .seconds) { 51 | self.unit = unit 52 | } 53 | 54 | open func transformFromJSON(_ value: Any?) -> Date? { 55 | var timeInterval: TimeInterval? 56 | if let timeInt = value as? Double { 57 | timeInterval = TimeInterval(timeInt) 58 | } 59 | 60 | if let timeStr = value as? String { 61 | timeInterval = TimeInterval(atof(timeStr)) 62 | } 63 | 64 | return timeInterval.flatMap { 65 | return Date(timeIntervalSince1970: unit.removeScale(from: $0)) 66 | } 67 | } 68 | 69 | open func transformToJSON(_ value: Date?) -> Double? { 70 | if let date = value { 71 | return Double(unit.addScale(to: date.timeIntervalSince1970)) 72 | } 73 | return nil 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/DictionaryTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DictionaryTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Milen Halachev on 7/20/16. 6 | // 7 | // Copyright (c) 2014-2018 Tristan Himmelman 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | import Foundation 28 | 29 | ///Transforms [String: AnyObject] <-> [Key: Value] where Key is RawRepresentable as String, Value is Mappable 30 | public struct DictionaryTransform: TransformType where Key: Hashable, Key: RawRepresentable, Key.RawValue == String, Value: Mappable { 31 | 32 | public init() { 33 | 34 | } 35 | 36 | public func transformFromJSON(_ value: Any?) -> [Key: Value]? { 37 | 38 | guard let json = value as? [String: Any] else { 39 | 40 | return nil 41 | } 42 | 43 | let result = json.reduce([:]) { (result, element) -> [Key: Value] in 44 | 45 | guard 46 | let key = Key(rawValue: element.0), 47 | let valueJSON = element.1 as? [String: Any], 48 | let value = Value(JSON: valueJSON) 49 | else { 50 | 51 | return result 52 | } 53 | 54 | var result = result 55 | result[key] = value 56 | return result 57 | } 58 | 59 | return result 60 | } 61 | 62 | public func transformToJSON(_ value: [Key: Value]?) -> Any? { 63 | 64 | let result = value?.reduce([:]) { (result, element) -> [String: Any] in 65 | 66 | let key = element.0.rawValue 67 | let value = element.1.toJSON() 68 | 69 | var result = result 70 | result[key] = value 71 | return result 72 | } 73 | 74 | return result 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/EnumOperators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumOperators.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 2016-09-26. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | 32 | // MARK:- Raw Representable types 33 | 34 | /// Object of Raw Representable type 35 | public func <- (left: inout T, right: Map) { 36 | left <- (right, EnumTransform()) 37 | } 38 | 39 | public func >>> (left: T, right: Map) { 40 | left >>> (right, EnumTransform()) 41 | } 42 | 43 | 44 | /// Optional Object of Raw Representable type 45 | public func <- (left: inout T?, right: Map) { 46 | left <- (right, EnumTransform()) 47 | } 48 | 49 | public func >>> (left: T?, right: Map) { 50 | left >>> (right, EnumTransform()) 51 | } 52 | 53 | 54 | // Code targeting the Swift 4.1 compiler and below. 55 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 56 | /// Implicitly Unwrapped Optional Object of Raw Representable type 57 | public func <- (left: inout T!, right: Map) { 58 | left <- (right, EnumTransform()) 59 | } 60 | #endif 61 | 62 | // MARK:- Arrays of Raw Representable type 63 | 64 | /// Array of Raw Representable object 65 | public func <- (left: inout [T], right: Map) { 66 | left <- (right, EnumTransform()) 67 | } 68 | 69 | public func >>> (left: [T], right: Map) { 70 | left >>> (right, EnumTransform()) 71 | } 72 | 73 | 74 | /// Array of Raw Representable object 75 | public func <- (left: inout [T]?, right: Map) { 76 | left <- (right, EnumTransform()) 77 | } 78 | 79 | public func >>> (left: [T]?, right: Map) { 80 | left >>> (right, EnumTransform()) 81 | } 82 | 83 | 84 | // Code targeting the Swift 4.1 compiler and below. 85 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 86 | /// Array of Raw Representable object 87 | public func <- (left: inout [T]!, right: Map) { 88 | left <- (right, EnumTransform()) 89 | } 90 | #endif 91 | 92 | // MARK:- Dictionaries of Raw Representable type 93 | 94 | /// Dictionary of Raw Representable object 95 | public func <- (left: inout [String: T], right: Map) { 96 | left <- (right, EnumTransform()) 97 | } 98 | 99 | public func >>> (left: [String: T], right: Map) { 100 | left >>> (right, EnumTransform()) 101 | } 102 | 103 | 104 | /// Dictionary of Raw Representable object 105 | public func <- (left: inout [String: T]?, right: Map) { 106 | left <- (right, EnumTransform()) 107 | } 108 | 109 | public func >>> (left: [String: T]?, right: Map) { 110 | left >>> (right, EnumTransform()) 111 | } 112 | 113 | 114 | // Code targeting the Swift 4.1 compiler and below. 115 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 116 | /// Dictionary of Raw Representable object 117 | public func <- (left: inout [String: T]!, right: Map) { 118 | left <- (right, EnumTransform()) 119 | } 120 | #endif 121 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/EnumTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Kaan Dedeoglu on 3/20/15. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | open class EnumTransform: TransformType { 32 | public typealias Object = T 33 | public typealias JSON = T.RawValue 34 | 35 | public init() {} 36 | 37 | open func transformFromJSON(_ value: Any?) -> T? { 38 | if let raw = value as? T.RawValue { 39 | return T(rawValue: raw) 40 | } 41 | return nil 42 | } 43 | 44 | open func transformToJSON(_ value: T?) -> T.RawValue? { 45 | if let obj = value { 46 | return obj.rawValue 47 | } 48 | return nil 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/FromJSON.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FromJSON.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 2014-10-09. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2016 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | internal final class FromJSON { 30 | 31 | /// Basic type 32 | class func basicType(_ field: inout FieldType, object: FieldType?) { 33 | if let value = object { 34 | field = value 35 | } 36 | } 37 | 38 | /// optional basic type 39 | class func optionalBasicType(_ field: inout FieldType?, object: FieldType?) { 40 | field = object 41 | } 42 | 43 | // Code targeting the Swift 4.1 compiler and below. 44 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 45 | /// Implicitly unwrapped optional basic type 46 | class func optionalBasicType(_ field: inout FieldType!, object: FieldType?) { 47 | field = object 48 | } 49 | #endif 50 | 51 | /// Mappable object 52 | class func object(_ field: inout N, map: Map) { 53 | if map.toObject { 54 | field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: field) 55 | } else if let value: N = Mapper(context: map.context).map(JSONObject: map.currentValue) { 56 | field = value 57 | } 58 | } 59 | 60 | /// Optional Mappable Object 61 | 62 | class func optionalObject(_ field: inout N?, map: Map) { 63 | if let f = field , map.toObject && map.currentValue != nil { 64 | field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: f) 65 | } else { 66 | field = Mapper(context: map.context).map(JSONObject: map.currentValue) 67 | } 68 | } 69 | 70 | // Code targeting the Swift 4.1 compiler and below. 71 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 72 | /// Implicitly unwrapped Optional Mappable Object 73 | class func optionalObject(_ field: inout N!, map: Map) { 74 | if let f = field , map.toObject && map.currentValue != nil { 75 | field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: f) 76 | } else { 77 | field = Mapper(context: map.context).map(JSONObject: map.currentValue) 78 | } 79 | } 80 | #endif 81 | 82 | /// mappable object array 83 | class func objectArray(_ field: inout Array, map: Map) { 84 | if let objects = Mapper(context: map.context).mapArray(JSONObject: map.currentValue) { 85 | field = objects 86 | } 87 | } 88 | 89 | /// optional mappable object array 90 | 91 | class func optionalObjectArray(_ field: inout Array?, map: Map) { 92 | if let objects: Array = Mapper(context: map.context).mapArray(JSONObject: map.currentValue) { 93 | field = objects 94 | } else { 95 | field = nil 96 | } 97 | } 98 | 99 | // Code targeting the Swift 4.1 compiler and below. 100 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 101 | /// Implicitly unwrapped optional mappable object array 102 | class func optionalObjectArray(_ field: inout Array!, map: Map) { 103 | if let objects: Array = Mapper(context: map.context).mapArray(JSONObject: map.currentValue) { 104 | field = objects 105 | } else { 106 | field = nil 107 | } 108 | } 109 | #endif 110 | 111 | /// mappable object array 112 | class func twoDimensionalObjectArray(_ field: inout Array>, map: Map) { 113 | if let objects = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) { 114 | field = objects 115 | } 116 | } 117 | 118 | /// optional mappable 2 dimentional object array 119 | class func optionalTwoDimensionalObjectArray(_ field: inout Array>?, map: Map) { 120 | field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) 121 | } 122 | 123 | // Code targeting the Swift 4.1 compiler and below. 124 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 125 | /// Implicitly unwrapped optional 2 dimentional mappable object array 126 | class func optionalTwoDimensionalObjectArray(_ field: inout Array>!, map: Map) { 127 | field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) 128 | } 129 | #endif 130 | 131 | /// Dctionary containing Mappable objects 132 | class func objectDictionary(_ field: inout Dictionary, map: Map) { 133 | if map.toObject { 134 | field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: field) 135 | } else { 136 | if let objects = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue) { 137 | field = objects 138 | } 139 | } 140 | } 141 | 142 | /// Optional dictionary containing Mappable objects 143 | class func optionalObjectDictionary(_ field: inout Dictionary?, map: Map) { 144 | if let f = field , map.toObject && map.currentValue != nil { 145 | field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: f) 146 | } else { 147 | field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue) 148 | } 149 | } 150 | 151 | // Code targeting the Swift 4.1 compiler and below. 152 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 153 | /// Implicitly unwrapped Dictionary containing Mappable objects 154 | class func optionalObjectDictionary(_ field: inout Dictionary!, map: Map) { 155 | if let f = field , map.toObject && map.currentValue != nil { 156 | field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: f) 157 | } else { 158 | field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue) 159 | } 160 | } 161 | #endif 162 | 163 | /// Dictionary containing Array of Mappable objects 164 | class func objectDictionaryOfArrays(_ field: inout Dictionary, map: Map) { 165 | if let objects = Mapper(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) { 166 | field = objects 167 | } 168 | } 169 | 170 | /// Optional Dictionary containing Array of Mappable objects 171 | class func optionalObjectDictionaryOfArrays(_ field: inout Dictionary?, map: Map) { 172 | field = Mapper(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) 173 | } 174 | 175 | // Code targeting the Swift 4.1 compiler and below. 176 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 177 | /// Implicitly unwrapped Dictionary containing Array of Mappable objects 178 | class func optionalObjectDictionaryOfArrays(_ field: inout Dictionary!, map: Map) { 179 | field = Mapper(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) 180 | } 181 | #endif 182 | 183 | /// mappable object Set 184 | class func objectSet(_ field: inout Set, map: Map) { 185 | if let objects = Mapper(context: map.context).mapSet(JSONObject: map.currentValue) { 186 | field = objects 187 | } 188 | } 189 | 190 | /// optional mappable object array 191 | class func optionalObjectSet(_ field: inout Set?, map: Map) { 192 | field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue) 193 | } 194 | 195 | // Code targeting the Swift 4.1 compiler and below. 196 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 197 | /// Implicitly unwrapped optional mappable object array 198 | class func optionalObjectSet(_ field: inout Set!, map: Map) { 199 | field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue) 200 | } 201 | #endif 202 | } 203 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/HexColorTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HexColorTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Vitaliy Kuzmenko on 10/10/16. 6 | // 7 | // Copyright (c) 2014-2018 Tristan Himmelman 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | #if os(iOS) || os(tvOS) || os(watchOS) 28 | import UIKit 29 | #elseif os(macOS) 30 | import Cocoa 31 | #endif 32 | 33 | #if os(iOS) || os(tvOS) || os(watchOS) || os(macOS) 34 | open class HexColorTransform: TransformType { 35 | 36 | #if os(iOS) || os(tvOS) || os(watchOS) 37 | public typealias Object = UIColor 38 | #else 39 | public typealias Object = NSColor 40 | #endif 41 | 42 | public typealias JSON = String 43 | 44 | var prefix: Bool = false 45 | 46 | var alpha: Bool = false 47 | 48 | public init(prefixToJSON: Bool = false, alphaToJSON: Bool = false) { 49 | alpha = alphaToJSON 50 | prefix = prefixToJSON 51 | } 52 | 53 | open func transformFromJSON(_ value: Any?) -> Object? { 54 | if let rgba = value as? String { 55 | if rgba.hasPrefix("#") { 56 | let index = rgba.index(rgba.startIndex, offsetBy: 1) 57 | let hex = String(rgba[index...]) 58 | return getColor(hex: hex) 59 | } else { 60 | return getColor(hex: rgba) 61 | } 62 | } 63 | return nil 64 | } 65 | 66 | open func transformToJSON(_ value: Object?) -> JSON? { 67 | if let value = value { 68 | return hexString(color: value) 69 | } 70 | return nil 71 | } 72 | 73 | fileprivate func hexString(color: Object) -> String { 74 | let comps = color.cgColor.components! 75 | let compsCount = color.cgColor.numberOfComponents 76 | let r: Int 77 | let g: Int 78 | var b: Int 79 | let a = Int(comps[compsCount - 1] * 255) 80 | if compsCount == 4 { // RGBA 81 | r = Int(comps[0] * 255) 82 | g = Int(comps[1] * 255) 83 | b = Int(comps[2] * 255) 84 | } else { // Grayscale 85 | r = Int(comps[0] * 255) 86 | g = Int(comps[0] * 255) 87 | b = Int(comps[0] * 255) 88 | } 89 | var hexString: String = "" 90 | if prefix { 91 | hexString = "#" 92 | } 93 | hexString += String(format: "%02X%02X%02X", r, g, b) 94 | 95 | if alpha { 96 | hexString += String(format: "%02X", a) 97 | } 98 | return hexString 99 | } 100 | 101 | fileprivate func getColor(hex: String) -> Object? { 102 | var red: CGFloat = 0.0 103 | var green: CGFloat = 0.0 104 | var blue: CGFloat = 0.0 105 | var alpha: CGFloat = 1.0 106 | 107 | let scanner = Scanner(string: hex) 108 | var hexValue: CUnsignedLongLong = 0 109 | if scanner.scanHexInt64(&hexValue) { 110 | switch (hex.count) { 111 | case 3: 112 | red = CGFloat((hexValue & 0xF00) >> 8) / 15.0 113 | green = CGFloat((hexValue & 0x0F0) >> 4) / 15.0 114 | blue = CGFloat(hexValue & 0x00F) / 15.0 115 | case 4: 116 | red = CGFloat((hexValue & 0xF000) >> 12) / 15.0 117 | green = CGFloat((hexValue & 0x0F00) >> 8) / 15.0 118 | blue = CGFloat((hexValue & 0x00F0) >> 4) / 15.0 119 | alpha = CGFloat(hexValue & 0x000F) / 15.0 120 | case 6: 121 | red = CGFloat((hexValue & 0xFF0000) >> 16) / 255.0 122 | green = CGFloat((hexValue & 0x00FF00) >> 8) / 255.0 123 | blue = CGFloat(hexValue & 0x0000FF) / 255.0 124 | case 8: 125 | red = CGFloat((hexValue & 0xFF000000) >> 24) / 255.0 126 | green = CGFloat((hexValue & 0x00FF0000) >> 16) / 255.0 127 | blue = CGFloat((hexValue & 0x0000FF00) >> 8) / 255.0 128 | alpha = CGFloat(hexValue & 0x000000FF) / 255.0 129 | default: 130 | // Invalid RGB string, number of characters after '#' should be either 3, 4, 6 or 8 131 | return nil 132 | } 133 | } else { 134 | // "Scan hex error 135 | return nil 136 | } 137 | #if os(iOS) || os(tvOS) || os(watchOS) 138 | return UIColor(red: red, green: green, blue: blue, alpha: alpha) 139 | #else 140 | return NSColor(red: red, green: green, blue: blue, alpha: alpha) 141 | #endif 142 | } 143 | } 144 | #endif 145 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/ISO8601DateTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ISO8601DateTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Jean-Pierre Mouilleseaux on 21 Nov 2014. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | public extension DateFormatter { 32 | convenience init(withFormat format : String, locale : String) { 33 | self.init() 34 | self.locale = Locale(identifier: locale) 35 | dateFormat = format 36 | } 37 | } 38 | 39 | open class ISO8601DateTransform: DateFormatterTransform { 40 | 41 | static let reusableISODateFormatter = DateFormatter(withFormat: "yyyy-MM-dd'T'HH:mm:ssZZZZZ", locale: "en_US_POSIX") 42 | 43 | public init() { 44 | super.init(dateFormatter: ISO8601DateTransform.reusableISODateFormatter) 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/IntegerOperators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IntegerOperators.swift 3 | // ObjectMapper 4 | // 5 | // Created by Suyeol Jeon on 17/02/2017. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | // MARK: - Signed Integer 32 | 33 | /// SignedInteger mapping 34 | public func <- (left: inout T, right: Map) { 35 | switch right.mappingType { 36 | case .fromJSON where right.isKeyPresent: 37 | let value: T = toSignedInteger(right.currentValue) ?? 0 38 | FromJSON.basicType(&left, object: value) 39 | case .toJSON: 40 | left >>> right 41 | default: () 42 | } 43 | } 44 | 45 | /// Optional SignedInteger mapping 46 | public func <- (left: inout T?, right: Map) { 47 | switch right.mappingType { 48 | case .fromJSON where right.isKeyPresent: 49 | let value: T? = toSignedInteger(right.currentValue) 50 | FromJSON.basicType(&left, object: value) 51 | case .toJSON: 52 | left >>> right 53 | default: () 54 | } 55 | } 56 | 57 | // Code targeting the Swift 4.1 compiler and below. 58 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 59 | /// ImplicitlyUnwrappedOptional SignedInteger mapping 60 | public func <- (left: inout T!, right: Map) { 61 | switch right.mappingType { 62 | case .fromJSON where right.isKeyPresent: 63 | let value: T! = toSignedInteger(right.currentValue) 64 | FromJSON.basicType(&left, object: value) 65 | case .toJSON: 66 | left >>> right 67 | default: () 68 | } 69 | } 70 | #endif 71 | 72 | 73 | // MARK: - Unsigned Integer 74 | 75 | /// UnsignedInteger mapping 76 | public func <- (left: inout T, right: Map) { 77 | switch right.mappingType { 78 | case .fromJSON where right.isKeyPresent: 79 | let value: T = toUnsignedInteger(right.currentValue) ?? 0 80 | FromJSON.basicType(&left, object: value) 81 | case .toJSON: 82 | left >>> right 83 | default: () 84 | } 85 | } 86 | 87 | 88 | /// Optional UnsignedInteger mapping 89 | public func <- (left: inout T?, right: Map) { 90 | switch right.mappingType { 91 | case .fromJSON where right.isKeyPresent: 92 | let value: T? = toUnsignedInteger(right.currentValue) 93 | FromJSON.basicType(&left, object: value) 94 | case .toJSON: 95 | left >>> right 96 | default: () 97 | } 98 | } 99 | 100 | // Code targeting the Swift 4.1 compiler and below. 101 | #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) 102 | /// ImplicitlyUnwrappedOptional UnsignedInteger mapping 103 | public func <- (left: inout T!, right: Map) { 104 | switch right.mappingType { 105 | case .fromJSON where right.isKeyPresent: 106 | let value: T! = toUnsignedInteger(right.currentValue) 107 | FromJSON.basicType(&left, object: value) 108 | case .toJSON: 109 | left >>> right 110 | default: () 111 | } 112 | } 113 | #endif 114 | 115 | // MARK: - Casting Utils 116 | 117 | /// Convert any value to `SignedInteger`. 118 | private func toSignedInteger(_ value: Any?) -> T? { 119 | guard 120 | let value = value, 121 | case let number as NSNumber = value 122 | else { 123 | return nil 124 | } 125 | 126 | if T.self == Int.self, let x = Int(exactly: number.int64Value) { 127 | return T.init(x) 128 | } 129 | if T.self == Int8.self, let x = Int8(exactly: number.int64Value) { 130 | return T.init(x) 131 | } 132 | if T.self == Int16.self, let x = Int16(exactly: number.int64Value) { 133 | return T.init(x) 134 | } 135 | if T.self == Int32.self, let x = Int32(exactly: number.int64Value) { 136 | return T.init(x) 137 | } 138 | if T.self == Int64.self, let x = Int64(exactly: number.int64Value) { 139 | return T.init(x) 140 | } 141 | 142 | return nil 143 | } 144 | 145 | /// Convert any value to `UnsignedInteger`. 146 | private func toUnsignedInteger(_ value: Any?) -> T? { 147 | guard 148 | let value = value, 149 | case let number as NSNumber = value 150 | else { 151 | return nil 152 | } 153 | 154 | if T.self == UInt.self, let x = UInt(exactly: number.uint64Value) { 155 | return T.init(x) 156 | } 157 | if T.self == UInt8.self, let x = UInt8(exactly: number.uint64Value) { 158 | return T.init(x) 159 | } 160 | if T.self == UInt16.self, let x = UInt16(exactly: number.uint64Value) { 161 | return T.init(x) 162 | } 163 | if T.self == UInt32.self, let x = UInt32(exactly: number.uint64Value) { 164 | return T.init(x) 165 | } 166 | if T.self == UInt64.self, let x = UInt64(exactly: number.uint64Value) { 167 | return T.init(x) 168 | } 169 | 170 | return nil 171 | } 172 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/MapError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MapError.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 2016-09-26. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | public struct MapError: Error { 32 | public var key: String? 33 | public var currentValue: Any? 34 | public var reason: String? 35 | public var file: StaticString? 36 | public var function: StaticString? 37 | public var line: UInt? 38 | 39 | public init(key: String?, currentValue: Any?, reason: String?, file: StaticString? = nil, function: StaticString? = nil, line: UInt? = nil) { 40 | self.key = key 41 | self.currentValue = currentValue 42 | self.reason = reason 43 | self.file = file 44 | self.function = function 45 | self.line = line 46 | } 47 | } 48 | 49 | extension MapError: CustomStringConvertible { 50 | 51 | private var location: String? { 52 | guard let file = file, let function = function, let line = line else { return nil } 53 | let fileName = ((String(describing: file).components(separatedBy: "/").last ?? "").components(separatedBy: ".").first ?? "") 54 | return "\(fileName).\(function):\(line)" 55 | } 56 | 57 | public var description: String { 58 | let info: [(String, Any?)] = [ 59 | ("- reason", reason), 60 | ("- location", location), 61 | ("- key", key), 62 | ("- currentValue", currentValue), 63 | ] 64 | let infoString = info.map { "\($0.0): \($0.1 ?? "nil")" }.joined(separator: "\n") 65 | return "Got an error while mapping.\n\(infoString)" 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/Mappable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Mappable.swift 3 | // ObjectMapper 4 | // 5 | // Created by Scott Hoyt on 10/25/15. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | /// BaseMappable should not be implemented directly. Mappable or StaticMappable should be used instead 32 | public protocol BaseMappable { 33 | /// This function is where all variable mappings should occur. It is executed by Mapper during the mapping (serialization and deserialization) process. 34 | mutating func mapping(map: Map) 35 | } 36 | 37 | public protocol Mappable: BaseMappable { 38 | /// This function can be used to validate JSON prior to mapping. Return nil to cancel mapping at this point 39 | init?(map: Map) 40 | } 41 | 42 | public protocol StaticMappable: BaseMappable { 43 | /// This is function that can be used to: 44 | /// 1) provide an existing cached object to be used for mapping 45 | /// 2) return an object of another class (which conforms to BaseMappable) to be used for mapping. For instance, you may inspect the JSON to infer the type of object that should be used for any given mapping 46 | static func objectForMapping(map: Map) -> BaseMappable? 47 | } 48 | 49 | public extension Mappable { 50 | 51 | /// Initializes object from a JSON String 52 | init?(JSONString: String, context: MapContext? = nil) { 53 | if let obj: Self = Mapper(context: context).map(JSONString: JSONString) { 54 | self = obj 55 | } else { 56 | return nil 57 | } 58 | } 59 | 60 | /// Initializes object from a JSON Dictionary 61 | init?(JSON: [String: Any], context: MapContext? = nil) { 62 | if let obj: Self = Mapper(context: context).map(JSON: JSON) { 63 | self = obj 64 | } else { 65 | return nil 66 | } 67 | } 68 | } 69 | 70 | public extension BaseMappable { 71 | 72 | /// Returns the JSON Dictionary for the object 73 | func toJSON() -> [String: Any] { 74 | return Mapper().toJSON(self) 75 | } 76 | 77 | /// Returns the JSON String for the object 78 | func toJSONString(prettyPrint: Bool = false) -> String? { 79 | return Mapper().toJSONString(self, prettyPrint: prettyPrint) 80 | } 81 | } 82 | 83 | public extension Array where Element: BaseMappable { 84 | 85 | /// Initialize Array from a JSON String 86 | init?(JSONString: String, context: MapContext? = nil) { 87 | if let obj: [Element] = Mapper(context: context).mapArray(JSONString: JSONString) { 88 | self = obj 89 | } else { 90 | return nil 91 | } 92 | } 93 | 94 | /// Initialize Array from a JSON Array 95 | init(JSONArray: [[String: Any]], context: MapContext? = nil) { 96 | let obj: [Element] = Mapper(context: context).mapArray(JSONArray: JSONArray) 97 | self = obj 98 | } 99 | 100 | /// Returns the JSON Array 101 | func toJSON() -> [[String: Any]] { 102 | return Mapper().toJSONArray(self) 103 | } 104 | 105 | /// Returns the JSON String for the object 106 | func toJSONString(prettyPrint: Bool = false) -> String? { 107 | return Mapper().toJSONString(self, prettyPrint: prettyPrint) 108 | } 109 | } 110 | 111 | public extension Set where Element: BaseMappable { 112 | 113 | /// Initializes a set from a JSON String 114 | init?(JSONString: String, context: MapContext? = nil) { 115 | if let obj: Set = Mapper(context: context).mapSet(JSONString: JSONString) { 116 | self = obj 117 | } else { 118 | return nil 119 | } 120 | } 121 | 122 | /// Initializes a set from JSON 123 | init?(JSONArray: [[String: Any]], context: MapContext? = nil) { 124 | guard let obj = Mapper(context: context).mapSet(JSONArray: JSONArray) as Set? else { 125 | return nil 126 | } 127 | self = obj 128 | } 129 | 130 | /// Returns the JSON Set 131 | func toJSON() -> [[String: Any]] { 132 | return Mapper().toJSONSet(self) 133 | } 134 | 135 | /// Returns the JSON String for the object 136 | func toJSONString(prettyPrint: Bool = false) -> String? { 137 | return Mapper().toJSONString(self, prettyPrint: prettyPrint) 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/NSDecimalNumberTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransformOf.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 8/22/16. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | open class NSDecimalNumberTransform: TransformType { 32 | public typealias Object = NSDecimalNumber 33 | public typealias JSON = String 34 | 35 | public init() {} 36 | 37 | open func transformFromJSON(_ value: Any?) -> NSDecimalNumber? { 38 | if let string = value as? String { 39 | return NSDecimalNumber(string: string) 40 | } else if let number = value as? NSNumber { 41 | return NSDecimalNumber(decimal: number.decimalValue) 42 | } else if let double = value as? Double { 43 | return NSDecimalNumber(floatLiteral: double) 44 | } 45 | return nil 46 | } 47 | 48 | open func transformToJSON(_ value: NSDecimalNumber?) -> String? { 49 | guard let value = value else { return nil } 50 | return value.description 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/ToJSON.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ToJSON.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 2014-10-13. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | private func setValue(_ value: Any, map: Map) { 32 | setValue(value, key: map.currentKey!, checkForNestedKeys: map.keyIsNested, delimiter: map.nestedKeyDelimiter, dictionary: &map.JSON) 33 | } 34 | 35 | private func setValue(_ value: Any, key: String, checkForNestedKeys: Bool, delimiter: String, dictionary: inout [String : Any]) { 36 | if checkForNestedKeys { 37 | let keyComponents = ArraySlice(key.components(separatedBy: delimiter).filter { !$0.isEmpty }.map { $0 }) 38 | setValue(value, forKeyPathComponents: keyComponents, dictionary: &dictionary) 39 | } else { 40 | dictionary[key] = value 41 | } 42 | } 43 | 44 | private func setValue(_ value: Any, forKeyPathComponents components: ArraySlice, dictionary: inout [String : Any]) { 45 | guard let head = components.first else { 46 | return 47 | } 48 | 49 | let headAsString = String(head) 50 | if components.count == 1 { 51 | dictionary[headAsString] = value 52 | } else { 53 | var child = dictionary[headAsString] as? [String : Any] ?? [:] 54 | 55 | let tail = components.dropFirst() 56 | setValue(value, forKeyPathComponents: tail, dictionary: &child) 57 | 58 | dictionary[headAsString] = child 59 | } 60 | } 61 | 62 | internal final class ToJSON { 63 | 64 | class func basicType(_ field: N, map: Map) { 65 | if let x = field as Any? , false 66 | || x is NSNumber // Basic types 67 | || x is Bool 68 | || x is Int 69 | || x is Double 70 | || x is Float 71 | || x is String 72 | || x is NSNull 73 | || x is Array // Arrays 74 | || x is Array 75 | || x is Array 76 | || x is Array 77 | || x is Array 78 | || x is Array 79 | || x is Array 80 | || x is Array> 81 | || x is Dictionary // Dictionaries 82 | || x is Dictionary 83 | || x is Dictionary 84 | || x is Dictionary 85 | || x is Dictionary 86 | || x is Dictionary 87 | || x is Dictionary 88 | { 89 | setValue(x, map: map) 90 | } 91 | } 92 | 93 | class func optionalBasicType(_ field: N?, map: Map) { 94 | if let field = field { 95 | basicType(field, map: map) 96 | } else if map.shouldIncludeNilValues { 97 | basicType(NSNull(), map: map) //If BasicType is nil, emit NSNull into the JSON output 98 | } 99 | } 100 | 101 | class func object(_ field: N, map: Map) { 102 | if let result = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSON(field) as Any? { 103 | setValue(result, map: map) 104 | } 105 | } 106 | 107 | class func optionalObject(_ field: N?, map: Map) { 108 | if let field = field { 109 | object(field, map: map) 110 | } else if map.shouldIncludeNilValues { 111 | basicType(NSNull(), map: map) //If field is nil, emit NSNull into the JSON output 112 | } 113 | } 114 | 115 | class func objectArray(_ field: Array, map: Map) { 116 | let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONArray(field) 117 | 118 | setValue(JSONObjects, map: map) 119 | } 120 | 121 | class func optionalObjectArray(_ field: Array?, map: Map) { 122 | if let field = field { 123 | objectArray(field, map: map) 124 | } 125 | } 126 | 127 | class func twoDimensionalObjectArray(_ field: Array>, map: Map) { 128 | var array = [[[String: Any]]]() 129 | for innerArray in field { 130 | let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONArray(innerArray) 131 | array.append(JSONObjects) 132 | } 133 | setValue(array, map: map) 134 | } 135 | 136 | class func optionalTwoDimensionalObjectArray(_ field: Array>?, map: Map) { 137 | if let field = field { 138 | twoDimensionalObjectArray(field, map: map) 139 | } 140 | } 141 | 142 | class func objectSet(_ field: Set, map: Map) { 143 | let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONSet(field) 144 | 145 | setValue(JSONObjects, map: map) 146 | } 147 | 148 | class func optionalObjectSet(_ field: Set?, map: Map) { 149 | if let field = field { 150 | objectSet(field, map: map) 151 | } 152 | } 153 | 154 | class func objectDictionary(_ field: Dictionary, map: Map) { 155 | let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONDictionary(field) 156 | 157 | setValue(JSONObjects, map: map) 158 | } 159 | 160 | class func optionalObjectDictionary(_ field: Dictionary?, map: Map) { 161 | if let field = field { 162 | objectDictionary(field, map: map) 163 | } 164 | } 165 | 166 | class func objectDictionaryOfArrays(_ field: Dictionary, map: Map) { 167 | let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONDictionaryOfArrays(field) 168 | 169 | setValue(JSONObjects, map: map) 170 | } 171 | 172 | class func optionalObjectDictionaryOfArrays(_ field: Dictionary?, map: Map) { 173 | if let field = field { 174 | objectDictionaryOfArrays(field, map: map) 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/TransformOf.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransformOf.swift 3 | // ObjectMapper 4 | // 5 | // Created by Syo Ikeda on 1/23/15. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | open class TransformOf: TransformType { 30 | public typealias Object = ObjectType 31 | public typealias JSON = JSONType 32 | 33 | private let fromJSON: (JSONType?) -> ObjectType? 34 | private let toJSON: (ObjectType?) -> JSONType? 35 | 36 | public init(fromJSON: @escaping(JSONType?) -> ObjectType?, toJSON: @escaping(ObjectType?) -> JSONType?) { 37 | self.fromJSON = fromJSON 38 | self.toJSON = toJSON 39 | } 40 | 41 | open func transformFromJSON(_ value: Any?) -> ObjectType? { 42 | return fromJSON(value as? JSONType) 43 | } 44 | 45 | open func transformToJSON(_ value: ObjectType?) -> JSONType? { 46 | return toJSON(value) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/TransformType.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransformType.swift 3 | // ObjectMapper 4 | // 5 | // Created by Syo Ikeda on 2/4/15. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | public protocol TransformType { 30 | associatedtype Object 31 | associatedtype JSON 32 | 33 | func transformFromJSON(_ value: Any?) -> Object? 34 | func transformToJSON(_ value: Object?) -> JSON? 35 | } 36 | -------------------------------------------------------------------------------- /Example/Pods/ObjectMapper/Sources/URLTransform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // URLTransform.swift 3 | // ObjectMapper 4 | // 5 | // Created by Tristan Himmelman on 2014-10-27. 6 | // 7 | // The MIT License (MIT) 8 | // 9 | // Copyright (c) 2014-2018 Tristan Himmelman 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | import Foundation 30 | 31 | open class URLTransform: TransformType { 32 | public typealias Object = URL 33 | public typealias JSON = String 34 | private let shouldEncodeURLString: Bool 35 | private let allowedCharacterSet: CharacterSet 36 | 37 | /** 38 | Initializes the URLTransform with an option to encode URL strings before converting them to an NSURL 39 | - parameter shouldEncodeUrlString: when true (the default) the string is encoded before passing 40 | to `NSURL(string:)` 41 | - returns: an initialized transformer 42 | */ 43 | public init(shouldEncodeURLString: Bool = false, allowedCharacterSet: CharacterSet = .urlQueryAllowed) { 44 | self.shouldEncodeURLString = shouldEncodeURLString 45 | self.allowedCharacterSet = allowedCharacterSet 46 | } 47 | 48 | open func transformFromJSON(_ value: Any?) -> URL? { 49 | guard let URLString = value as? String else { return nil } 50 | 51 | if !shouldEncodeURLString { 52 | return URL(string: URLString) 53 | } 54 | 55 | guard let escapedURLString = URLString.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) else { 56 | return nil 57 | } 58 | return URL(string: escapedURLString) 59 | } 60 | 61 | open func transformToJSON(_ value: URL?) -> String? { 62 | if let URL = value { 63 | return URL.absoluteString 64 | } 65 | return nil 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/LICENSE.txt: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2014-2015 Stephen Celis () 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Core/Blob.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | public struct Blob { 26 | 27 | public let bytes: [UInt8] 28 | 29 | public init(bytes: [UInt8]) { 30 | self.bytes = bytes 31 | } 32 | 33 | public init(bytes: UnsafeRawPointer, length: Int) { 34 | let i8bufptr = UnsafeBufferPointer(start: bytes.assumingMemoryBound(to: UInt8.self), count: length) 35 | self.init(bytes: [UInt8](i8bufptr)) 36 | } 37 | 38 | public func toHex() -> String { 39 | return bytes.map { 40 | ($0 < 16 ? "0" : "") + String($0, radix: 16, uppercase: false) 41 | }.joined(separator: "") 42 | } 43 | 44 | } 45 | 46 | extension Blob : CustomStringConvertible { 47 | 48 | public var description: String { 49 | return "x'\(toHex())'" 50 | } 51 | 52 | } 53 | 54 | extension Blob : Equatable { 55 | 56 | } 57 | 58 | public func ==(lhs: Blob, rhs: Blob) -> Bool { 59 | return lhs.bytes == rhs.bytes 60 | } 61 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Core/Errors.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public enum QueryError: Error, CustomStringConvertible { 4 | case noSuchTable(name: String) 5 | case noSuchColumn(name: String, columns: [String]) 6 | case ambiguousColumn(name: String, similar: [String]) 7 | case unexpectedNullValue(name: String) 8 | 9 | public var description: String { 10 | switch self { 11 | case .noSuchTable(let name): 12 | return "No such table: \(name)" 13 | case .noSuchColumn(let name, let columns): 14 | return "No such column `\(name)` in columns \(columns)" 15 | case .ambiguousColumn(let name, let similar): 16 | return "Ambiguous column `\(name)` (please disambiguate: \(similar))" 17 | case .unexpectedNullValue(let name): 18 | return "Unexpected null value for column `\(name)`" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Core/Value.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | /// - Warning: `Binding` is a protocol that SQLite.swift uses internally to 26 | /// directly map SQLite types to Swift types. 27 | /// 28 | /// Do not conform custom types to the Binding protocol. See the `Value` 29 | /// protocol, instead. 30 | public protocol Binding {} 31 | 32 | public protocol Number : Binding {} 33 | 34 | public protocol Value : Expressible { // extensions cannot have inheritance clauses 35 | 36 | associatedtype ValueType = Self 37 | 38 | associatedtype Datatype : Binding 39 | 40 | static var declaredDatatype: String { get } 41 | 42 | static func fromDatatypeValue(_ datatypeValue: Datatype) -> ValueType 43 | 44 | var datatypeValue: Datatype { get } 45 | 46 | } 47 | 48 | extension Double : Number, Value { 49 | 50 | public static let declaredDatatype = "REAL" 51 | 52 | public static func fromDatatypeValue(_ datatypeValue: Double) -> Double { 53 | return datatypeValue 54 | } 55 | 56 | public var datatypeValue: Double { 57 | return self 58 | } 59 | 60 | } 61 | 62 | extension Int64 : Number, Value { 63 | 64 | public static let declaredDatatype = "INTEGER" 65 | 66 | public static func fromDatatypeValue(_ datatypeValue: Int64) -> Int64 { 67 | return datatypeValue 68 | } 69 | 70 | public var datatypeValue: Int64 { 71 | return self 72 | } 73 | 74 | } 75 | 76 | extension String : Binding, Value { 77 | 78 | public static let declaredDatatype = "TEXT" 79 | 80 | public static func fromDatatypeValue(_ datatypeValue: String) -> String { 81 | return datatypeValue 82 | } 83 | 84 | public var datatypeValue: String { 85 | return self 86 | } 87 | 88 | } 89 | 90 | extension Blob : Binding, Value { 91 | 92 | public static let declaredDatatype = "BLOB" 93 | 94 | public static func fromDatatypeValue(_ datatypeValue: Blob) -> Blob { 95 | return datatypeValue 96 | } 97 | 98 | public var datatypeValue: Blob { 99 | return self 100 | } 101 | 102 | } 103 | 104 | // MARK: - 105 | 106 | extension Bool : Binding, Value { 107 | 108 | public static var declaredDatatype = Int64.declaredDatatype 109 | 110 | public static func fromDatatypeValue(_ datatypeValue: Int64) -> Bool { 111 | return datatypeValue != 0 112 | } 113 | 114 | public var datatypeValue: Int64 { 115 | return self ? 1 : 0 116 | } 117 | 118 | } 119 | 120 | extension Int : Number, Value { 121 | 122 | public static var declaredDatatype = Int64.declaredDatatype 123 | 124 | public static func fromDatatypeValue(_ datatypeValue: Int64) -> Int { 125 | return Int(datatypeValue) 126 | } 127 | 128 | public var datatypeValue: Int64 { 129 | return Int64(self) 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Extensions/FTS5.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | extension Module { 26 | public static func FTS5(_ config: FTS5Config) -> Module { 27 | return Module(name: "fts5", arguments: config.arguments()) 28 | } 29 | } 30 | 31 | /// Configuration for the [FTS5](https://www.sqlite.org/fts5.html) extension. 32 | /// 33 | /// **Note:** this is currently only applicable when using SQLite.swift together with a FTS5-enabled version 34 | /// of SQLite. 35 | open class FTS5Config : FTSConfig { 36 | public enum Detail : CustomStringConvertible { 37 | /// store rowid, column number, term offset 38 | case full 39 | /// store rowid, column number 40 | case column 41 | /// store rowid 42 | case none 43 | 44 | public var description: String { 45 | switch self { 46 | case .full: return "full" 47 | case .column: return "column" 48 | case .none: return "none" 49 | } 50 | } 51 | } 52 | 53 | var detail: Detail? 54 | var contentRowId: Expressible? 55 | var columnSize: Int? 56 | 57 | override public init() { 58 | } 59 | 60 | /// [External Content Tables](https://www.sqlite.org/fts5.html#section_4_4_2) 61 | @discardableResult open func contentRowId(_ column: Expressible) -> Self { 62 | self.contentRowId = column 63 | return self 64 | } 65 | 66 | /// [The Columnsize Option](https://www.sqlite.org/fts5.html#section_4_5) 67 | @discardableResult open func columnSize(_ size: Int) -> Self { 68 | self.columnSize = size 69 | return self 70 | } 71 | 72 | /// [The Detail Option](https://www.sqlite.org/fts5.html#section_4_6) 73 | @discardableResult open func detail(_ detail: Detail) -> Self { 74 | self.detail = detail 75 | return self 76 | } 77 | 78 | override func options() -> Options { 79 | var options = super.options() 80 | options.append("content_rowid", value: contentRowId) 81 | if let columnSize = columnSize { 82 | options.append("columnsize", value: Expression(value: columnSize)) 83 | } 84 | options.append("detail", value: detail) 85 | return options 86 | } 87 | 88 | override func formatColumnDefinitions() -> [Expressible] { 89 | return columnDefinitions.map { definition in 90 | if definition.options.contains(.unindexed) { 91 | return " ".join([definition.0, Expression(literal: "UNINDEXED")]) 92 | } else { 93 | return definition.0 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Extensions/RTree.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | extension Module { 26 | 27 | public static func RTree(_ primaryKey: Expression, _ pairs: (Expression, Expression)...) -> Module where T.Datatype == Int64, U.Datatype == Double { 28 | var arguments: [Expressible] = [primaryKey] 29 | 30 | for pair in pairs { 31 | arguments.append(contentsOf: [pair.0, pair.1] as [Expressible]) 32 | } 33 | 34 | return Module(name: "rtree", arguments: arguments) 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Foundation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | import Foundation 26 | 27 | extension Data : Value { 28 | 29 | public static var declaredDatatype: String { 30 | return Blob.declaredDatatype 31 | } 32 | 33 | public static func fromDatatypeValue(_ dataValue: Blob) -> Data { 34 | return Data(dataValue.bytes) 35 | } 36 | 37 | public var datatypeValue: Blob { 38 | return withUnsafeBytes { (pointer: UnsafeRawBufferPointer) -> Blob in 39 | return Blob(bytes: pointer.baseAddress!, length: count) 40 | } 41 | } 42 | 43 | } 44 | 45 | extension Date : Value { 46 | 47 | public static var declaredDatatype: String { 48 | return String.declaredDatatype 49 | } 50 | 51 | public static func fromDatatypeValue(_ stringValue: String) -> Date { 52 | return dateFormatter.date(from: stringValue)! 53 | } 54 | 55 | public var datatypeValue: String { 56 | return dateFormatter.string(from: self) 57 | } 58 | 59 | } 60 | 61 | /// A global date formatter used to serialize and deserialize `NSDate` objects. 62 | /// If multiple date formats are used in an application’s database(s), use a 63 | /// custom `Value` type per additional format. 64 | public var dateFormatter: DateFormatter = { 65 | let formatter = DateFormatter() 66 | formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS" 67 | formatter.locale = Locale(identifier: "en_US_POSIX") 68 | formatter.timeZone = TimeZone(secondsFromGMT: 0) 69 | return formatter 70 | }() 71 | 72 | extension UUID : Value { 73 | 74 | public static var declaredDatatype: String { 75 | return String.declaredDatatype 76 | } 77 | 78 | public static func fromDatatypeValue(_ stringValue: String) -> UUID { 79 | return UUID(uuidString: stringValue)! 80 | } 81 | 82 | public var datatypeValue: String { 83 | return self.uuidString 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Helpers.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #if SQLITE_SWIFT_STANDALONE 26 | import sqlite3 27 | #elseif SQLITE_SWIFT_SQLCIPHER 28 | import SQLCipher 29 | #elseif os(Linux) 30 | import CSQLite 31 | #else 32 | import SQLite3 33 | #endif 34 | 35 | public typealias Star = (Expression?, Expression?) -> Expression 36 | 37 | public func *(_: Expression?, _: Expression?) -> Expression { 38 | return Expression(literal: "*") 39 | } 40 | 41 | public protocol _OptionalType { 42 | 43 | associatedtype WrappedType 44 | 45 | } 46 | 47 | extension Optional : _OptionalType { 48 | 49 | public typealias WrappedType = Wrapped 50 | 51 | } 52 | 53 | // let SQLITE_STATIC = unsafeBitCast(0, sqlite3_destructor_type.self) 54 | let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self) 55 | 56 | extension String { 57 | 58 | func quote(_ mark: Character = "\"") -> String { 59 | let escaped = reduce("") { string, character in 60 | string + (character == mark ? "\(mark)\(mark)" : "\(character)") 61 | } 62 | return "\(mark)\(escaped)\(mark)" 63 | } 64 | 65 | func join(_ expressions: [Expressible]) -> Expressible { 66 | var (template, bindings) = ([String](), [Binding?]()) 67 | for expressible in expressions { 68 | let expression = expressible.expression 69 | template.append(expression.template) 70 | bindings.append(contentsOf: expression.bindings) 71 | } 72 | return Expression(template.joined(separator: self), bindings) 73 | } 74 | 75 | func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true) -> Expression { 76 | return infix([lhs, rhs], wrap: wrap) 77 | } 78 | 79 | func infix(_ terms: [Expressible], wrap: Bool = true) -> Expression { 80 | let expression = Expression(" \(self) ".join(terms).expression) 81 | guard wrap else { 82 | return expression 83 | } 84 | return "".wrap(expression) 85 | } 86 | 87 | func prefix(_ expressions: Expressible) -> Expressible { 88 | return "\(self) ".wrap(expressions) as Expression 89 | } 90 | 91 | func prefix(_ expressions: [Expressible]) -> Expressible { 92 | return "\(self) ".wrap(expressions) as Expression 93 | } 94 | 95 | func wrap(_ expression: Expressible) -> Expression { 96 | return Expression("\(self)(\(expression.expression.template))", expression.expression.bindings) 97 | } 98 | 99 | func wrap(_ expressions: [Expressible]) -> Expression { 100 | return wrap(", ".join(expressions)) 101 | } 102 | 103 | } 104 | 105 | func transcode(_ literal: Binding?) -> String { 106 | guard let literal = literal else { return "NULL" } 107 | 108 | switch literal { 109 | case let blob as Blob: 110 | return blob.description 111 | case let string as String: 112 | return string.quote("'") 113 | case let binding: 114 | return "\(binding)" 115 | } 116 | } 117 | 118 | func value(_ v: Binding) -> A { 119 | return A.fromDatatypeValue(v as! A.Datatype) as! A 120 | } 121 | 122 | func value(_ v: Binding?) -> A { 123 | return value(v!) 124 | } 125 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/SQLite.h: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | FOUNDATION_EXPORT double SQLiteVersionNumber; 4 | FOUNDATION_EXPORT const unsigned char SQLiteVersionString[]; 5 | 6 | #import "SQLiteObjc.h" 7 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Typed/Collation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | /// A collating function used to compare to strings. 26 | /// 27 | /// - SeeAlso: 28 | public enum Collation { 29 | 30 | /// Compares string by raw data. 31 | case binary 32 | 33 | /// Like binary, but folds uppercase ASCII letters into their lowercase 34 | /// equivalents. 35 | case nocase 36 | 37 | /// Like binary, but strips trailing space. 38 | case rtrim 39 | 40 | /// A custom collating sequence identified by the given string, registered 41 | /// using `Database.create(collation:…)` 42 | case custom(String) 43 | 44 | } 45 | 46 | extension Collation : Expressible { 47 | 48 | public var expression: Expression { 49 | return Expression(literal: description) 50 | } 51 | 52 | } 53 | 54 | extension Collation : CustomStringConvertible { 55 | 56 | public var description : String { 57 | switch self { 58 | case .binary: 59 | return "BINARY" 60 | case .nocase: 61 | return "NOCASE" 62 | case .rtrim: 63 | return "RTRIM" 64 | case .custom(let collation): 65 | return collation.quote() 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Typed/CustomFunctions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | public extension Connection { 26 | 27 | /// Creates or redefines a custom SQL function. 28 | /// 29 | /// - Parameters: 30 | /// 31 | /// - function: The name of the function to create or redefine. 32 | /// 33 | /// - deterministic: Whether or not the function is deterministic (_i.e._ 34 | /// the function always returns the same result for a given input). 35 | /// 36 | /// Default: `false` 37 | /// 38 | /// - block: A block of code to run when the function is called. 39 | /// The assigned types must be explicit. 40 | /// 41 | /// - Returns: A closure returning an SQL expression to call the function. 42 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping () -> Z) throws -> (() -> Expression) { 43 | let fn = try createFunction(function, 0, deterministic) { _ in block() } 44 | return { fn([]) } 45 | } 46 | 47 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping () -> Z?) throws -> (() -> Expression) { 48 | let fn = try createFunction(function, 0, deterministic) { _ in block() } 49 | return { fn([]) } 50 | } 51 | 52 | // MARK: - 53 | 54 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A) -> Z) throws -> ((Expression) -> Expression) { 55 | let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0])) } 56 | return { arg in fn([arg]) } 57 | } 58 | 59 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?) -> Z) throws -> ((Expression) -> Expression) { 60 | let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value)) } 61 | return { arg in fn([arg]) } 62 | } 63 | 64 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A) -> Z?) throws -> ((Expression) -> Expression) { 65 | let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0])) } 66 | return { arg in fn([arg]) } 67 | } 68 | 69 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?) -> Z?) throws -> ((Expression) -> Expression) { 70 | let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value)) } 71 | return { arg in fn([arg]) } 72 | } 73 | 74 | // MARK: - 75 | 76 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B) -> Z) throws -> (Expression, Expression) -> Expression { 77 | let fn = try createFunction(function, 2, deterministic) { args in block(value(args[0]), value(args[1])) } 78 | return { a, b in fn([a, b]) } 79 | } 80 | 81 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B) -> Z) throws -> (Expression, Expression) -> Expression { 82 | let fn = try createFunction(function, 2, deterministic) { args in block(args[0].map(value), value(args[1])) } 83 | return { a, b in fn([a, b]) } 84 | } 85 | 86 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B?) -> Z) throws -> (Expression, Expression) -> Expression { 87 | let fn = try createFunction(function, 2, deterministic) { args in block(value(args[0]), args[1].map(value)) } 88 | return { a, b in fn([a, b]) } 89 | } 90 | 91 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B) -> Z?) throws -> (Expression, Expression) -> Expression { 92 | let fn = try createFunction(function, 2, deterministic) { args in block(value(args[0]), value(args[1])) } 93 | return { a, b in fn([a, b]) } 94 | } 95 | 96 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B?) -> Z) throws -> (Expression, Expression) -> Expression { 97 | let fn = try createFunction(function, 2, deterministic) { args in block(args[0].map(value), args[1].map(value)) } 98 | return { a, b in fn([a, b]) } 99 | } 100 | 101 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B) -> Z?) throws -> (Expression, Expression) -> Expression { 102 | let fn = try createFunction(function, 2, deterministic) { args in block(args[0].map(value), value(args[1])) } 103 | return { a, b in fn([a, b]) } 104 | } 105 | 106 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B?) -> Z?) throws -> (Expression, Expression) -> Expression { 107 | let fn = try createFunction(function, 2, deterministic) { args in block(value(args[0]), args[1].map(value)) } 108 | return { a, b in fn([a, b]) } 109 | } 110 | 111 | func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B?) -> Z?) throws -> (Expression, Expression) -> Expression { 112 | let fn = try createFunction(function, 2, deterministic) { args in block(args[0].map(value), args[1].map(value)) } 113 | return { a, b in fn([a, b]) } 114 | } 115 | 116 | // MARK: - 117 | 118 | fileprivate func createFunction(_ function: String, _ argumentCount: UInt, _ deterministic: Bool, _ block: @escaping ([Binding?]) -> Z) throws -> (([Expressible]) -> Expression) { 119 | createFunction(function, argumentCount: argumentCount, deterministic: deterministic) { arguments in 120 | block(arguments).datatypeValue 121 | } 122 | return { arguments in 123 | function.quote().wrap(", ".join(arguments)) 124 | } 125 | } 126 | 127 | fileprivate func createFunction(_ function: String, _ argumentCount: UInt, _ deterministic: Bool, _ block: @escaping ([Binding?]) -> Z?) throws -> (([Expressible]) -> Expression) { 128 | createFunction(function, argumentCount: argumentCount, deterministic: deterministic) { arguments in 129 | block(arguments)?.datatypeValue 130 | } 131 | return { arguments in 132 | function.quote().wrap(", ".join(arguments)) 133 | } 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Typed/DateAndTimeFunctions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | import Foundation 26 | 27 | /// All five date and time functions take a time string as an argument. 28 | /// The time string is followed by zero or more modifiers. 29 | /// The strftime() function also takes a format string as its first argument. 30 | /// 31 | /// https://www.sqlite.org/lang_datefunc.html 32 | public class DateFunctions { 33 | /// The date() function returns the date in this format: YYYY-MM-DD. 34 | public static func date(_ timestring: String, _ modifiers: String...) -> Expression { 35 | return timefunction("date", timestring: timestring, modifiers: modifiers) 36 | } 37 | 38 | /// The time() function returns the time as HH:MM:SS. 39 | public static func time(_ timestring: String, _ modifiers: String...) -> Expression { 40 | return timefunction("time", timestring: timestring, modifiers: modifiers) 41 | } 42 | 43 | /// The datetime() function returns "YYYY-MM-DD HH:MM:SS". 44 | public static func datetime(_ timestring: String, _ modifiers: String...) -> Expression { 45 | return timefunction("datetime", timestring: timestring, modifiers: modifiers) 46 | } 47 | 48 | /// The julianday() function returns the Julian day - 49 | /// the number of days since noon in Greenwich on November 24, 4714 B.C. 50 | public static func julianday(_ timestring: String, _ modifiers: String...) -> Expression { 51 | return timefunction("julianday", timestring: timestring, modifiers: modifiers) 52 | } 53 | 54 | /// The strftime() routine returns the date formatted according to the format string specified as the first argument. 55 | public static func strftime(_ format: String, _ timestring: String, _ modifiers: String...) -> Expression { 56 | if !modifiers.isEmpty { 57 | let templates = [String](repeating: "?", count: modifiers.count).joined(separator: ", ") 58 | return Expression("strftime(?, ?, \(templates))", [format, timestring] + modifiers) 59 | } 60 | return Expression("strftime(?, ?)", [format, timestring]) 61 | } 62 | 63 | private static func timefunction(_ name: String, timestring: String, modifiers: [String]) -> Expression { 64 | if !modifiers.isEmpty { 65 | let templates = [String](repeating: "?", count: modifiers.count).joined(separator: ", ") 66 | return Expression("\(name)(?, \(templates))", [timestring] + modifiers) 67 | } 68 | return Expression("\(name)(?)", [timestring]) 69 | } 70 | } 71 | 72 | extension Date { 73 | public var date: Expression { 74 | return DateFunctions.date(dateFormatter.string(from: self)) 75 | } 76 | 77 | public var time: Expression { 78 | return DateFunctions.time(dateFormatter.string(from: self)) 79 | } 80 | 81 | public var datetime: Expression { 82 | return DateFunctions.datetime(dateFormatter.string(from: self)) 83 | } 84 | 85 | public var julianday: Expression { 86 | return DateFunctions.julianday(dateFormatter.string(from: self)) 87 | } 88 | } 89 | 90 | extension Expression where UnderlyingType == Date { 91 | public var date: Expression { 92 | return Expression("date(\(template))", bindings) 93 | } 94 | 95 | public var time: Expression { 96 | return Expression("time(\(template))", bindings) 97 | } 98 | 99 | public var datetime: Expression { 100 | return Expression("datetime(\(template))", bindings) 101 | } 102 | 103 | public var julianday: Expression { 104 | return Expression("julianday(\(template))", bindings) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLite/Typed/Expression.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | public protocol ExpressionType : Expressible { // extensions cannot have inheritance clauses 26 | 27 | associatedtype UnderlyingType = Void 28 | 29 | var template: String { get } 30 | var bindings: [Binding?] { get } 31 | 32 | init(_ template: String, _ bindings: [Binding?]) 33 | 34 | } 35 | 36 | extension ExpressionType { 37 | 38 | public init(literal: String) { 39 | self.init(literal, []) 40 | } 41 | 42 | public init(_ identifier: String) { 43 | self.init(literal: identifier.quote()) 44 | } 45 | 46 | public init(_ expression: U) { 47 | self.init(expression.template, expression.bindings) 48 | } 49 | 50 | } 51 | 52 | /// An `Expression` represents a raw SQL fragment and any associated bindings. 53 | public struct Expression : ExpressionType { 54 | 55 | public typealias UnderlyingType = Datatype 56 | 57 | public var template: String 58 | public var bindings: [Binding?] 59 | 60 | public init(_ template: String, _ bindings: [Binding?]) { 61 | self.template = template 62 | self.bindings = bindings 63 | } 64 | 65 | } 66 | 67 | public protocol Expressible { 68 | 69 | var expression: Expression { get } 70 | 71 | } 72 | 73 | extension Expressible { 74 | 75 | // naïve compiler for statements that can’t be bound, e.g., CREATE TABLE 76 | // FIXME: make internal (0.13.0) 77 | public func asSQL() -> String { 78 | let expressed = expression 79 | var idx = 0 80 | return expressed.template.reduce("") { template, character in 81 | let transcoded: String 82 | 83 | if character == "?" { 84 | transcoded = transcode(expressed.bindings[idx]) 85 | idx += 1 86 | } else { 87 | transcoded = String(character) 88 | } 89 | return template + transcoded 90 | } 91 | } 92 | 93 | } 94 | 95 | extension ExpressionType { 96 | 97 | public var expression: Expression { 98 | return Expression(template, bindings) 99 | } 100 | 101 | public var asc: Expressible { 102 | return " ".join([self, Expression(literal: "ASC")]) 103 | } 104 | 105 | public var desc: Expressible { 106 | return " ".join([self, Expression(literal: "DESC")]) 107 | } 108 | 109 | } 110 | 111 | extension ExpressionType where UnderlyingType : Value { 112 | 113 | public init(value: UnderlyingType) { 114 | self.init("?", [value.datatypeValue]) 115 | } 116 | 117 | } 118 | 119 | extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.WrappedType : Value { 120 | 121 | public static var null: Self { 122 | return self.init(value: nil) 123 | } 124 | 125 | public init(value: UnderlyingType.WrappedType?) { 126 | self.init("?", [value?.datatypeValue]) 127 | } 128 | 129 | } 130 | 131 | extension Value { 132 | 133 | public var expression: Expression { 134 | return Expression(value: self).expression 135 | } 136 | 137 | } 138 | 139 | public let rowid = Expression("ROWID") 140 | 141 | public func cast(_ expression: Expression) -> Expression { 142 | return Expression("CAST (\(expression.template) AS \(U.declaredDatatype))", expression.bindings) 143 | } 144 | 145 | public func cast(_ expression: Expression) -> Expression { 146 | return Expression("CAST (\(expression.template) AS \(U.declaredDatatype))", expression.bindings) 147 | } 148 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLiteObjc/SQLiteObjc.m: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #import "SQLiteObjc.h" 26 | #import "fts3_tokenizer.h" 27 | 28 | #pragma mark - FTS 29 | 30 | typedef struct __SQLiteTokenizer { 31 | sqlite3_tokenizer base; 32 | __unsafe_unretained _SQLiteTokenizerNextCallback callback; 33 | } __SQLiteTokenizer; 34 | 35 | typedef struct __SQLiteTokenizerCursor { 36 | void * base; 37 | const char * input; 38 | int inputOffset; 39 | int inputLength; 40 | int idx; 41 | } __SQLiteTokenizerCursor; 42 | 43 | static NSMutableDictionary * __SQLiteTokenizerMap; 44 | 45 | static int __SQLiteTokenizerCreate(int argc, const char * const * argv, sqlite3_tokenizer ** ppTokenizer) { 46 | __SQLiteTokenizer * tokenizer = (__SQLiteTokenizer *)sqlite3_malloc(sizeof(__SQLiteTokenizer)); 47 | if (!tokenizer) { 48 | return SQLITE_NOMEM; 49 | } 50 | memset(tokenizer, 0, sizeof(* tokenizer)); 51 | 52 | NSString * key = [NSString stringWithUTF8String:argv[0]]; 53 | tokenizer->callback = [__SQLiteTokenizerMap objectForKey:key]; 54 | if (!tokenizer->callback) { 55 | return SQLITE_ERROR; 56 | } 57 | 58 | *ppTokenizer = &tokenizer->base; 59 | return SQLITE_OK; 60 | } 61 | 62 | static int __SQLiteTokenizerDestroy(sqlite3_tokenizer * pTokenizer) { 63 | sqlite3_free(pTokenizer); 64 | return SQLITE_OK; 65 | } 66 | 67 | static int __SQLiteTokenizerOpen(sqlite3_tokenizer * pTokenizer, const char * pInput, int nBytes, sqlite3_tokenizer_cursor ** ppCursor) { 68 | __SQLiteTokenizerCursor * cursor = (__SQLiteTokenizerCursor *)sqlite3_malloc(sizeof(__SQLiteTokenizerCursor)); 69 | if (!cursor) { 70 | return SQLITE_NOMEM; 71 | } 72 | 73 | cursor->input = pInput; 74 | cursor->inputOffset = 0; 75 | cursor->inputLength = 0; 76 | cursor->idx = 0; 77 | 78 | *ppCursor = (sqlite3_tokenizer_cursor *)cursor; 79 | return SQLITE_OK; 80 | } 81 | 82 | static int __SQLiteTokenizerClose(sqlite3_tokenizer_cursor * pCursor) { 83 | sqlite3_free(pCursor); 84 | return SQLITE_OK; 85 | } 86 | 87 | static int __SQLiteTokenizerNext(sqlite3_tokenizer_cursor * pCursor, const char ** ppToken, int * pnBytes, int * piStartOffset, int * piEndOffset, int * piPosition) { 88 | __SQLiteTokenizerCursor * cursor = (__SQLiteTokenizerCursor *)pCursor; 89 | __SQLiteTokenizer * tokenizer = (__SQLiteTokenizer *)cursor->base; 90 | 91 | cursor->inputOffset += cursor->inputLength; 92 | const char * input = cursor->input + cursor->inputOffset; 93 | const char * token = [tokenizer->callback(input, &cursor->inputOffset, &cursor->inputLength) cStringUsingEncoding:NSUTF8StringEncoding]; 94 | if (!token) { 95 | return SQLITE_DONE; 96 | } 97 | 98 | *ppToken = token; 99 | *pnBytes = (int)strlen(token); 100 | *piStartOffset = cursor->inputOffset; 101 | *piEndOffset = cursor->inputOffset + cursor->inputLength; 102 | *piPosition = cursor->idx++; 103 | return SQLITE_OK; 104 | } 105 | 106 | static const sqlite3_tokenizer_module __SQLiteTokenizerModule = { 107 | 0, 108 | __SQLiteTokenizerCreate, 109 | __SQLiteTokenizerDestroy, 110 | __SQLiteTokenizerOpen, 111 | __SQLiteTokenizerClose, 112 | __SQLiteTokenizerNext 113 | }; 114 | 115 | int _SQLiteRegisterTokenizer(sqlite3 *db, const char * moduleName, const char * submoduleName, _SQLiteTokenizerNextCallback callback) { 116 | static dispatch_once_t onceToken; 117 | dispatch_once(&onceToken, ^{ 118 | __SQLiteTokenizerMap = [NSMutableDictionary new]; 119 | }); 120 | 121 | sqlite3_stmt * stmt; 122 | int status = sqlite3_prepare_v2(db, "SELECT fts3_tokenizer(?, ?)", -1, &stmt, 0); 123 | if (status != SQLITE_OK ){ 124 | return status; 125 | } 126 | const sqlite3_tokenizer_module * pModule = &__SQLiteTokenizerModule; 127 | sqlite3_bind_text(stmt, 1, moduleName, -1, SQLITE_STATIC); 128 | sqlite3_bind_blob(stmt, 2, &pModule, sizeof(pModule), SQLITE_STATIC); 129 | sqlite3_step(stmt); 130 | status = sqlite3_finalize(stmt); 131 | if (status != SQLITE_OK ){ 132 | return status; 133 | } 134 | 135 | [__SQLiteTokenizerMap setObject:[callback copy] forKey:[NSString stringWithUTF8String:submoduleName]]; 136 | 137 | return SQLITE_OK; 138 | } 139 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLiteObjc/fts3_tokenizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 July 10 3 | ** 4 | ** The author disclaims copyright to this source code. 5 | ** 6 | ************************************************************************* 7 | ** Defines the interface to tokenizers used by fulltext-search. There 8 | ** are three basic components: 9 | ** 10 | ** sqlite3_tokenizer_module is a singleton defining the tokenizer 11 | ** interface functions. This is essentially the class structure for 12 | ** tokenizers. 13 | ** 14 | ** sqlite3_tokenizer is used to define a particular tokenizer, perhaps 15 | ** including customization information defined at creation time. 16 | ** 17 | ** sqlite3_tokenizer_cursor is generated by a tokenizer to generate 18 | ** tokens from a particular input. 19 | */ 20 | #ifndef _FTS3_TOKENIZER_H_ 21 | #define _FTS3_TOKENIZER_H_ 22 | 23 | /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time. 24 | ** If tokenizers are to be allowed to call sqlite3_*() functions, then 25 | ** we will need a way to register the API consistently. 26 | */ 27 | #import "sqlite3.h" 28 | 29 | /* 30 | ** Structures used by the tokenizer interface. When a new tokenizer 31 | ** implementation is registered, the caller provides a pointer to 32 | ** an sqlite3_tokenizer_module containing pointers to the callback 33 | ** functions that make up an implementation. 34 | ** 35 | ** When an fts3 table is created, it passes any arguments passed to 36 | ** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the 37 | ** sqlite3_tokenizer_module.xCreate() function of the requested tokenizer 38 | ** implementation. The xCreate() function in turn returns an 39 | ** sqlite3_tokenizer structure representing the specific tokenizer to 40 | ** be used for the fts3 table (customized by the tokenizer clause arguments). 41 | ** 42 | ** To tokenize an input buffer, the sqlite3_tokenizer_module.xOpen() 43 | ** method is called. It returns an sqlite3_tokenizer_cursor object 44 | ** that may be used to tokenize a specific input buffer based on 45 | ** the tokenization rules supplied by a specific sqlite3_tokenizer 46 | ** object. 47 | */ 48 | typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module; 49 | typedef struct sqlite3_tokenizer sqlite3_tokenizer; 50 | typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor; 51 | 52 | struct sqlite3_tokenizer_module { 53 | 54 | /* 55 | ** Structure version. Should always be set to 0 or 1. 56 | */ 57 | int iVersion; 58 | 59 | /* 60 | ** Create a new tokenizer. The values in the argv[] array are the 61 | ** arguments passed to the "tokenizer" clause of the CREATE VIRTUAL 62 | ** TABLE statement that created the fts3 table. For example, if 63 | ** the following SQL is executed: 64 | ** 65 | ** CREATE .. USING fts3( ... , tokenizer arg1 arg2) 66 | ** 67 | ** then argc is set to 2, and the argv[] array contains pointers 68 | ** to the strings "arg1" and "arg2". 69 | ** 70 | ** This method should return either SQLITE_OK (0), or an SQLite error 71 | ** code. If SQLITE_OK is returned, then *ppTokenizer should be set 72 | ** to point at the newly created tokenizer structure. The generic 73 | ** sqlite3_tokenizer.pModule variable should not be initialized by 74 | ** this callback. The caller will do so. 75 | */ 76 | int (*xCreate)( 77 | int argc, /* Size of argv array */ 78 | const char *const*argv, /* Tokenizer argument strings */ 79 | sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */ 80 | ); 81 | 82 | /* 83 | ** Destroy an existing tokenizer. The fts3 module calls this method 84 | ** exactly once for each successful call to xCreate(). 85 | */ 86 | int (*xDestroy)(sqlite3_tokenizer *pTokenizer); 87 | 88 | /* 89 | ** Create a tokenizer cursor to tokenize an input buffer. The caller 90 | ** is responsible for ensuring that the input buffer remains valid 91 | ** until the cursor is closed (using the xClose() method). 92 | */ 93 | int (*xOpen)( 94 | sqlite3_tokenizer *pTokenizer, /* Tokenizer object */ 95 | const char *pInput, int nBytes, /* Input buffer */ 96 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Created tokenizer cursor */ 97 | ); 98 | 99 | /* 100 | ** Destroy an existing tokenizer cursor. The fts3 module calls this 101 | ** method exactly once for each successful call to xOpen(). 102 | */ 103 | int (*xClose)(sqlite3_tokenizer_cursor *pCursor); 104 | 105 | /* 106 | ** Retrieve the next token from the tokenizer cursor pCursor. This 107 | ** method should either return SQLITE_OK and set the values of the 108 | ** "OUT" variables identified below, or SQLITE_DONE to indicate that 109 | ** the end of the buffer has been reached, or an SQLite error code. 110 | ** 111 | ** *ppToken should be set to point at a buffer containing the 112 | ** normalized version of the token (i.e. after any case-folding and/or 113 | ** stemming has been performed). *pnBytes should be set to the length 114 | ** of this buffer in bytes. The input text that generated the token is 115 | ** identified by the byte offsets returned in *piStartOffset and 116 | ** *piEndOffset. *piStartOffset should be set to the index of the first 117 | ** byte of the token in the input buffer. *piEndOffset should be set 118 | ** to the index of the first byte just past the end of the token in 119 | ** the input buffer. 120 | ** 121 | ** The buffer *ppToken is set to point at is managed by the tokenizer 122 | ** implementation. It is only required to be valid until the next call 123 | ** to xNext() or xClose(). 124 | */ 125 | /* TODO(shess) current implementation requires pInput to be 126 | ** nul-terminated. This should either be fixed, or pInput/nBytes 127 | ** should be converted to zInput. 128 | */ 129 | int (*xNext)( 130 | sqlite3_tokenizer_cursor *pCursor, /* Tokenizer cursor */ 131 | const char **ppToken, int *pnBytes, /* OUT: Normalized text for token */ 132 | int *piStartOffset, /* OUT: Byte offset of token in input buffer */ 133 | int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */ 134 | int *piPosition /* OUT: Number of tokens returned before this one */ 135 | ); 136 | 137 | /*********************************************************************** 138 | ** Methods below this point are only available if iVersion>=1. 139 | */ 140 | 141 | /* 142 | ** Configure the language id of a tokenizer cursor. 143 | */ 144 | int (*xLanguageid)(sqlite3_tokenizer_cursor *pCsr, int iLangid); 145 | }; 146 | 147 | struct sqlite3_tokenizer { 148 | const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */ 149 | /* Tokenizer implementations will typically add additional fields */ 150 | }; 151 | 152 | struct sqlite3_tokenizer_cursor { 153 | sqlite3_tokenizer *pTokenizer; /* Tokenizer for this cursor. */ 154 | /* Tokenizer implementations will typically add additional fields */ 155 | }; 156 | 157 | int fts3_global_term_cnt(int iTerm, int iCol); 158 | int fts3_term_cnt(int iTerm, int iCol); 159 | 160 | 161 | #endif /* _FTS3_TOKENIZER_H_ */ 162 | -------------------------------------------------------------------------------- /Example/Pods/SQLite.swift/Sources/SQLiteObjc/include/SQLiteObjc.h: -------------------------------------------------------------------------------- 1 | // 2 | // SQLite.swift 3 | // https://github.com/stephencelis/SQLite.swift 4 | // Copyright © 2014-2015 Stephen Celis. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | @import Foundation; 26 | #if defined(SQLITE_SWIFT_STANDALONE) 27 | @import sqlite3; 28 | #elif defined(SQLITE_SWIFT_SQLCIPHER) 29 | @import SQLCipher; 30 | #else 31 | @import SQLite3; 32 | #endif 33 | 34 | NS_ASSUME_NONNULL_BEGIN 35 | typedef NSString * _Nullable (^_SQLiteTokenizerNextCallback)(const char *input, int *inputOffset, int *inputLength); 36 | int _SQLiteRegisterTokenizer(sqlite3 *db, const char *module, const char *tokenizer, _Nullable _SQLiteTokenizerNextCallback callback); 37 | NS_ASSUME_NONNULL_END 38 | 39 | -------------------------------------------------------------------------------- /Example/Pods/SQLiteValueExtension/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 暴走的鑫鑫 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Example/Pods/SQLiteValueExtension/README-CN.md: -------------------------------------------------------------------------------- 1 | # SQLiteValueExtension 2 | 基于SQLite.swift库,更方便的存储数组、字典或自定义数据类型。 3 | 4 | 核心思路是:先把数组、字典或自定义类型转成字符串类型,再进行存储。查询的时候再把字符串转成数组、字典或自定义数据类型。 5 | 6 | # 使用 7 | 8 | 只要是遵从`SQLiteValueStringExpressible`协议的数据类型,就可以通过`SQLite.swift`存储到数据库。 9 | 10 | ## 原生基础类型 11 | 以下基础类型都已经遵从`SQLiteValueStringExpressible`协议。 12 | - `Int`、 13 | - `Int64` 14 | - `Bool` 15 | - `Double` 16 | - `Float` 17 | - `String` 18 | - `Blob` 19 | - `Data` 20 | - `Date` 21 | 22 | ## 数组、字典 23 | 24 | `Array.Element`、`Dictionary.Key`和`Dictionary.Value`类型遵从`SQLiteValueStringExpressible`协议,就可以通过`SQLite.swift`存储到数据库。 25 | 26 | ```Swift 27 | //Expression定义 28 | static let intArray = Expression<[Int]?>("int_array") 29 | static let intStringDict = Expression<[Int:String]?>("int_string_dict") 30 | //Insert 31 | let insert = config.insert(normalInt <- basic.normalInt, intStringDict <- basic.intStringDict) 32 | try connection.run(insert) 33 | //Query 34 | let rows = try connection.prepare(config) 35 | var result = [BasicDataModel]() 36 | for data in rows { 37 | let basic = BasicDataModel(JSON: [String : Any]())! 38 | basic.normalInt = data[normalInt] 39 | basic.intStringDict = data[intStringDict] 40 | result.append(basic) 41 | } 42 | ``` 43 | 44 | ## 自定义类型 45 | 46 | 遵从`SQLiteValueStorable`协议并实现相关方法。 47 | 48 | `SQLiteValueStorable`继承`SQLiteValueStringExpressible`协议,在extensioin中指定了`datatypeValue`为`String`,简化了使用流程。 49 | 50 | ```Swift 51 | extension BasicInfoModel: SQLiteValueStorable { 52 | public static func fromStringValue(_ stringValue: String) -> BasicInfoModel { 53 | return BasicInfoModel(JSONString: stringValue) ?? BasicInfoModel(JSON: [String : Any]())! 54 | } 55 | public var stringValue: String { 56 | return toJSONString() ?? "" 57 | } 58 | } 59 | ``` 60 | 61 | ### 存储自定义类型的数组或字典使用示例 62 | 63 | ```Swift 64 | //Expression定义 65 | static let modelArray = Expression<[BasicInfoModel]?>("model_array") 66 | static let stringModelDict = Expression<[String:BasicInfoModel]?>("string_model_dict") 67 | //Insert 68 | let insert = config.insert(modelArray <- basic.modelArray, stringModelDict <- basic.stringModelDict) 69 | try connection.run(insert) 70 | //Query 71 | let rows = try connection.prepare(config) 72 | var result = [BasicDataModel]() 73 | for data in rows { 74 | let basic = BasicDataModel(JSON: [String : Any]())! 75 | basic.modelArray = data[modelArray] 76 | basic.intStringDict = data[intStringDict] 77 | result.append(basic) 78 | } 79 | ``` 80 | 81 | ## 新增基础类型支持 82 | 83 | 比如`Float`数据类型: 84 | ```Swift 85 | extension Float: SQLiteValueStringExpressible { 86 | public static var declaredDatatype: String { Double.declaredDatatype } 87 | public static func fromDatatypeValue(_ datatypeValue: Double) -> Float { 88 | return Float(datatypeValue) 89 | } 90 | public var datatypeValue: Double { 91 | return Double(self) 92 | } 93 | public static func fromStringValue(_ stringValue: String) -> Float { 94 | return Float(stringValue) ?? 0 95 | } 96 | public var stringValue: String { 97 | return String(self) 98 | } 99 | } 100 | ``` 101 | 102 | 如果需要支持其他基础数据类型,欢迎提交Issue或Pull Request。 103 | 104 | # 安装 105 | 106 | ## Cocoapods 107 | 108 | ``` 109 | pod 'SQLiteValueExtension' 110 | ``` 111 | 112 | ## SPM 113 | 114 | 从0.0.6版本开始支持。 115 | 116 | Xcode11的安装教程,可以参考文章:[在 Xcode 中使用 Swift Package](https://xiaozhuanlan.com/topic/9635421780) 117 | 118 | # 推荐 119 | 120 | - [ModelAdaptor](https://github.com/pujiaxin33/ModelAdaptor): 基于`SQLite.swift`的轻量级ORM库。 121 | - [SQLite.swift custom-types](https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md#custom-types) 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Example/Pods/SQLiteValueExtension/Sources/SQLiteValueExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SQLiteValueExtension.swift 3 | // SQLiteValueExtension 4 | // 5 | // Created by jiaxin on 2020/7/14. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SQLite 11 | 12 | public protocol StringValueExpressible { 13 | associatedtype ValueType = Self 14 | static func fromStringValue(_ stringValue: String) -> ValueType 15 | var stringValue: String { get } 16 | } 17 | 18 | extension Int: StringValueExpressible { 19 | public static func fromStringValue(_ stringValue: String) -> Int { 20 | return Int(stringValue) ?? 0 21 | } 22 | public var stringValue: String { 23 | return String(self) 24 | } 25 | } 26 | extension Int64: StringValueExpressible { 27 | public static func fromStringValue(_ stringValue: String) -> Int64 { 28 | return Int64(stringValue) ?? 0 29 | } 30 | public var stringValue: String { 31 | return String(self) 32 | } 33 | } 34 | extension Bool: StringValueExpressible { 35 | public static func fromStringValue(_ stringValue: String) -> Bool { 36 | return Bool(stringValue) ?? false 37 | } 38 | public var stringValue: String { 39 | return String(self) 40 | } 41 | } 42 | extension Double: StringValueExpressible { 43 | public static func fromStringValue(_ stringValue: String) -> Double { 44 | return Double(stringValue) ?? 0 45 | } 46 | public var stringValue: String { 47 | return String(self) 48 | } 49 | } 50 | extension String: StringValueExpressible { 51 | public static func fromStringValue(_ stringValue: String) -> String { 52 | return stringValue 53 | } 54 | public var stringValue: String { 55 | return self 56 | } 57 | } 58 | extension Blob: StringValueExpressible { 59 | public static func fromStringValue(_ stringValue: String) -> Blob { 60 | var bytes = [UInt8]() 61 | for start in stride(from: 0, to: stringValue.count, by: 2) { 62 | let startIndex = stringValue.index(stringValue.startIndex, offsetBy: start) 63 | let endIndex = stringValue.index(startIndex, offsetBy: 2) 64 | let byteString = stringValue[startIndex.. Data { 75 | return fromDatatypeValue(Blob.fromStringValue(stringValue)) 76 | } 77 | public var stringValue: String { 78 | return datatypeValue.toHex() 79 | } 80 | } 81 | extension Date: StringValueExpressible { 82 | public static func fromStringValue(_ stringValue: String) -> Date { 83 | return fromDatatypeValue(stringValue) 84 | } 85 | public var stringValue: String { 86 | return datatypeValue 87 | } 88 | } 89 | //=====================Add New Type ===================== 90 | extension Float: SQLiteValueStringExpressible { 91 | public static var declaredDatatype: String { Double.declaredDatatype } 92 | public static func fromDatatypeValue(_ datatypeValue: Double) -> Float { 93 | return Float(datatypeValue) 94 | } 95 | public var datatypeValue: Double { 96 | return Double(self) 97 | } 98 | public static func fromStringValue(_ stringValue: String) -> Float { 99 | return Float(stringValue) ?? 0 100 | } 101 | public var stringValue: String { 102 | return String(self) 103 | } 104 | } 105 | 106 | //=====================Extension Array===================== 107 | extension Array: Expressible where Element: StringValueExpressible { 108 | public var expression: Expression { 109 | return Expression(value: self).expression 110 | } 111 | } 112 | extension Array: SQLiteValueStringExpressible where Element: StringValueExpressible { 113 | public typealias Datatype = String 114 | public static var declaredDatatype: String { String.declaredDatatype } 115 | public static func fromStringValue(_ stringValue: String) -> Self { 116 | var result = [Element]() 117 | if let object = try? JSONSerialization.jsonObject(with: Data(stringValue.utf8), options: []) as? [String] { 118 | for string in object { 119 | let value = Element.fromStringValue(string) as! Element 120 | result.append(value) 121 | } 122 | } 123 | return result 124 | } 125 | public var stringValue: String { 126 | let stringArray = self.map { $0.stringValue } 127 | if let data = try? JSONSerialization.data(withJSONObject: stringArray, options: []) { 128 | return String(data: data, encoding: .utf8) ?? "" 129 | } 130 | return "" 131 | } 132 | public static func fromDatatypeValue(_ datatypeValue: Datatype) -> Self { 133 | return fromStringValue(datatypeValue) 134 | } 135 | public var datatypeValue: Datatype { 136 | return stringValue 137 | } 138 | } 139 | //=====================Extension Dictionary===================== 140 | extension Dictionary: Expressible where Key: StringValueExpressible, Dictionary.Value: StringValueExpressible { 141 | public var expression: Expression { 142 | return Expression(value: self).expression 143 | } 144 | } 145 | extension Dictionary: SQLiteValueStringExpressible where Dictionary.Key: StringValueExpressible, Dictionary.Value: StringValueExpressible { 146 | public typealias Datatype = String 147 | public static var declaredDatatype: String { String.declaredDatatype } 148 | public static func fromStringValue(_ stringValue: String) -> Self { 149 | var result = [Key:Dictionary.Value]() 150 | if let object = try? JSONSerialization.jsonObject(with: Data(stringValue.utf8), options: []) as? [String:String] { 151 | for (key, value) in object { 152 | let resultKey = Key.fromStringValue(key) as! Key 153 | let resultValue = Dictionary.Value.fromStringValue(value) as! Dictionary.Value 154 | result[resultKey] = resultValue 155 | } 156 | } 157 | return result 158 | } 159 | public var stringValue: String { 160 | var result = [String:String]() 161 | for (key, value) in self { 162 | result[key.stringValue] = value.stringValue 163 | } 164 | if let data = try? JSONSerialization.data(withJSONObject: result, options: []) { 165 | return String(data: data, encoding: .utf8) ?? "" 166 | } 167 | return "" 168 | } 169 | public static func fromDatatypeValue(_ datatypeValue: Datatype) -> Self { 170 | return fromStringValue(datatypeValue) 171 | } 172 | public var datatypeValue: Datatype { 173 | return stringValue 174 | } 175 | } 176 | 177 | public typealias SQLiteValueStringExpressible = SQLite.Value & StringValueExpressible 178 | 179 | //=====================For Easy Use===================== 180 | public protocol SQLiteValueStorable: SQLiteValueStringExpressible { } 181 | public extension SQLiteValueStorable { 182 | static var declaredDatatype: String { String.declaredDatatype } 183 | var datatypeValue: String { stringValue } 184 | static func fromDatatypeValue(_ datatypeValue: String) -> Self { 185 | return fromStringValue(datatypeValue) as! Self 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ModelAdapter/ModelAdapter-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.0.5 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ModelAdapter/ModelAdapter-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_ModelAdapter : NSObject 3 | @end 4 | @implementation PodsDummy_ModelAdapter 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ModelAdapter/ModelAdapter-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ModelAdapter/ModelAdapter-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double ModelAdapterVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char ModelAdapterVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ModelAdapter/ModelAdapter.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/ModelAdapter 3 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift" "${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension" 4 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 5 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" 6 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT} 10 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 13 | SKIP_INSTALL = YES 14 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 15 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ModelAdapter/ModelAdapter.modulemap: -------------------------------------------------------------------------------- 1 | framework module ModelAdapter { 2 | umbrella header "ModelAdapter-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ModelAdapter/ModelAdapter.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/ModelAdapter 3 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift" "${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension" 4 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 5 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" 6 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT} 10 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 13 | SKIP_INSTALL = YES 14 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 15 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ObjectMapper/ObjectMapper-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 4.2.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ObjectMapper/ObjectMapper-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_ObjectMapper : NSObject 3 | @end 4 | @implementation PodsDummy_ObjectMapper 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ObjectMapper/ObjectMapper-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ObjectMapper/ObjectMapper-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double ObjectMapperVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char ObjectMapperVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ObjectMapper/ObjectMapper.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/ObjectMapper 9 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 10 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | SKIP_INSTALL = YES 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ObjectMapper/ObjectMapper.modulemap: -------------------------------------------------------------------------------- 1 | framework module ObjectMapper { 2 | umbrella header "ObjectMapper-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/ObjectMapper/ObjectMapper.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/ObjectMapper 9 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 10 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | SKIP_INSTALL = YES 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_Example : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_Example 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks-Debug-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-Example/Pods-Example-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/ModelAdapter/ModelAdapter.framework 3 | ${BUILT_PRODUCTS_DIR}/ObjectMapper/ObjectMapper.framework 4 | ${BUILT_PRODUCTS_DIR}/SQLite.swift/SQLite.framework 5 | ${BUILT_PRODUCTS_DIR}/SQLiteValueExtension/SQLiteValueExtension.framework -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks-Debug-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ModelAdapter.framework 2 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectMapper.framework 3 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLite.framework 4 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLiteValueExtension.framework -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks-Release-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-Example/Pods-Example-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/ModelAdapter/ModelAdapter.framework 3 | ${BUILT_PRODUCTS_DIR}/ObjectMapper/ObjectMapper.framework 4 | ${BUILT_PRODUCTS_DIR}/SQLite.swift/SQLite.framework 5 | ${BUILT_PRODUCTS_DIR}/SQLiteValueExtension/SQLiteValueExtension.framework -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks-Release-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ModelAdapter.framework 2 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectMapper.framework 3 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLite.framework 4 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLiteValueExtension.framework -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_ExampleVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_ExampleVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 3 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ModelAdapter" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper" "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift" "${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension" 4 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 5 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ModelAdapter/ModelAdapter.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper/ObjectMapper.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift/SQLite.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension/SQLiteValueExtension.framework/Headers" 6 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 7 | OTHER_LDFLAGS = $(inherited) -l"sqlite3" -framework "ModelAdapter" -framework "ObjectMapper" -framework "SQLite" -framework "SQLiteValueExtension" -framework "UIKit" 8 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 9 | PODS_BUILD_DIR = ${BUILD_DIR} 10 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 11 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 12 | PODS_ROOT = ${SRCROOT}/Pods 13 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 14 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 15 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_Example { 2 | umbrella header "Pods-Example-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Example/Pods-Example.release.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 3 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ModelAdapter" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper" "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift" "${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension" 4 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 5 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/ModelAdapter/ModelAdapter.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/ObjectMapper/ObjectMapper.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift/SQLite.framework/Headers" "${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension/SQLiteValueExtension.framework/Headers" 6 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 7 | OTHER_LDFLAGS = $(inherited) -l"sqlite3" -framework "ModelAdapter" -framework "ObjectMapper" -framework "SQLite" -framework "SQLiteValueExtension" -framework "UIKit" 8 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 9 | PODS_BUILD_DIR = ${BUILD_DIR} 10 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 11 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 12 | PODS_ROOT = ${SRCROOT}/Pods 13 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 14 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 15 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLite.swift/SQLite.swift-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.13.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLite.swift/SQLite.swift-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_SQLite_swift : NSObject 3 | @end 4 | @implementation PodsDummy_SQLite_swift 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLite.swift/SQLite.swift-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLite.swift/SQLite.swift-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | #import "SQLite.h" 14 | #import "SQLiteObjc.h" 15 | 16 | FOUNDATION_EXPORT double SQLiteVersionNumber; 17 | FOUNDATION_EXPORT const unsigned char SQLiteVersionString[]; 18 | 19 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLite.swift/SQLite.swift.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | OTHER_LDFLAGS = $(inherited) -l"sqlite3" 5 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 6 | PODS_BUILD_DIR = ${BUILD_DIR} 7 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_ROOT = ${SRCROOT} 9 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/SQLite.swift 10 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 11 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 12 | SKIP_INSTALL = YES 13 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 14 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLite.swift/SQLite.swift.modulemap: -------------------------------------------------------------------------------- 1 | framework module SQLite { 2 | umbrella header "SQLite.swift-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLite.swift/SQLite.swift.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | OTHER_LDFLAGS = $(inherited) -l"sqlite3" 5 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 6 | PODS_BUILD_DIR = ${BUILD_DIR} 7 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_ROOT = ${SRCROOT} 9 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/SQLite.swift 10 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 11 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 12 | SKIP_INSTALL = YES 13 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 14 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLiteValueExtension/SQLiteValueExtension-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.0.7 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLiteValueExtension/SQLiteValueExtension-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_SQLiteValueExtension : NSObject 3 | @end 4 | @implementation PodsDummy_SQLiteValueExtension 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLiteValueExtension/SQLiteValueExtension-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLiteValueExtension/SQLiteValueExtension-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double SQLiteValueExtensionVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char SQLiteValueExtensionVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLiteValueExtension/SQLiteValueExtension.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension 3 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift" 4 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 5 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" 6 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT} 10 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/SQLiteValueExtension 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 13 | SKIP_INSTALL = YES 14 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 15 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLiteValueExtension/SQLiteValueExtension.modulemap: -------------------------------------------------------------------------------- 1 | framework module SQLiteValueExtension { 2 | umbrella header "SQLiteValueExtension-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/SQLiteValueExtension/SQLiteValueExtension.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SQLiteValueExtension 3 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SQLite.swift" 4 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 5 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" 6 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT} 10 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/SQLiteValueExtension 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 13 | SKIP_INSTALL = YES 14 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 15 | -------------------------------------------------------------------------------- /ModelAdapter.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | s.name = "ModelAdapter" 4 | s.version = "0.0.8" 5 | s.summary = "ModelAdapter" 6 | s.homepage = "https://github.com/pujiaxin33/ModelAdapter" 7 | s.license = "MIT" 8 | s.author = { "pujiaxin33" => "317437084@qq.com" } 9 | s.platform = :ios, "9.0" 10 | s.swift_version = "5.1" 11 | s.source = { :git => "https://github.com/pujiaxin33/ModelAdapter.git", :tag => "#{s.version}" } 12 | s.framework = "UIKit" 13 | s.source_files = "Sources", "Sources/**/*.{swift}" 14 | s.requires_arc = true 15 | 16 | s.dependency 'SQLite.swift' 17 | s.dependency 'SQLiteValueExtension', '~> 0.0.7' 18 | end 19 | -------------------------------------------------------------------------------- /ModelAdapter.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ModelAdapter/ModelAdapter.h: -------------------------------------------------------------------------------- 1 | // 2 | // ModelAdapter.h 3 | // ModelAdapter 4 | // 5 | // Created by tony on 2021/10/20. 6 | // 7 | 8 | #import 9 | 10 | //! Project version number for ModelAdapter. 11 | FOUNDATION_EXPORT double ModelAdapterVersionNumber; 12 | 13 | //! Project version string for ModelAdapter. 14 | FOUNDATION_EXPORT const unsigned char ModelAdapterVersionString[]; 15 | 16 | // In this header, you should import all the public headers of your framework using statements like #import 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ModelAdapter 2 | 3 | A SQLite ORM for Swift 5.1+ powered by [SQLite.swift](https://github.com/stephencelis/SQLite.swift). 4 | 5 | 基于SQLite.swift封装的SQLite ORM库,需要Swift 5.1+。减少SQLite.swift库需要的数据库定义、增删改查等样板代码,只需要简单的配置就能完成数据对象对应数据库表的搭建。 6 | 7 | # 使用示例 8 | 9 | 下面是一个简单使用示例,看看`ModelAdapter`如何简化代码! 10 | 11 | ## Column定义 12 | 13 | - 1、数据类型遵从`ModelAdapterModel`协议 14 | - 2、非可选值属性使用`@Field`进行注解 15 | - 3、可选值属性使用`@FieldOptional`进行注解 16 | - 4、在`Field`或`FieldOptional`初始化器填写column相关信息 17 | 18 | ```Swift 19 | struct CustomModel: ModelAdapterModel { 20 | @Field(key: "user_id", primaryKey: true) 21 | var userID: Int = 0 22 | @FieldOptional 23 | var nickName: String? 24 | @FieldOptional(unique: true) 25 | var phone: Int? 26 | @Field 27 | var age: Int = 0 28 | 29 | init() { 30 | initFieldExpressions() 31 | } 32 | } 33 | ``` 34 | 35 | ## `ModelAdapterModel`其他配置 36 | 37 | - 实现`ModelAdapterModel`协议的指定初始化器,并且在`init`方法调用`initFieldExpressions`方法。 38 | ```Swift 39 | struct CustomModel: ModelAdapterModel { 40 | init() { 41 | initFieldExpressions() 42 | } 43 | } 44 | ``` 45 | 46 | ## 数据库DAO定义 47 | 48 | - 自定义`CustomDAO`类,遵从`ModelAdapterDAO`协议 49 | - 设置关联类型`Entity`为`CustomModel` 50 | - 实现`ModelAdapterDAO`协议要求的`connection`和`table`属性 51 | - 整个数据库层的定义就完成了,不需要自己写增删改查的样板代码了。 52 | 53 | ```Swift 54 | class CustomDAO: ModelAdapterDAO { 55 | typealias Entity = CustomModel 56 | var connection: Connection = try! Connection("\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/db.sqlite3") 57 | var table: Table = Table("user") 58 | 59 | required init() { 60 | } 61 | } 62 | ``` 63 | 64 | ## 开始使用 65 | 66 | ### 通过JSON字典数据创建model。 67 | 引入了[ObjectMapper](https://github.com/tristanhimmelman/ObjectMapper)库完成JSON To Model。 68 | ```Swift 69 | let jsonDict = ["user_id" : 123, "nickName" : "暴走的鑫鑫", "phone": 123456, "age": 33] 70 | let model = CustomModel(JSON: jsonDict)! 71 | ``` 72 | 73 | ### 创建dao实例并创建数据库表单 74 | ```Swift 75 | let dao = CustomDAO() 76 | dao.createTable() 77 | ``` 78 | 79 | ### 插入数据 80 | ```Swift 81 | try? dao.insert(entity: model) 82 | ``` 83 | 84 | ### 删除数据 85 | ```Swift 86 | try? dao.delete(model.$userID.expression == 123) 87 | ``` 88 | 89 | ### 更新数据 90 | ```Swift 91 | model.phone = 654321 92 | try? dao.update(entity: model, model.$userID.expression == 123) 93 | ``` 94 | 95 | ### 查询数据 96 | ```Swift 97 | //查询全部 98 | let queryAll = try? dao.queryAll() 99 | //条件查询 100 | let queryOne = try? dao.query(model.$userID.expression == 123) 101 | ``` 102 | 103 | # 详细说明 104 | 105 | ## 自定义column key 106 | 107 | - 默认是属性名称,比如age属性在数据库的column值就是age 108 | - 通过Field的key进行自定义,比如nickName属性在数据库的column值就是nick_name 109 | 110 | ```Swift 111 | @Field(key: "nick_name")) 112 | var nickName: String = "名字" 113 | @Field 114 | var age: Int = 0 115 | ``` 116 | 117 | ## 自动创建数据库column 118 | 119 | 当首次建表之后,后续添加的属性,会自动创建数据库column。比如现在新增了height属性,只需要正常配置即可。 120 | ```Swift 121 | @Field 122 | var height: Double = 188 123 | ``` 124 | 125 | ## 存储自定义类型 126 | 127 | 属性的类型是自定义类型时,需要让自定义类型遵从`SQLiteValueStringExpressible`协议并实现相关方法,就能够存储进数据库。为了方便使用,使用`SQLiteValueStorable`协议,它遵从于`SQLiteValueStringExpressible`协议。 128 | 129 | `SQLiteValueStorable`协议就是让自定义类型能够和String互相转换,从而能够存储进数据库。更多详细信息,点击[SQLiteValueExtension](https://github.com/pujiaxin33/SQLiteValueExtension)进行了解。 130 | 131 | 使用`SQLiteValueStorable`协议时需要导入`import SQLiteValueExtension`。 132 | 133 | ```Swift 134 | struct NestModel: SQLiteValueStorable { 135 | var nestName: String? 136 | var nestAge: Int = 0 137 | 138 | static func fromStringValue(_ stringValue: String) -> NestModel { 139 | return NestModel(JSONString: stringValue) ?? NestModel(JSON: [String : Any]())! 140 | } 141 | var stringValue: String { 142 | return toJSONString() ?? "" 143 | } 144 | } 145 | 146 | class CustomModel: ModelAdapterModel { 147 | @FieldOptional 148 | var nest: NestModel? 149 | } 150 | ``` 151 | 152 | ## 存储数组、字典 153 | 154 | 以下基础类型都已经遵从`SQLiteValueStringExpressible`协议。 155 | - `Int`、 156 | - `Int64` 157 | - `Bool` 158 | - `Double` 159 | - `Float` 160 | - `String` 161 | - `Blob` 162 | - `Data` 163 | - `Date` 164 | 165 | ### 存储数组 166 | 167 | 只需要`Array.Element`遵从于`SQLiteValueStringExpressible`即可。比如`[NestModel]`、`[Int]`、`[Date]`。 168 | 169 | ### 存储字典 170 | 171 | 只需要`Dictionay.key`和`Value`遵从于`SQLiteValueStringExpressible`即可。 172 | 比如`[String: NestModel]`、`[Int : NestModel]`、`[String: [NestModel]]`。 173 | 174 | ## 自定义存储属性 175 | 176 | 如果值类型没有遵从`SQLiteValueStringExpressible`,就不能使用@Field。需要遵从`ModelAdapterModelCustomStorage`协议,然后自己处理数据的存储流程。存储数据类型`Set`示例如下: 177 | ```Swift 178 | class CustomModel: ModelAdapterModel { 179 | var customSet: Set? = nil 180 | } 181 | 182 | extension CustomModel: ModelAdapterCustomStorage { 183 | static let customSetExpression = Expression("custom_set") 184 | 185 | func createColumn(tableBuilder: TableBuilder) { 186 | tableBuilder.column(CustomModel.customSetExpression) 187 | } 188 | func setters() -> [Setter] { 189 | guard let set = customSet else { 190 | return [] 191 | } 192 | guard let data = try? JSONSerialization.data(withJSONObject: Array(set), options: []) else { 193 | return [] 194 | } 195 | return [CustomModel.customSetExpression <- String(data: data, encoding: .utf8)] 196 | } 197 | mutating func update(with row: Row) { 198 | guard let string = row[CustomModel.customSetExpression] else { 199 | return 200 | } 201 | let data = Data(string.utf8) 202 | guard let stringArray = try? JSONSerialization.jsonObject(with: data, options: []) as? [String] else { 203 | return 204 | } 205 | self.customSet = Set(stringArray) 206 | } 207 | } 208 | ``` 209 | 210 | ## DAO层使用 211 | 212 | `ModelAdapterDAO`协议默认实现了常用的增删改查方法: 213 | ```Swift 214 | func createTable(ifNotExists: Bool) 215 | func insert(entity: Entity) throws 216 | func insert(entities: [Entity]) throws 217 | func deleteAll() throws 218 | func delete(_ predicate: SQLite.Expression) throws 219 | func delete(_ predicate: SQLite.Expression) throws 220 | func update(entity: Entity, _ predicate: SQLite.Expression) throws 221 | func update(entity: Entity, _ predicate: SQLite.Expression) throws 222 | func query(_ predicate: SQLite.Expression) throws -> Entity? 223 | func query(_ predicate: SQLite.Expression) throws -> Entity? 224 | func queryAll() throws -> [Entity]? 225 | ``` 226 | 227 | ### 自定义数据库操作 228 | 229 | ```Swift 230 | class CustomDAO: ModelAdapterDAO { 231 | func customUpdate(entity: Entity) throws { 232 | let statement = table.update(entity.$nickName.expression <- "自定义更新") 233 | try connection.run(statement) 234 | } 235 | } 236 | ``` 237 | 238 | # 安装 239 | 240 | ## Cocoapods 241 | 242 | ``` 243 | pod 'ModelAdapter', '~> 0.0.8' 244 | ``` 245 | 246 | # 要求 247 | 248 | - iOS 9+ 249 | - Swift 5.1+ 250 | - Xcode 12+ 251 | 252 | # 依赖 253 | 254 | - `SQLite.swift` 255 | - `SQLiteValueExtension` 256 | 257 | 258 | -------------------------------------------------------------------------------- /Sources/Core/Defines.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FieldWrappedProtocol.swift 3 | // ModelAdapter 4 | // 5 | // Created by jiaxin on 2020/6/15. 6 | // 7 | 8 | import Foundation 9 | import SQLite 10 | 11 | public protocol ModelAdapterModel: CustomStringConvertible { 12 | init() 13 | mutating func update(with row: Row) 14 | } 15 | public extension ModelAdapterModel { 16 | func update(with row: Row) {} 17 | } 18 | 19 | public extension ModelAdapterModel { 20 | var description: String { 21 | let mirror = Mirror(reflecting: self) 22 | var infoDict = [String:Any]() 23 | for child in mirror.children { 24 | guard let propertyName = child.label else { 25 | continue 26 | } 27 | if let valueDesc = child.value as? CustomStringConvertible { 28 | infoDict[propertyName] = valueDesc.description 29 | }else if JSONSerialization.isValidJSONObject(child.value) { 30 | infoDict[propertyName] = child.value 31 | }else { 32 | let valueMirror = Mirror(reflecting: child.value) 33 | infoDict[propertyName] = mirrorDescriptionPrettyPrinted(valueMirror.description) 34 | } 35 | } 36 | if JSONSerialization.isValidJSONObject(infoDict), 37 | let data = try? JSONSerialization.data(withJSONObject: infoDict, options: .prettyPrinted), 38 | let string = String(data: data, encoding: .utf8) { 39 | return "\(mirrorDescriptionPrettyPrinted(mirror.description)):\(string)" 40 | } 41 | return mirrorDescriptionPrettyPrinted(mirror.description) 42 | } 43 | } 44 | 45 | public protocol ModelAdapterModelCustomStorage { 46 | func createColumn(tableBuilder: TableBuilder) 47 | func addColumnStatements(table: Table) -> [String]? 48 | func setters() -> [Setter] 49 | } 50 | 51 | public extension ModelAdapterModelCustomStorage { 52 | func addColumnStatements(table: Table) -> [String]? { 53 | return nil 54 | } 55 | } 56 | 57 | protocol FieldIdentifierProtocol { 58 | var key: String? { get } 59 | } 60 | 61 | protocol FieldStorageIdentifierBaseProtocol: FieldIdentifierProtocol { 62 | func createColumn(tableBuilder: TableBuilder) 63 | func addColumn(table: Table) -> String? 64 | func setter() -> Setter? 65 | func initExpresionIfNeeded(key: String) 66 | func update(with row: Row) 67 | } 68 | protocol FieldStorageIdentifierProtocol: FieldStorageIdentifierBaseProtocol { } 69 | protocol FieldOptionalStorageIdentifierProtocol: FieldStorageIdentifierBaseProtocol { } 70 | 71 | 72 | internal func mirrorDescriptionPrettyPrinted(_ string: String) -> String { 73 | return string.replacingOccurrences(of: "Mirror for ", with: "") 74 | } 75 | -------------------------------------------------------------------------------- /Sources/Core/Field.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Defines.swift 3 | // ModelAdapter 4 | // 5 | // Created by jiaxin on 2020/6/14. 6 | // Copyright © 2020 jiaxin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SQLite 11 | 12 | class StorageParams { 13 | var key: String? = nil 14 | var isPrimaryKey: Bool? = nil 15 | var primaryKey: SQLite.PrimaryKey? = nil 16 | var unique: Bool = false 17 | var collate: SQLite.Collation? = nil 18 | var check: ((Expression) -> Expression)? = nil 19 | var checkOptional: ((Expression) -> Expression)? = nil 20 | 21 | init(key: String? = nil, isPrimaryKey: Bool? = nil, primaryKey: SQLite.PrimaryKey? = nil, unique: Bool = false, collate: SQLite.Collation? = nil, check: ((Expression) -> Expression)? = nil, checkOptional: ((Expression) -> Expression)? = nil) { 22 | self.key = key 23 | self.isPrimaryKey = isPrimaryKey 24 | self.primaryKey = primaryKey 25 | self.unique = unique 26 | self.collate = collate 27 | self.check = check 28 | self.checkOptional = checkOptional 29 | } 30 | } 31 | 32 | extension Field: FieldIdentifierProtocol { } 33 | 34 | @propertyWrapper public class Field { 35 | public var wrappedValue: Value 36 | public var projectedValue: Field { self } 37 | let key: String? 38 | let params: StorageParams 39 | 40 | public init(wrappedValue: Value, key: String? = nil, primaryKey: Bool? = nil, check: ((Expression) -> Expression)? = nil) { 41 | self.wrappedValue = wrappedValue 42 | self.params = StorageParams(key: key, isPrimaryKey: primaryKey, check: check) 43 | self.key = key 44 | 45 | if wrappedValue is ExpressibleByNilLiteral { 46 | assertionFailure("Use @FieldOptional when value is optional") 47 | } 48 | } 49 | public init(wrappedValue: Value, key: String? = nil, unique: Bool = false, check: ((Expression) -> Expression)? = nil) { 50 | self.wrappedValue = wrappedValue 51 | self.params = StorageParams(key: key, unique: unique, check: check) 52 | self.key = key 53 | 54 | if wrappedValue is ExpressibleByNilLiteral { 55 | assertionFailure("Use @FieldOptional when value is optional") 56 | } 57 | } 58 | 59 | public init(wrappedValue: Value, key: String? = nil, primaryKey: SQLite.PrimaryKey? = nil, check: ((Expression) -> Expression)? = nil) where Value == Int64 { 60 | self.wrappedValue = wrappedValue 61 | self.params = StorageParams(key: key, primaryKey: primaryKey, check: check) 62 | self.key = key 63 | 64 | if wrappedValue is ExpressibleByNilLiteral { 65 | assertionFailure("Use @FieldOptional when value is optional") 66 | } 67 | } 68 | public init(wrappedValue: Value, key: String? = nil, primaryKey: SQLite.PrimaryKey? = nil, collate: SQLite.Collation? = nil, check: ((Expression) -> Expression)? = nil) where Value == String { 69 | self.wrappedValue = wrappedValue 70 | self.params = StorageParams(key: key, primaryKey: primaryKey, collate: collate, check: check) 71 | self.key = key 72 | 73 | if wrappedValue is ExpressibleByNilLiteral { 74 | assertionFailure("Use @FieldOptional when value is optional") 75 | } 76 | } 77 | public init(wrappedValue: Value, key: String? = nil, unique: Bool = false, collate: SQLite.Collation? = nil, check: ((Expression) -> Expression)? = nil) where Value == String { 78 | self.wrappedValue = wrappedValue 79 | self.params = StorageParams(key: key, unique: unique, collate: collate, check: check) 80 | self.key = key 81 | 82 | if wrappedValue is ExpressibleByNilLiteral { 83 | assertionFailure("Use @FieldOptional when value is optional") 84 | } 85 | } 86 | } 87 | extension Field: CustomStringConvertible { 88 | public var description: String { 89 | if let desc = self.wrappedValue as? CustomStringConvertible { 90 | return desc.description 91 | }else { 92 | let mirror = Mirror(reflecting: self.wrappedValue) 93 | return mirrorDescriptionPrettyPrinted(mirror.description) 94 | } 95 | } 96 | } 97 | 98 | extension FieldOptional: FieldIdentifierProtocol {} 99 | 100 | @propertyWrapper public class FieldOptional { 101 | public var wrappedValue: Value? 102 | public var projectedValue: FieldOptional { self } 103 | let key: String? 104 | let params: StorageParams 105 | 106 | public init(wrappedValue: Value? = nil, key: String? = nil, unique: Bool = false, check: ((Expression) -> Expression)? = nil) { 107 | self.wrappedValue = wrappedValue 108 | self.params = StorageParams(key: key, unique: unique, checkOptional: check) 109 | self.key = key 110 | } 111 | public init(wrappedValue: Value? = nil, key: String? = nil, unique: Bool = false, collate: SQLite.Collation? = nil, check: ((Expression) -> Expression)? = nil) where Value == String { 112 | self.wrappedValue = wrappedValue 113 | self.params = StorageParams(key: key, unique: unique, collate: collate, checkOptional: check) 114 | self.key = key 115 | } 116 | } 117 | extension FieldOptional: CustomStringConvertible { 118 | public var description: String { 119 | if let desc = self.wrappedValue as? CustomStringConvertible { 120 | return desc.description 121 | }else if let value = self.wrappedValue { 122 | let mirror = Mirror(reflecting: value) 123 | return mirrorDescriptionPrettyPrinted(mirror.description) 124 | }else { 125 | return "nil" 126 | } 127 | } 128 | } 129 | 130 | -------------------------------------------------------------------------------- /Sources/Core/KeyManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // KeyManager.swift 3 | // ModelAdapter 4 | // 5 | // Created by jiaxin on 2020/6/30. 6 | // 7 | 8 | import Foundation 9 | 10 | class KeyManager { 11 | static func storageKey(propertyName: String, key: String?) -> String { 12 | if key?.isEmpty == false { 13 | return key! 14 | }else if propertyName.hasPrefix("_") { 15 | let from = propertyName.index(after: propertyName.startIndex) 16 | return String(propertyName[from...]) 17 | }else { 18 | return propertyName 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/Storage/StorageWrappedProtocol.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FieldDAOExtension.swift 3 | // ModelAdapter 4 | // 5 | // Created by jiaxin on 2020/6/15. 6 | // 7 | 8 | import Foundation 9 | import SQLite 10 | import SQLiteValueExtension 11 | import UIKit 12 | 13 | struct AssociatedKeys { 14 | static var expression: UInt8 = 0 15 | static var expressionOptional: UInt8 = 0 16 | } 17 | 18 | protocol FieldValueDataypeEqualToInt64IdentifierProtocol { 19 | func createColumnWithPrimaryKey(tableBuilder: TableBuilder) 20 | } 21 | protocol FieldValueDataypeEqualToStringIdentifierProtocol { 22 | func createColumnWithCollate(tableBuilder: TableBuilder) 23 | func addColumnWithCollate(table: Table) -> String? 24 | } 25 | 26 | extension Field: FieldStorageIdentifierBaseProtocol where Value: SQLiteValueStringExpressible { } 27 | extension Field: FieldStorageIdentifierProtocol where Value: SQLiteValueStringExpressible { 28 | public var expression: Expression { 29 | set { 30 | objc_setAssociatedObject(self, &AssociatedKeys.expression, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 31 | } 32 | get { 33 | return objc_getAssociatedObject(self, &AssociatedKeys.expression) as! Expression 34 | } 35 | } 36 | 37 | public func setter() -> Setter? { 38 | return self.expression <- self.wrappedValue 39 | } 40 | 41 | public func initExpresionIfNeeded(key: String) { 42 | if objc_getAssociatedObject(self, &AssociatedKeys.expression) == nil { 43 | self.expression = Expression(key) 44 | } 45 | } 46 | 47 | public func update(with row: Row) { 48 | if let rowValue = try? row.get(expression) { 49 | self.wrappedValue = rowValue 50 | } 51 | } 52 | 53 | public func createColumn(tableBuilder: TableBuilder) { 54 | if self.params.isPrimaryKey != nil { 55 | tableBuilder.column(expression, primaryKey: self.params.isPrimaryKey!, check: self.params.check?(expression)) 56 | }else if self.params.primaryKey != nil { 57 | if let bridge = self as? FieldValueDataypeEqualToInt64IdentifierProtocol { 58 | bridge.createColumnWithPrimaryKey(tableBuilder: tableBuilder) 59 | } 60 | }else if self.params.collate != nil { 61 | if let bridge = self as? FieldValueDataypeEqualToStringIdentifierProtocol { 62 | bridge.createColumnWithCollate(tableBuilder: tableBuilder) 63 | } 64 | }else { 65 | tableBuilder.column(expression, unique: self.params.unique, check: self.params.check?(expression)) 66 | } 67 | } 68 | 69 | public func addColumn(table: Table) -> String? { 70 | if self.params.collate != nil { 71 | if let bridge = self as? FieldValueDataypeEqualToStringIdentifierProtocol { 72 | return bridge.addColumnWithCollate(table: table) 73 | } 74 | } 75 | return table.addColumn(expression, check: self.params.check?(expression), defaultValue: self.wrappedValue) 76 | } 77 | } 78 | 79 | extension Field: FieldValueDataypeEqualToInt64IdentifierProtocol where Value: SQLiteValueStringExpressible, Value.Datatype == Int64 { 80 | func createColumnWithPrimaryKey(tableBuilder: TableBuilder) { 81 | if self.params.primaryKey != nil { 82 | tableBuilder.column(expression, primaryKey: self.params.primaryKey!, check: self.params.check?(expression)) 83 | } 84 | } 85 | } 86 | extension Field: FieldValueDataypeEqualToStringIdentifierProtocol where Value: SQLiteValueStringExpressible, Value.Datatype == String { 87 | func createColumnWithCollate(tableBuilder: TableBuilder) { 88 | if self.params.collate != nil { 89 | tableBuilder.column(expression, unique: self.params.unique, check: self.params.check?(expression), collate: self.params.collate!) 90 | } 91 | } 92 | func addColumnWithCollate(table: Table) -> String? { 93 | if self.params.collate != nil { 94 | return table.addColumn(expression, check: self.params.check?(expression), defaultValue: self.wrappedValue, collate: self.params.collate!) 95 | } 96 | return nil 97 | } 98 | } 99 | 100 | extension FieldOptional: FieldStorageIdentifierBaseProtocol where Value: SQLiteValueStringExpressible { } 101 | extension FieldOptional: FieldOptionalStorageIdentifierProtocol where Value: SQLiteValueStringExpressible { 102 | public var expression: Expression { 103 | set { 104 | objc_setAssociatedObject(self, &AssociatedKeys.expressionOptional, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 105 | } 106 | get { 107 | return objc_getAssociatedObject(self, &AssociatedKeys.expressionOptional) as! Expression 108 | } 109 | } 110 | 111 | public func setter() -> Setter? { 112 | return self.expression <- self.wrappedValue 113 | } 114 | 115 | public func initExpresionIfNeeded(key: String) { 116 | if objc_getAssociatedObject(self, &AssociatedKeys.expressionOptional) == nil { 117 | self.expression = Expression(key) 118 | } 119 | } 120 | 121 | public func update(with row: Row) { 122 | self.wrappedValue = try? row.get(expression) 123 | } 124 | 125 | public func createColumn(tableBuilder: TableBuilder) { 126 | if self.params.collate != nil { 127 | if let bridge = self as? FieldValueDataypeEqualToStringIdentifierProtocol { 128 | bridge.createColumnWithCollate(tableBuilder: tableBuilder) 129 | } 130 | }else { 131 | if let check = self.params.checkOptional?(expression) { 132 | tableBuilder.column(expression, unique: self.params.unique, check: check) 133 | }else { 134 | tableBuilder.column(expression, unique: self.params.unique) 135 | } 136 | } 137 | } 138 | 139 | public func addColumn(table: Table) -> String? { 140 | if self.params.collate != nil { 141 | if let bridge = self as? FieldValueDataypeEqualToStringIdentifierProtocol { 142 | return bridge.addColumnWithCollate(table: table) 143 | } 144 | } 145 | if let check = self.params.checkOptional?(expression) { 146 | return table.addColumn(expression, check: check, defaultValue: self.wrappedValue) 147 | }else { 148 | return table.addColumn(expression, defaultValue: self.wrappedValue) 149 | } 150 | } 151 | } 152 | 153 | extension FieldOptional: FieldValueDataypeEqualToStringIdentifierProtocol where Value: SQLiteValueStringExpressible, Value.Datatype == String { 154 | func createColumnWithCollate(tableBuilder: TableBuilder) { 155 | if self.params.collate != nil { 156 | if let check = self.params.checkOptional?(expression) { 157 | tableBuilder.column(expression, unique: self.params.unique, check: check, collate: self.params.collate!) 158 | }else { 159 | tableBuilder.column(expression, unique: self.params.unique, collate: self.params.collate!) 160 | } 161 | 162 | } 163 | } 164 | func addColumnWithCollate(table: Table) -> String? { 165 | if self.params.collate != nil { 166 | if let check = self.params.checkOptional?(expression) { 167 | return table.addColumn(expression, check: check, defaultValue: self.wrappedValue, collate: self.params.collate!) 168 | }else { 169 | return table.addColumn(expression, defaultValue: self.wrappedValue, collate: self.params.collate!) 170 | } 171 | } 172 | return nil 173 | } 174 | } 175 | --------------------------------------------------------------------------------