Skip to content

Commit b6acb0a

Browse files
committed
Change subscript
1 parent 2cb5c01 commit b6acb0a

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

Ballcap/DataRepresentable.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,15 @@ public extension DataRepresentable where Self: Object {
111111
}
112112
}
113113

114-
subscript<T: Any>(keyPath: WritableKeyPath<Model, T>) -> T? {
114+
subscript<T: Any>(keyPath: WritableKeyPath<Model, T>) -> T {
115115
get {
116-
return self.data?[keyPath: keyPath]
116+
guard let data = self.data else {
117+
fatalError("[Ballcap: DataRepresentable] This object has not data.")
118+
}
119+
return data[keyPath: keyPath]
117120
}
118121
set {
119-
self.data?[keyPath: keyPath] = newValue!
122+
self.data![keyPath: keyPath] = newValue
120123
}
121124
}
122125

BallcapTests/CodableDocumentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class CodableDocumentTests: XCTestCase {
311311
var ref: DocumentReference = Firestore.firestore().document("a/a")
312312
}
313313
let document: Document<Model> = Document()
314-
XCTAssertEqual(document[\.ref]?.path, "a/a")
314+
XCTAssertEqual(document[\.ref].path, "a/a")
315315
}
316316

317317
func testDocumentSubScriptRefWrite() {

BallcapTests/ObjectTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class ObjectTests: XCTestCase {
8989
}
9090
let o: Obj = Obj(id: "a")
9191
XCTAssertEqual(o[\.path], "a")
92+
o[\.path] = "b"
93+
XCTAssertEqual(o[\.path], "b")
9294
}
9395

9496
func testObjectSaveUpdateDelete() {

icon.sketch

325 KB
Binary file not shown.

0 commit comments

Comments
 (0)