iFS 2.0

iFS 2.0

FRΛƝCƎƧCØ SØRRƎƝTIƝØ 维护。



iFS 2.0

  • FRΛƝCƎƧCØ SØRRƎƝTIƝØ

iFS

为 iOS 9+ 提供开发便利,以支持开发者加快某些频繁使用的操作

contact platform cocoapods carthage license

安装

CocoaPods

pod 'iFS'

手动

Imports iFS framework and the related frameworks dependencies in your project

功能

内购验证

FsManager.InAppPurchase.shared.verifyReceipt(productID: "ProductID001", sharedKey: "XXX", isSandBox: true) { (jResult) in
	print("Output: \(jResult)")
}

验证涉及使用产品ID和共享密钥。可能的答案可以是

  • 有效(已购买产品)
  • 未测试(无法进行测试或从未购买过)
  • 已过期(适用于可续订订阅)
  • 已取消(因退款请求而取消)

侧菜单

let sideMenuVC = sideMenuViewController() 
if self.navigationController != nil {
	FsManager.SideMenu.shared.open(direction: .left, container: self.navigationController!, injectViewController: sideMenuVC)
}

解析JSON到Codable模型

extension FsManager.Models {

    class Base: Codable {
        let update: Bool
        let success: Bool
        
        private enum CodingKeys: String, CodingKey {
            case update
            case success
        }
        
        required init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)
            self.update = try container.decode(Bool.self, forKey: .update)
            self.success = try container.decode(Bool.self, forKey: .success)
        }
        
        func encode(to encoder: Encoder) throws {
            var container = encoder.container(keyedBy: CodingKeys.self)
            try container.encode(update, forKey: .update)
            try container.encode(success, forKey: .success)
        }
    }
    
    class User: Base {
        let data: Data?
        
        private enum CodingKeys: String, CodingKey {
            case data
        }
        
        required init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)
            self.data = try container.decodeIfPresent(Data.self, forKey: .data)
            try super.init(from: decoder)
        }
        
        struct Data: Codable {
            let id: Int
            let name: String
            let userid: String
            let password: String

            private enum CodingKeys: String, CodingKey {
                case id
                case name
                case userid
				case password
            }
            
            init(from data: Data) {
                self.id = data.id
                self.name = data.name
                self.userid = data.userid
                self.password = data.password
            }
        }
    }
	
}

let jsonUser: JSON(
	[
		"success": true,
		"update": false,
		"data": JSON(
			[
				"id": 1,
				"name": "Full name of user",
				"userid": "user001",
				"password": "test.123"
			]
		)
	]
)

let user: FsManager.Models.User = FsManager.Models.shared.decode(json: jsonUser)

读写Realm模型

保存整个模型到Realm

let user: FsManager.Models.User = FsManager.Models.shared.decode(json: jsonUser, toRealm: true, toRealmUpdate: true)

仅保存必要的Codable模型到Realm

extension FsManager.Models {

    class User: Base {
        let data: RLM_User?
        
        private enum CodingKeys: String, CodingKey {
            case data
        }
        
        required init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)
            self.data = try container.decodeIfPresent(Data.self, forKey: .data)
            try super.init(from: decoder)
        }
        
    }
	
	class RLM_User: Object, Codable {
		@objc dynamic var id = 0
		@objc dynamic var name = ""
		@objc dynamic var userid = ""
		@objc dynamic var password = ""

		override static func primaryKey() -> String? {
			return #keyPath(RLM_User.id)
		}

		private enum CodingKeys: String, CodingKey {
			case id
			case name
			case userid
			case password
		}

		convenience init(from data: RLM_User) {
			self.init()
			self.id = data.id
			self.name = data.name
			self.userid = data.userid
			self.password = data.password
		}

		convenience required init(from decoder: Decoder) throws {
			let container = try decoder.container(keyedBy: CodingKeys.self)
			let data = RLM_User()
			data.id = try container.decode(Int.self, forKey: .id)
			data.name = try container.decode(String.self, forKey: .name)
			data.userid = try container.decode(String.self, forKey: .userid)
			data.password = try container.decode(String.self, forKey: .password)
			self.init(from: data)
		}

		required init() {
			super.init()
		}

		required init(value: Any, schema: RLMSchema) {
			super.init(value: value, schema: schema)
		}

		required init(realm: RLMRealm, schema: RLMObjectSchema) {
			super.init(realm: realm, schema: schema)
		}

	}
	
}

if let userToRealm = user.data {
	FsManager.RealmManager.shared.save(nil, content: userToRealm, type: .realmObject, isUpdate: true, completion: { (errorLevel) in
		print("ErrorLevel: \(errorLevel)")
	})
}

REST API

FsManager.Api.shared.rest("Url api rest", .get, [:], nil, .json, true, completion: { (success, result, response, errorLevel, errorMsg) in
	print("Success: \(success)")
	print("Result: \(result)")
	print("Response: \(response)")
	print("ErrorLevel: \(errorLevel)")
	print("ErrorMsg: \(errorMsg)")
})

许可证

The MIT License (MIT)

Copyright (c) 2018 Francesco Sorrentino

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.