Skip to content

Commit 5261101

Browse files
committed
Update license
1 parent a91d7db commit 5261101

File tree

13 files changed

+149
-64
lines changed

13 files changed

+149
-64
lines changed

KakaJSON.xcodeproj/project.pbxproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
2D645BA12302995100075A9E /* TypeProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D645BA02302995100075A9E /* TypeProxy.swift */; };
2020
2D645BA323029A0400075A9E /* ConvertibleEnum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D645BA223029A0400075A9E /* ConvertibleEnum.swift */; };
2121
2D645D3F23058B2500046636 /* ConvertibleConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D645D3E23058B2500046636 /* ConvertibleConfig.swift */; };
22-
2D7B8DE2230825D000DEC901 /* Set+KK.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D7B8DE1230825D000DEC901 /* Set+KK.swift */; };
2322
2D92DD232301262500A96858 /* KakaJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D92DD192301262500A96858 /* KakaJSON.framework */; };
2423
2D92DD2A2301262500A96858 /* KakaJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D92DD1C2301262500A96858 /* KakaJSON.h */; settings = {ATTRIBUTES = (Public, ); }; };
2524
2D92DDA8230126BD00A96858 /* Common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DD9F230126BD00A96858 /* Common.swift */; };
@@ -91,11 +90,11 @@
9190
2D5875C92301C2C4001A809B /* MTJ_03_ModelArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTJ_03_ModelArray.swift; sourceTree = "<group>"; };
9291
2D5875CB2301C49D001A809B /* MTJ_04_KeyMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTJ_04_KeyMapping.swift; sourceTree = "<group>"; };
9392
2D5875CD2301CFEF001A809B /* MTJ_05_CustomValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTJ_05_CustomValue.swift; sourceTree = "<group>"; };
93+
2D5C3F38230CFBC2008EF2DC /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
9494
2D645B9E23026E8E00075A9E /* ModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelType.swift; sourceTree = "<group>"; };
9595
2D645BA02302995100075A9E /* TypeProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProxy.swift; sourceTree = "<group>"; };
9696
2D645BA223029A0400075A9E /* ConvertibleEnum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertibleEnum.swift; sourceTree = "<group>"; };
9797
2D645D3E23058B2500046636 /* ConvertibleConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertibleConfig.swift; sourceTree = "<group>"; };
98-
2D7B8DE1230825D000DEC901 /* Set+KK.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Set+KK.swift"; sourceTree = "<group>"; };
9998
2D92DD192301262500A96858 /* KakaJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KakaJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; };
10099
2D92DD1C2301262500A96858 /* KakaJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KakaJSON.h; sourceTree = "<group>"; };
101100
2D92DD1D2301262500A96858 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -264,7 +263,6 @@
264263
2D92DDBC2301279E00A96858 /* JSONSerialization+KK.swift */,
265264
2DCEB38C230175AC0030701B /* Array+KK.swift */,
266265
2D5253AD2305461300F854D9 /* NSObject+KK.swift */,
267-
2D7B8DE1230825D000DEC901 /* Set+KK.swift */,
268266
2D0AC2B423099A4B00992F29 /* Data+KK.swift */,
269267
);
270268
path = Extension;
@@ -273,6 +271,7 @@
273271
2D92DDBD2301279E00A96858 /* Metadata */ = {
274272
isa = PBXGroup;
275273
children = (
274+
2D5C3F38230CFBC2008EF2DC /* LICENSE */,
276275
2D92DDBE2301279E00A96858 /* Metadata.swift */,
277276
2D92DDBF2301279E00A96858 /* Property.swift */,
278277
2D92DDC02301279E00A96858 /* Layout */,
@@ -452,7 +451,6 @@
452451
2D92DDFB2301279E00A96858 /* StructType.swift in Sources */,
453452
2D92DDEB2301279E00A96858 /* Property.swift in Sources */,
454453
2D92DDE92301279E00A96858 /* JSONSerialization+KK.swift in Sources */,
455-
2D7B8DE2230825D000DEC901 /* Set+KK.swift in Sources */,
456454
2D92DDF52301279E00A96858 /* TupleType.swift in Sources */,
457455
2D92DE032301279E00A96858 /* Descriptor.swift in Sources */,
458456
2D92DDDE2301279E00A96858 /* Logger.swift in Sources */,

KakaJSON/Extension/Array+KK.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ extension Set: KKCompatible {}
1414
extension NSSet: KKCompatible {}
1515

1616
public extension KK where Base: ExpressibleByArrayLiteral & Sequence {
17-
// MARK: - JSON -> Model
17+
/// JSONObjectArray -> ModelArray
1818
func modelArray<M: Convertible>(_ type: M.Type) -> [M]? {
1919
return modelArray(anyType: type) as? [M]
2020
}
2121

22+
/// JSONObjectArray -> ModelArray
2223
func modelArray(anyType: Any.Type) -> [Any]? {
2324
guard let t = anyType as? Convertible.Type,
2425
let mt = Metadata.type(anyType) as? ModelType,
@@ -35,18 +36,20 @@ public extension KK where Base: ExpressibleByArrayLiteral & Sequence {
3536
return arr.isEmpty ? nil : arr
3637
}
3738

38-
// MARK: - Model -> JSON
39-
func JSONArray() -> [Any]? {
40-
return base~?.kk_JSON() as? [Any]
41-
}
42-
39+
/// ModelArray -> JSONObjectArray
4340
func JSONObjectArray() -> [[String: Any]]? {
4441
let arr = base.compactMap { element -> [String: Any]? in
4542
(element~! as? Convertible)?.kk_JSONObject()
4643
}
4744
return arr.isEmpty ? nil : arr
4845
}
4946

47+
/// Array -> JSONArray
48+
func JSONArray() -> [Any]? {
49+
return base~?.kk_JSON() as? [Any]
50+
}
51+
52+
/// Array -> JSONArray
5053
func JSONString(prettyPrinted: Bool = false) -> String? {
5154
if let str = JSONSerialization.kk_string(JSONArray(),
5255
prettyPrinted: prettyPrinted) {

KakaJSON/Extension/Data+KK.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ extension Data: KKCompatible {}
1212
extension NSData: KKCompatible {}
1313

1414
public extension KK where Base == Data {
15-
// MARK: - JSON -> Model
15+
/// JSONObject -> Model
1616
func model<M: Convertible>(_ type: M.Type) -> M? {
1717
return model(anyType: type) as? M
1818
}
1919

20+
/// JSONObject -> Model
2021
func model(anyType: Any.Type) -> Any? {
2122
if let json = JSONSerialization.kk_JSON(base, [String: Any].self) {
2223
return json.kk.model(anyType: anyType)
@@ -25,10 +26,12 @@ public extension KK where Base == Data {
2526
return nil
2627
}
2728

29+
/// JSONObjectArray -> ModelArray
2830
func modelArray<M: Convertible>(_ type: M.Type) -> [M]? {
2931
return modelArray(anyType: type) as? [M]
3032
}
3133

34+
/// JSONObjectArray -> ModelArray
3235
func modelArray(anyType: Any.Type) -> [Any]? {
3336
if let json = JSONSerialization.kk_JSON(base, [Any].self) {
3437
return json.kk.modelArray(anyType: anyType)
@@ -39,19 +42,22 @@ public extension KK where Base == Data {
3942
}
4043

4144
public extension KK where Base: NSData {
42-
// MARK: - JSON -> Model
45+
/// JSONObject -> Model
4346
func model<M: Convertible>(_ type: M.Type) -> M? {
4447
return model(anyType: type) as? M
4548
}
4649

50+
/// JSONObject -> Model
4751
func model(anyType: Any.Type) -> Any? {
4852
return (base as Data).kk.model(anyType: anyType)
4953
}
5054

55+
/// JSONObjectArray -> ModelArray
5156
func modelArray<M: Convertible>(_ type: M.Type) -> [M]? {
5257
return modelArray(anyType: type) as? [M]
5358
}
5459

60+
/// JSONObjectArray -> ModelArray
5561
func modelArray(anyType: Any.Type) -> [Any]? {
5662
return (base as Data).kk.modelArray(anyType: anyType)
5763
}

KakaJSON/Extension/Dictionary+KK.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ extension Dictionary: KKGenericCompatible {
1414
}
1515

1616
public extension KKGeneric where Base == [String: T] {
17-
// MARK: JSON -> Model
17+
/// JSONObject -> Model
1818
func model<M: Convertible>(_ type: M.Type) -> M? {
1919
return model(anyType: type) as? M
2020
}
2121

22+
/// JSONObject -> Model
2223
func model(anyType: Any.Type) -> Any? {
2324
guard let t = anyType as? Convertible.Type,
2425
let mt = Metadata.type(anyType) as? ModelType,
@@ -29,21 +30,24 @@ public extension KKGeneric where Base == [String: T] {
2930
}
3031

3132
public extension KKGeneric where Base == [NSString: T] {
32-
// MARK: JSON -> Model
33+
/// JSONObject -> Model
3334
func model<M: Convertible>(_ type: M.Type) -> M? {
3435
return model(anyType: type) as? M
3536
}
3637

38+
/// JSONObject -> Model
3739
func model(anyType: Any.Type) -> Any? {
3840
return (base as [String: Any]).kk.model(anyType: anyType)
3941
}
4042
}
4143

4244
public extension KK where Base: NSDictionary {
45+
/// JSONObject -> Model
4346
func model<M: Convertible>(_ type: M.Type) -> M? {
4447
return (base as? [String: Any])?.kk.model(type)
4548
}
4649

50+
/// JSONObject -> Model
4751
func model(anyType: Any.Type) -> Any? {
4852
return (base as? [String: Any])?.kk.model(anyType: anyType)
4953
}

KakaJSON/Extension/Optional+KK.swift

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,78 +31,97 @@ extension Optional: KKGenericCompatible {
3131
}
3232

3333
public extension KKGeneric where Base == Optional<T> {
34+
/// get the most inner value
3435
var value: Any? { return base.kk_value }
3536

37+
/// convert value to String
3638
var string: String? {
3739
return base.kk_value(String.self) as? String
3840
}
3941

42+
/// convert value to Bool
4043
var bool: Bool? {
4144
return base.kk_value(Bool.self) as? Bool
4245
}
4346

47+
/// convert value to Int
4448
var int: Int? {
4549
return base.kk_value(Int.self) as? Int
4650
}
4751

52+
/// convert value to Int8
4853
var int8: Int8? {
4954
return base.kk_value(Int8.self) as? Int8
5055
}
5156

57+
/// convert value to Int16
5258
var int16: Int16? {
5359
return base.kk_value(Int16.self) as? Int16
5460
}
5561

62+
/// convert value to Int32
5663
var int32: Int32? {
5764
return base.kk_value(Int32.self) as? Int32
5865
}
5966

67+
/// convert value to Int64
6068
var int64: Int64? {
6169
return base.kk_value(Int64.self) as? Int64
6270
}
6371

72+
/// convert value to UInt
6473
var uInt: UInt? {
6574
return base.kk_value(UInt.self) as? UInt
6675
}
6776

77+
/// convert value to UInt8
6878
var uInt8: UInt8? {
6979
return base.kk_value(UInt8.self) as? UInt8
7080
}
7181

82+
/// convert value to UInt16
7283
var uInt16: UInt16? {
7384
return base.kk_value(UInt16.self) as? UInt16
7485
}
7586

87+
/// convert value to UInt32
7688
var uInt32: UInt32? {
7789
return base.kk_value(UInt32.self) as? UInt32
7890
}
7991

92+
/// convert value to UInt64
8093
var uInt64: UInt64? {
8194
return base.kk_value(UInt64.self) as? UInt64
8295
}
8396

97+
/// convert value to Float
8498
var float: Float? {
8599
return base.kk_value(Float.self) as? Float
86100
}
87101

102+
/// convert value to Double
88103
var double: Double? {
89104
return base.kk_value(Double.self) as? Double
90105
}
91106

92107
#if canImport(CoreGraphics)
108+
/// convert value to CGFloat
93109
var cgFloat: CGFloat? {
94110
return base.kk_value(CGFloat.self) as? CGFloat
95111
}
96112
#endif
97113

114+
/// convert value to Decimal
98115
var decimal: Decimal? {
99116
return base.kk_value(Decimal.self) as? Decimal
100117
}
101118

119+
/// convert value to NSNumber
102120
var number: NSNumber? {
103121
return base.kk_value(NSNumber.self) as? NSNumber
104122
}
105123

124+
/// convert value to NSDecimalNumber
106125
var decimalNumber: NSDecimalNumber? {
107126
return base.kk_value(NSDecimalNumber.self) as? NSDecimalNumber
108127
}
@@ -281,16 +300,12 @@ private extension Optional {
281300
}
282301

283302
func _JSON(from array: [Any]) -> Any? {
284-
let newArray = array.compactMap {
285-
$0~?.kk_JSON()
286-
}
303+
let newArray = array.compactMap { $0~?.kk_JSON() }
287304
return newArray.isEmpty ? nil : newArray
288305
}
289306

290307
func _JSON(from dict: [String: Any]) -> Any? {
291-
let newDict = dict.compactMapValues {
292-
$0~?.kk_JSON()
293-
}
308+
let newDict = dict.compactMapValues { $0~?.kk_JSON() }
294309
return newDict.isEmpty ? nil : newDict
295310
}
296311

@@ -325,34 +340,18 @@ protocol SwiftArrayValue: ArrayValue {}
325340
extension Array: SwiftArrayValue {}
326341

327342
protocol SetValue: CollectionValue {
328-
// func kk_map<T>(_ transform: (Any) throws -> T) rethrows -> [T]
329-
// func kk_compactMap<T>(_ transform: (Any) throws -> T?) rethrows -> [T]
330343
func kk_array() -> [Any]
331344
}
332-
extension NSSet: SetValue {
333-
// func kk_map<T>(_ transform: (Any) throws -> T) rethrows -> [T] {
334-
// return map { try! transform($0) }
335-
// }
336-
// func kk_compactMap<T>(_ transform: (Any) throws -> T?) rethrows -> [T] {
337-
// return compactMap { try! transform($0) }
338-
// }
339-
func kk_array() -> [Any] {
340-
return [Any](self)
341-
}
342-
}
343-
protocol SwiftSetValue: SetValue {}
344-
extension Set: SwiftSetValue {
345-
// func kk_map<T>(_ transform: (Any) throws -> T) rethrows -> [T] {
346-
// return map { try! transform($0) }
347-
// }
348-
// func kk_compactMap<T>(_ transform: (Any) throws -> T?) rethrows -> [T] {
349-
// return compactMap { try! transform($0) }
350-
// }
345+
extension SetValue where Self: Sequence {
351346
func kk_array() -> [Any] {
352347
return map { $0 }
353348
}
354349
}
355350

351+
extension NSSet: SetValue {}
352+
protocol SwiftSetValue: SetValue {}
353+
extension Set: SwiftSetValue {}
354+
356355
protocol StringValue {}
357356
extension String: StringValue {}
358357
extension NSString: StringValue {}

KakaJSON/Extension/Set+KK.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

KakaJSON/Extension/String+KK.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ public extension KK where Base: ExpressibleByStringLiteral {
5252
return newStr
5353
}
5454

55-
// MARK: - JSON -> Model
55+
/// JSONObject -> Model
5656
func model<M: Convertible>(_ type: M.Type) -> M? {
5757
return model(anyType: type) as? M
5858
}
5959

60+
/// JSONObject -> Model
6061
func model(anyType: Any.Type) -> Any? {
6162
if let json = JSONSerialization.kk_JSON(base as? String, [String: Any].self) {
6263
return json.kk.model(anyType: anyType)
@@ -65,10 +66,12 @@ public extension KK where Base: ExpressibleByStringLiteral {
6566
return nil
6667
}
6768

69+
/// JSONObjectArray -> ModelArray
6870
func modelArray<M: Convertible>(_ type: M.Type) -> [M]? {
6971
return modelArray(anyType: type) as? [M]
7072
}
7173

74+
/// JSONObjectArray -> ModelArray
7275
func modelArray(anyType: Any.Type) -> [Any]? {
7376
if let json = JSONSerialization.kk_JSON(base as? String, [Any].self) {
7477
return json.kk.modelArray(anyType: anyType)

0 commit comments

Comments
 (0)