Skip to content

Commit 2eabf88

Browse files
committed
1.2.0
1 parent 23b9e12 commit 2eabf88

32 files changed

+1513
-2319
lines changed

Source/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Find the result in `ios-framework/ObjectBox-iOS-Aggregate.build/`
7575

7676
This is essentially what comes for free with Carthage. Xcode 10 changed the build system a bit. The build script is adjusted accordingly. But you may have to adjust the script a bit for future Xcode versions; that's another point of failure you wouldn't have to worry about with Carthage.
7777

78-
iOS Framework Project Organization
79-
----------------------------------
78+
Swift Framework Project Organization
79+
------------------------------------
8080

8181
You look at and build the framework itself via `ios-framework/ObjectBox.xcodeproj`.
8282

Source/download_dependencies.command

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ fi
2424

2525
# Nothing to build, so download instead
2626
if [ ! -d "${dest_dir}" ] || [ ! -e "${dest_dir}/libObjectBoxCore-iOS.a" ]; then
27-
version=1.1
28-
core_version=0.7.2
27+
version=1.2.0
28+
core_version=0.8.1
2929
archive_path="${my_dir}/external/objectbox-static.zip"
3030
OBXLIB_URL_apple_static="https://github.com/objectbox/objectbox-swift/releases/download/v${version}/ObjectBoxCore-static-${core_version}.zip"
3131

Source/ios-framework/CodeGenTests/ToolTestProject33.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main(_ args: [String]) throws -> Int32 {
4949
}
5050

5151
for entity in records {
52-
let results = try box.query({ DataThing.firstData == entity.firstData }).build().all()
52+
let results = try box.query({ DataThing.firstData == entity.firstData }).build().find()
5353
if results.count != 1 {
5454
print("error: Expected one \(entity), \(results.count) found")
5555
return 1

Source/ios-framework/CodeGenTests/ToolTestProject42.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func main(_ args: [String]) throws -> Int32 {
107107
print("note: Testing forward:")
108108
// Could do this without a relation by just looking for the book by name & asking for its authors,
109109
// but we're testing queries over relations here, so do it the complicated way:
110-
let tinyPrettyThingsAuthors = try authorBox.query().link(Author.books) { Book.name == tinyPrettyThings.name }.build().all()
110+
let tinyPrettyThingsAuthors = try authorBox.query().link(Author.books) { Book.name == tinyPrettyThings.name }.build().find()
111111
if tinyPrettyThingsAuthors.count != 2 {
112112
print("error: Author count wrong. Expected 2, found \(tinyPrettyThingsAuthors.count)")
113113
return 1
@@ -122,7 +122,7 @@ func main(_ args: [String]) throws -> Int32 {
122122
}
123123

124124
print("note: Testing backlink:")
125-
let sonasBooks = try bookBox.query().link(Book.authors) { Author.name == sona.name }.build().all()
125+
let sonasBooks = try bookBox.query().link(Book.authors) { Author.name == sona.name }.build().find()
126126
if sonasBooks.count != 2 {
127127
print("error: Book count wrong. Expected 2, found \(sonasBooks.count)")
128128
return 1

Source/ios-framework/CodeGenTests/ToolTestProject43.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func main(_ args: [String]) throws -> Int32 {
7878
try amanda.books.applyToDb()
7979

8080
print("note: Testing forward:")
81-
let dhoniellesBooks = try bookBox.query().link(Book.author) { Author.name == dhonielle.name }.build().all()
81+
let dhoniellesBooks = try bookBox.query().link(Book.author) { Author.name == dhonielle.name }.build().find()
8282
if dhoniellesBooks.count != 2 {
8383
print("error: Book count wrong. Expected 2, found \(dhoniellesBooks.count)")
8484
return 1
@@ -95,7 +95,7 @@ func main(_ args: [String]) throws -> Int32 {
9595
print("note: Testing backlink:")
9696
let bellesAskingAuthors = try authorBox.query().link(Author.books) {
9797
Book.name == theBelles.name || Book.name == theArtOfAsking.name
98-
}.build().all()
98+
}.build().find()
9999
if bellesAskingAuthors.count != 2 {
100100
print("error: Author count wrong. Expected 2, found \(bellesAskingAuthors.count)")
101101
return 1

Source/ios-framework/CodeGenTests/ToolTestProject49.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func main(_ args: [String]) throws -> Int32 {
107107
print("note: Testing forward:")
108108
// Could do this without a relation by just looking for the book by name & asking for its authors,
109109
// but we're testing queries over relations here, so do it the complicated way:
110-
let tinyPrettyThingsAuthors = try authorBox.query().link(Author.books) { Book.name == tinyPrettyThings.name }.build().all()
110+
let tinyPrettyThingsAuthors = try authorBox.query().link(Author.books) { Book.name == tinyPrettyThings.name }.build().find()
111111
if tinyPrettyThingsAuthors.count != 2 {
112112
print("error: Author count wrong. Expected 2, found \(tinyPrettyThingsAuthors.count)")
113113
return 1
@@ -122,7 +122,7 @@ func main(_ args: [String]) throws -> Int32 {
122122
}
123123

124124
print("note: Testing backlink:")
125-
let sonasBooks = try bookBox.query().link(Book.authors) { Author.name == sona.name }.build().all()
125+
let sonasBooks = try bookBox.query().link(Book.authors) { Author.name == sona.name }.build().find()
126126
if sonasBooks.count != 2 {
127127
print("error: Book count wrong. Expected 2, found \(sonasBooks.count)")
128128
return 1

Source/ios-framework/CodeGenTests/ToolTestProject50.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func main(_ args: [String]) throws -> Int32 {
8080
try bookBox.put(allBooks) // We edited the authors, but the books contain the ToOne that needs persisting.
8181

8282
print("note: Testing forward:")
83-
let dhoniellesBooks = try bookBox.query().link(Book.author) { Author.name == dhonielle.name }.build().all()
83+
let dhoniellesBooks = try bookBox.query().link(Book.author) { Author.name == dhonielle.name }.build().find()
8484
if dhoniellesBooks.count != 2 {
8585
throw TestErrors.testFailed(message: "Book count wrong. Expected 2, found \(dhoniellesBooks.count)")
8686
}
@@ -94,7 +94,7 @@ func main(_ args: [String]) throws -> Int32 {
9494
print("note: Testing backlink:")
9595
let bellesAskingAuthors = try authorBox.query().link(Author.books) {
9696
Book.name == theBelles.name || Book.name == theArtOfAsking.name
97-
}.build().all()
97+
}.build().find()
9898
if bellesAskingAuthors.count != 2 {
9999
throw TestErrors.testFailed(message: "Author count wrong. Expected 2, found \(bellesAskingAuthors.count)")
100100
}

Source/ios-framework/CodeGenTests/ToolTestProject57.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func main(_ args: [String]) throws -> Int32 {
4646
try busBox.put(testRoute)
4747
try busBox.put(testRoute2)
4848

49-
let results = try busBox.query { BusRoute.driverName.isNil() }.build().all()
49+
let results = try busBox.query { BusRoute.driverName.isNil() }.build().find()
5050
if results.count != 1 {
5151
throw TestErrors.testFailed(message: "Expected 1 result, found \(results.count)")
5252
}

Source/ios-framework/CommonSource/Box.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ extension Box {
462462
}
463463

464464
/// :nodoc:
465-
@available(*, deprecated, message: "Use all() instead.")
465+
@available(*, deprecated, renamed: "all")
466466
public func find() throws -> [EntityType] {
467467
return try all()
468468
}

Source/ios-framework/CommonSource/Entities/EntityPropertyTypeImplementations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// limitations under the License.
1515
//
1616

17+
// TODO: check if those still make sense like this; e.g. check property queries
18+
1719
/// Marks all supported scalar value types as such.
1820
/// Used to provide 1 interface for e.g. `distinct`.
1921
public protocol EntityScalarPropertyType {}

Source/ios-framework/CommonSource/Entities/Property.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ where E == E.EntityBindingType.EntityType {
5151
/// The internal ID of the property, in terms of the database schema.
5252
public var propertyId: UInt32 { return base.propertyId }
5353
}
54+
55+
/// Property represents a "value" and not a relation; TODO Decide if useful (one generic parameter less) or drop it
56+
public typealias ValueProperty<E: EntityInspectable & __EntityRelatable, V: EntityPropertyTypeConvertible> =
57+
Property<E, V, Void> where E == E.EntityBindingType.EntityType

Source/ios-framework/CommonSource/Errors.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,31 @@ internal func checkLastError() throws {
111111
internal func checkLastError(_ error: obx_err) throws {
112112
if error == OBX_SUCCESS { return }
113113
let message = String(utf8String: obx_last_error_message()) ?? ""
114+
if error != OBX_NOT_FOUND {
115+
// In case the error is not catched, info might be lost; so better print it now(?), or is there a better way?
116+
print("Error occurred: \(message) (\(error))")
117+
}
114118
obx_last_error_clear()
115119
try throwObxErr(error, message: message)
116120
}
117121

122+
/// Reserved for "wrong usages" by the user that the compiler cannot detect (try/catch otherwise).
118123
internal func failFatallyIfError() {
119-
let error = obx_last_error_code()
120-
if error == OBX_SUCCESS { return }
121-
let message = String(utf8String: obx_last_error_message()) ?? ""
122-
obx_last_error_clear()
123-
do {
124-
try throwObxErr(error, message: message)
125-
} catch {
126-
fatalError("Unexpected error \(error)")
124+
checkFatalError(obx_last_error_code())
125+
}
126+
127+
/// Reserved for "wrong usages" by the user that the compiler cannot detect (try/catch otherwise).
128+
internal func checkFatalError(_ err: obx_err) {
129+
if err != OBX_SUCCESS {
130+
for symbol in Thread.callStackSymbols {
131+
// Print the stack trace without the "unexciting" symbols
132+
if !symbol.contains("XCTest") && !symbol.contains("xctest") && !symbol.contains("CoreFoundation")
133+
&& !symbol.contains("checkFatalError") && !symbol.contains("failFatallyIfError") {
134+
print(symbol)
135+
}
136+
}
137+
let message = String(utf8String: obx_last_error_message()) ?? "Unknown"
138+
fatalError("\(message) (\(err))")
127139
}
128140
}
129141

Source/ios-framework/CommonSource/FlatBufferBuilder.swift

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public class FlatBufferBuilder {
7575
}
7676
}
7777

78+
// MARK: collect
79+
7880
public extension FlatBufferBuilder {
7981
/// Take a value read from the given entity and write it to the given property.
8082
func collect(_ value: Bool, at propertyOffset: UInt16) {
@@ -177,3 +179,113 @@ public extension FlatBufferBuilder {
177179
}
178180
}
179181
}
182+
183+
// MARK: collect optionals
184+
185+
// Adapter methods for writing optionals and relations to a FlatBufferBuilder
186+
// Null values are simply not collected
187+
public extension FlatBufferBuilder {
188+
/// :nodoc:
189+
func collect(_ value: Int?, at propertyOffset: UInt16) {
190+
guard let value = value else { return }
191+
self.collect(value, at: propertyOffset)
192+
}
193+
194+
/// :nodoc:
195+
func collect(_ value: Int64?, at propertyOffset: UInt16) {
196+
guard let value = value else { return }
197+
self.collect(value, at: propertyOffset)
198+
}
199+
200+
/// :nodoc:
201+
func collect(_ value: Int32?, at propertyOffset: UInt16) {
202+
guard let value = value else { return }
203+
self.collect(value, at: propertyOffset)
204+
}
205+
206+
/// :nodoc:
207+
func collect(_ value: Int16?, at propertyOffset: UInt16) {
208+
guard let value = value else { return }
209+
self.collect(value, at: propertyOffset)
210+
}
211+
212+
/// :nodoc:
213+
func collect(_ value: Int8?, at propertyOffset: UInt16) {
214+
guard let value = value else { return }
215+
self.collect(value, at: propertyOffset)
216+
}
217+
218+
/// :nodoc:
219+
func collect(_ value: UInt?, at propertyOffset: UInt16) {
220+
guard let value = value else { return }
221+
self.collect(value, at: propertyOffset)
222+
}
223+
224+
/// :nodoc:
225+
func collect(_ value: UInt64?, at propertyOffset: UInt16) {
226+
guard let value = value else { return }
227+
self.collect(value, at: propertyOffset)
228+
}
229+
230+
/// :nodoc:
231+
func collect(_ value: UInt32?, at propertyOffset: UInt16) {
232+
guard let value = value else { return }
233+
self.collect(value, at: propertyOffset)
234+
}
235+
236+
/// :nodoc:
237+
func collect(_ value: UInt16?, at propertyOffset: UInt16) {
238+
guard let value = value else { return }
239+
self.collect(value, at: propertyOffset)
240+
}
241+
242+
/// :nodoc:
243+
func collect(_ value: UInt8?, at propertyOffset: UInt16) {
244+
guard let value = value else { return }
245+
self.collect(value, at: propertyOffset)
246+
}
247+
248+
/// :nodoc:
249+
func collect(_ value: Bool?, at propertyOffset: UInt16) {
250+
guard let value = value else { return }
251+
self.collect(value, at: propertyOffset)
252+
}
253+
254+
/// :nodoc:
255+
func collect(_ value: Float?, at propertyOffset: UInt16) {
256+
guard let value = value else { return }
257+
self.collect(value, at: propertyOffset)
258+
}
259+
260+
/// :nodoc:
261+
func collect(_ value: Double?, at propertyOffset: UInt16) {
262+
guard let value = value else { return }
263+
self.collect(value, at: propertyOffset)
264+
}
265+
266+
/// :nodoc:
267+
func collect(_ value: String?, at propertyOffset: UInt16) {
268+
guard let value = value else { return }
269+
self.collect(value, at: propertyOffset)
270+
}
271+
272+
/// :nodoc:
273+
func collect<T>(_ value: EntityId<T>?, at propertyOffset: UInt16) {
274+
guard let value = value else { return }
275+
self.collect(value.value, at: propertyOffset)
276+
}
277+
278+
/// :nodoc:
279+
func collect<E: EntityInspectable & __EntityRelatable>(_ relation: ToOne<E>, at propertyOffset: UInt16,
280+
store: Store)
281+
where E == E.EntityBindingType.EntityType {
282+
guard relation.hasValue else { return }
283+
let relatedBox = store.box(for: type(of: relation).Target.self)
284+
do {
285+
guard let targetId = try relatedBox.put(relation) else { return }
286+
self.collect(targetId.value, at: propertyOffset)
287+
} catch {
288+
objc_exception_throw(error)
289+
}
290+
}
291+
}

Source/ios-framework/CommonSource/Observer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ extension Query {
260260
let result: ContiguousArray<EntityType>
261261
var resultError: ObjectBoxError?
262262
do {
263-
result = try self.allContiguous()
263+
result = try self.findContiguous()
264264
} catch let error as ObjectBoxError {
265265
resultError = error
266266
result = []

0 commit comments

Comments
 (0)