Skip to content

Commit c5a9ca9

Browse files
authored
Merge pull request #281 from zapcannon87/developer
feat(storage): convenience init of LCArray from LCArray
2 parents 168331e + 50fd1c6 commit c5a9ca9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

LeanCloudTests/LCTypeTestCase.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ class LCTypeTestCase: BaseTestCase {
5656
XCTAssertEqual(convert("foo") as? LCString, "foo")
5757
XCTAssertEqual(convert(NSString(string: "foo")) as? LCString, "foo")
5858
}
59+
60+
func testArrayInit() {
61+
let array1 = LCArray([42])
62+
let array2 = LCArray(array1)
63+
XCTAssertFalse(array1 === array2)
64+
XCTAssertEqual(array1.value.count, array2.value.count)
65+
XCTAssertEqual(array1.value.first as? LCNumber, array2.value.first as? LCNumber)
66+
}
5967

6068
func testArrayConvertible() {
6169
let date = Date()

Sources/Foundation/Array.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public class LCArray: NSObject, LCValue, Collection, ExpressibleByArrayLiteral {
2828
self.init()
2929
self.value = value.map { $0.lcValue }
3030
}
31+
32+
public convenience init(_ array: LCArray) {
33+
self.init()
34+
self.value = array.value
35+
}
3136

3237
public convenience required init(arrayLiteral elements: LCValueConvertible...) {
3338
self.init(elements)

0 commit comments

Comments
 (0)