Skip to content

Commit 72e710e

Browse files
authored
Merge pull request #288 from zapcannon87/developer
feat(storage): all LCValue can init from self
2 parents aa4db7d + 38fc1ee commit 72e710e

File tree

7 files changed

+44
-4
lines changed

7 files changed

+44
-4
lines changed

LeanCloudTests/LCTypeTestCase.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class LCTypeTestCase: BaseTestCase {
3232
func testBoolConvertible() {
3333
XCTAssertEqual(convert(true) as? LCBool, true)
3434
XCTAssertEqual(LCBool(true).boolValue, true)
35+
XCTAssertFalse(LCBool(LCBool()).value)
3536
}
3637

3738
func testIntegerConvertible() {
@@ -50,11 +51,13 @@ class LCTypeTestCase: BaseTestCase {
5051
func testFloatConvertible() {
5152
XCTAssertEqual(convert(Float(42)) as? LCNumber, 42)
5253
XCTAssertEqual(convert(Double(42)) as? LCNumber, 42)
54+
XCTAssertEqual(LCNumber(), LCNumber(LCNumber()))
5355
}
5456

5557
func testStringConvertible() {
5658
XCTAssertEqual(convert("foo") as? LCString, "foo")
5759
XCTAssertEqual(convert(NSString(string: "foo")) as? LCString, "foo")
60+
XCTAssertEqual(LCString(), LCString(LCString()))
5861
}
5962

6063
func testArrayInit() {
@@ -102,11 +105,17 @@ class LCTypeTestCase: BaseTestCase {
102105
func testDataConvertible() {
103106
let data = Data()
104107
XCTAssertEqual(convert(data) as? LCData, LCData(data))
108+
XCTAssertTrue(LCData(LCData()).value.isEmpty)
105109
}
106110

107111
func testDateConvertible() {
108112
let date = Date()
109113
XCTAssertEqual(convert(date) as? LCDate, LCDate(date))
114+
XCTAssertEqual(LCDate(date), LCDate(LCDate(date)))
115+
}
116+
117+
func testGeoPoint() {
118+
XCTAssertEqual(LCGeoPoint(), LCGeoPoint(LCGeoPoint()))
110119
}
111120

112121
func archiveThenUnarchive<T>(_ object: T) -> T {

Sources/Foundation/Bool.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public final class LCBool: NSObject, LCValue, LCValueExtension, ExpressibleByBoo
2424
self.init()
2525
self.value = value
2626
}
27+
28+
public convenience init(_ bool: LCBool) {
29+
self.init()
30+
self.value = bool.value
31+
}
2732

2833
public convenience required init(booleanLiteral value: BooleanLiteralType) {
2934
self.init(value)

Sources/Foundation/Data.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ public final class LCData: NSObject, LCValue, LCValueExtension {
2828
super.init()
2929
}
3030

31-
public convenience init(_ data: Data) {
31+
public convenience init(_ value: Data) {
3232
self.init()
33-
value = data
33+
self.value = value
34+
}
35+
36+
public convenience init(_ data: LCData) {
37+
self.init()
38+
self.value = data.value
3439
}
3540

3641
init?(base64EncodedString: String) {

Sources/Foundation/Date.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ public final class LCDate: NSObject, LCValue, LCValueExtension {
3939
super.init()
4040
}
4141

42-
public convenience init(_ date: Date) {
42+
public convenience init(_ value: Date) {
4343
self.init()
44-
value = date
44+
self.value = value
45+
}
46+
47+
public convenience init(_ date: LCDate) {
48+
self.init()
49+
self.value = date.value
4550
}
4651

4752
init?(isoString: String) {

Sources/Foundation/GeoPoint.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public final class LCGeoPoint: NSObject, LCValue, LCValueExtension {
4242
self.latitude = latitude
4343
self.longitude = longitude
4444
}
45+
46+
public convenience init(_ geoPoint: LCGeoPoint) {
47+
self.init()
48+
self.latitude = geoPoint.latitude
49+
self.longitude = geoPoint.longitude
50+
}
4551

4652
init?(dictionary: [String: Any]) {
4753
guard let type = dictionary["__type"] as? String else {

Sources/Foundation/Number.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public final class LCNumber: NSObject, LCValue, LCValueExtension, ExpressibleByF
2424
self.init()
2525
self.value = value
2626
}
27+
28+
public convenience init(_ number: LCNumber) {
29+
self.init()
30+
self.value = number.value
31+
}
2732

2833
public convenience required init(floatLiteral value: FloatLiteralType) {
2934
self.init(value)

Sources/Foundation/String.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public final class LCString: NSObject, LCValue, LCValueExtension, ExpressibleByS
2727
self.init()
2828
self.value = value
2929
}
30+
31+
public convenience init(_ string: LCString) {
32+
self.init()
33+
self.value = string.value
34+
}
3035

3136
public convenience required init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
3237
self.init(String(value))

0 commit comments

Comments
 (0)