ObjectBox Swift - persisting your Swift objects superfast and simple

Overview

ObjectBox Swift

Version Platform

ObjectBox is a superfast, light-weight object persistence framework. This Swift API seamlessly persists objects on-device for iOS and macOS.

let santa = Person(firstName: "Santa", lastName: "Claus")
try personBox.put(santa)

let query: Query<Person> = personBox.query {
    return (Person.firstName.contains("Santa") || Person.age > 100)
           && Person.lastName.isEqual(to: "Claus") 
}.build()
let oldClauses = query.find()

Want details? Read the guides or check out the API docs.

Adding ObjectBox to your project

CocoaPods is recommended to set up ObjectBox in your project. See the installation docs for alternative setups, or the New to CocoaPods? section below for a quick intro. To install the ObjectBox pod, add the following line to your Podfile:

  pod 'ObjectBox'

Then run this to install the ObjectBox framework:

cd /path/to/your/project/folder/ # whatever folder your Podfile is in.
pod install
Pods/ObjectBox/setup.rb myproject.xcodeproj # whatever your Xcode project is named

And, don't forget to close the Xcode project (.xcodeproj) and open the workspace (.xcworkspace) instead. Now, you are all set to define your first ObjectBox entities; e.g. check the getting started guide or the example described below.

New to CocoaPods?

CocoaPods is a dependency manager and sets up libraries like ObjectBox in your Xcode project. To install it, run this in a terminal:

sudo gem install cocoapods

In CocoaPods, you keep track of used libraries in a file called "Podfile". If you don't have this file yet, navigate to your Xcode project folder and use CocoaPods to create one:

pod init

CocoaPods troubleshooting

If pod install fails, try updating CocoaPods first:

gem update xcodeproj && gem update cocoapods && pod repo update

Swift versions

Here's a list of ObjectBox releases, and the Swift versions they were compiled with:

ObjectBox version(s) Swift version
1.5.0 5.3(.2)
1.4.1 5.3
1.3, 1.4.0 5.2
1.2 5.1

This might be relevant, e.g. when using Carthage. For various reasons, we recommend using the latest version.

Example

In the Example directory, you'll find a "Notes" example app demonstrating ObjectBox's Swift API. The example comes with two apps: one for iOS and one for macOS. The iOS example is a full GUI application, whereas the macOS example runs a few operations and then exits.

To setup the example, use CocoaPods to acquire the framework:

cd Example/
pod install # if that fails, update CocoaPods (see Installation)
Pods/ObjectBox/setup.rb

This will generate a NotesExample.xcworkspace that you can launch to try out ObjectBox.

How can ObjectBox Help You?

We want ObjectBox to be not only the fastest, but also the most Swift-friendly persistence solution.

To do that, we want your feedback: what do you love? What's amiss? Where do you struggle in everyday app development?

We're looking forward to receiving your comments and requests:

Thank you!

Keep in touch

Sign up here for future updates on ObjectBox Swift.

For general news on ObjectBox, check our blog or follow @ObjectBox_io on Twitter.

Background: code generation

ObjectBox Swift generates code at build time for optimal performance at runtime by avoiding reflection etc. This is automatically done for you and should be transparent. Internally, we use a fork of Sourcery for this.

Source code

Source code for ObjectBox's Swift binding can be found in the Source folder.

Other languages/bindings

ObjectBox is a multi platform database supporting multiple languages:

License

All files in this repository are under the Apache 2 license:

Copyright 2018-2021 ObjectBox Ltd. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Crash on ObjectBox initialization: Duplicate index ID 1 found for property EntityD.group

    Crash on ObjectBox initialization: Duplicate index ID 1 found for property EntityD.group

    Issue Basics

    App crashes when we initialize ObjectBox

    • ObjectBox version (are using the latest version?): 0.5.0
    • Reproducibility: occurs always

    Reproducing the bug

    Description

    I'm initializing the BoxStore on app start during the initialization of the Swinject graph.

    Code

    extension Store {
    	static func createStore() throws -> Store {
    		let directory = try FileManager.default.url(
    			for: .documentDirectory,
    			in: .userDomainMask,
    			appropriateFor: nil,
    			create: true)
    		return try Store(directoryPath: directory.path)
    	}
    }
    

    DBUtils

    class DBUtils {
    	static var sharedInstance = DBUtils()
    	var store : Store!
    	
    	init() {
    		store = try! Store.createStore()
    		
    		store.register(entity: EntityA.self)
    		store.register(entity: EntityB.self)
    		store.register(entity: EntityC.self)
    		store.register(entity: EntityD.self)
    	}
    }
    

    Swinject code

    container.register(Store.self) { _ in
    			DBUtils.sharedInstance.store }.inObjectScope(.container)
    

    Entities

    class EntityA: Entity {
    	var id : Id<EntityA> = 0
    	var name = ""
    	var played = 0
    	var won = 0
    	
    	var group: ToOne<EntityC> = nil
    
    	required init() {
    	}
    }
    
    class EntityB: Entity {
    	var id : Id<EntityB> = 0
    	var name = ""
    	var matches : ToMany<EntityD, EntityB> = nil
    	
    	required init() {
    	}
    }
    
    class EntityC: Entity {
    	var id : Id<EntityC> = 0
    	var name = ""
    	var entitiesA: ToMany<EntityA, EntityC> = nil
    	
    	required init() {
    	}
    }
    
    class EntityD: Entity {
    	var id : Id<EntityD> = 0
        var day : Int?
    	var date: Date?
    	var isPlayed : Bool = false
    	var localPoints: Int?
    	var foreignPoints: Int?
    	
    	var group: ToOne<EntityC> = nil
    	var fase: ToOne<EntityB> = nil
    	var local: ToOne<EntityA> = nil
    	var foreign: ToOne<EntityA> = nil
    	
    	required init() {
    	}
    }
    

    Stacktrace

    Terminating app due to uncaught exception 'Unhandled ObjectBox C++ Exception', reason: 'Duplicate index ID 1 found for property EntityD.group
    *** First throw call stack:
    (
    	0   CoreFoundation                      0x0000000106cbb1e6 __exceptionPreprocess + 294
    	1   libobjc.A.dylib                     0x000000010586b031 objc_exception_throw + 48
    	2   ObjectBox                           0x0000000104d13086 _Z24runWithExceptionHandlingPU15__autoreleasingP7NSErrorU13block_pointerFvvE + 2401
    	3   ObjectBox                           0x0000000104d1384a _Z24runWithExceptionHandlingPU15__autoreleasingP7NSErrorU13block_pointerFvvE + 4389
    	4   MyApp                   0x00000001046c9140 $SSo8OBXStoreC17MyAppE13directoryPath16maxDbSizeInKByte8fileMode0G7ReadersABSS_s6UInt64Vs6UInt32VAKtKcfc + 256
    	5   MyApp                   0x00000001046c8fe7 $SSo8OBXStoreC17MyAppE13directoryPath16maxDbSizeInKByte8fileMode0G7ReadersABSS_s6UInt64Vs6UInt32VAKtKcfC + 87
    	6   MyApp                   0x00000001046ca76b $SSo8OBXStoreC17MyAppE11createStoreAByKFZ + 411
    	7   MyApp                   0x00000001046ca09d $S17MyApp7DBUtilsCACycfc + 173
    	8   MyApp                   0x00000001046c9d10 $S17MyApp7DBUtilsCACycfC + 64
    	9   MyApp                   0x00000001046c9cbc globalinit_33_9CDCCD402CC08FC843F21FD87EBB68C2_func0 + 28
    	10  libdispatch.dylib                   0x000000010b12c848 _dispatch_client_callout + 8
    	11  libdispatch.dylib                   0x000000010b12ddc0 dispatch_once_f + 285
    	12  libswiftCore.dylib                  0x00000001063feea9 swift_once + 25
    	13  MyApp                   0x00000001046c9d94 $S17MyApp7DBUtilsC14sharedInstanceACvau + 36
    	14  MyApp                   0x00000001046c1b7f $S17MyApp16ContainerFactoryCACycfcSo8OBXStoreC8Swinject8Resolver_pcfU_ + 15
    	15  MyApp                   0x00000001046c1c70 $S8Swinject8Resolver_pSo8OBXStoreCIegno_AaB_pADIegnr_TR + 16
    	16  MyApp                   0x00000001046c1cd1 $S8Swinject8Resolver_pSo8OBXStoreCIegno_AaB_pADIegnr_TRTA + 17
    	17  Swinject                            0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
    	18  Swinject                            0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
    	19  Swinject                            0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
    	20  Swinject                            0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
    	21  Swinject                            0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
    	22  Swinject                            0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
    	23  Swinject                            0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
    	24  Swinject                            0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
    	25  Swinject                            0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
    	26  Swinject                            0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
    	27  Swinject                            0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
    	28  Swinject                            0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
    	29  Swinject                            0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
    	30  SwinjectAutoregistration            0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
    	31  SwinjectAutoregistration            0x00000001050f88d8 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq_ctr0_lFxAA8Resolver_pcfU_ + 232
    	32  SwinjectAutoregistration            0x00000001050f8ad2 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq_ctr0_lFxAA8Resolver_pcfU_TA + 50
    	33  Swinject                            0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
    	34  Swinject                            0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
    	35  Swinject                            0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
    	36  Swinject                            0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
    	37  Swinject                            0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
    	38  Swinject                            0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
    	39  Swinject                            0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
    	40  Swinject                            0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
    	41  Swinject                            0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
    	42  Swinject                            0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
    	43  Swinject                            0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
    	44  Swinject                            0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
    	45  Swinject                            0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
    	46  SwinjectAutoregistration            0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
    	47  SwinjectAutoregistration            0x00000001050f9186 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_t_tctr1_lFxAA8Resolver_pcfU_ + 342
    	48  SwinjectAutoregistration            0x00000001050f9535 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_t_tctr1_lFxAA8Resolver_pcfU_TA + 69
    	49  Swinject                            0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
    	50  Swinject                            0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
    	51  Swinject                            0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
    	52  Swinject                            0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
    	53  Swinject                            0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
    	54  Swinject                            0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
    	55  Swinject                            0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
    	56  Swinject                            0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
    	57  Swinject                            0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
    	58  Swinject                            0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
    	59  Swinject                            0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
    	60  Swinject                            0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
    	61  Swinject                            0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
    	62  SwinjectAutoregistration            0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
    	63  SwinjectAutoregistration            0x0000000105100ff0 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_q2_q3_t_tctr4_lFxAA8Resolver_pcfU_ + 688
    	64  SwinjectAutoregistration            0x000000010510192c $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_q2_q3_t_tctr4_lFxAA8Resolver_pcfU_TA + 108
    	65  Swinject                            0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
    	66  Swinject                            0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
    	67  Swinject                            0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
    	68  Swinject                            0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
    	69  Swinject                            0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
    	70  Swinject                            0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
    	71  Swinject                            0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
    	72  Swinject                            0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
    	73  Swinject                            0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
    	74  Swinject                            0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
    	75  Swinject                            0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
    	76  Swinject                            0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
    	77  Swinject                            0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
    	78  SwinjectAutoregistration            0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
    	79  SwinjectAutoregistration            0x00000001050fa9d4 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_t_tctr2_lFxAA8Resolver_pcfU_ + 452
    	80  SwinjectAutoregistration            0x00000001050faf43 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_t_tctr2_lFxAA8Resolver_pcfU_TA + 83
    	81  Swinject                            0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
    	82  Swinject                            0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
    	83  Swinject                            0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
    	84  Swinject                            0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
    	85  Swinject                            0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
    	86  Swinject                            0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
    	87  Swinject                            0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
    	88  Swinject                            0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
    	89  Swinject                            0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
    	90  Swinject                            0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
    	91  Swinject                            0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
    	92  Swinject                            0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
    	93  MyApp                   0x00000001046a081d $S17MyApp11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFyycfU_ + 189
    	94  MyApp                   0x00000001046a0941 $S17MyApp11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFyycfU_TA + 17
    	95  MyApp                   0x00000001046a09ad $SIeg_IeyB_TR + 45
    	96  libdispatch.dylib                   0x000000010b12c848 _dispatch_client_callout + 8
    	97  libdispatch.dylib                   0x000000010b132b35 _dispatch_continuation_pop + 967
    	98  libdispatch.dylib                   0x000000010b13dfa6 _dispatch_source_invoke + 1635
    	99  libdispatch.dylib                   0x000000010b137b9e _dispatch_main_queue_callback_4CF + 1255
    	100 CoreFoundation                      0x0000000106c7dc99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    	101 CoreFoundation                      0x0000000106c41ea6 __CFRunLoopRun + 2342
    	102 CoreFoundation                      0x0000000106c4130b CFRunLoopRunSpecific + 635
    	103 GraphicsServices                    0x000000010d633a73 GSEventRunModal + 62
    	104 UIKit                               0x00000001080f20b7 UIApplicationMain + 159
    	105 MyApp                   0x00000001046a2057 main + 71
    	106 libdyld.dylib                       0x000000010b1a9955 start + 1
    )
    

    I also tried without Swinject with the same results. I got the same classes and relationships on Android and it works.

    opened by JuanFcoMiranda 20
  • build fail: The element XCRemoteSwiftPackageReference is not supported

    build fail: The element XCRemoteSwiftPackageReference is not supported

    I hate CocoaPods, so chose to manual setup.

    image image image image

    The project could compiled successfully until execute "gem install xcodeproj" command. I am using xcode 11 beta9 and Catalina

    opened by zicjin 13
  • Question: Generated Entity Info to include framework models

    Question: Generated Entity Info to include framework models

    This is more of a specific question than an overall issue. I am wondering if there is a way for the generate_sources script to also include models included in a framework, In this case, a cocoapod. I am working on a project that has two apps with an internal pod used within both apps. Both apps shared most of the models so they are included within the core framework.

    Is there a way I can have Sourcery also generate entity info for the models included in a different module?

    opened by BergerBytes 13
  • Preferred C API

    Preferred C API

    You said "let us know what you think", but not sure of the best place to do that. Really looking forward to trying this out, but not sure how or if I should yet.

    Ideally, no Objective-C, and you can just have the C++ version back swift (C++ wrapped in a standard C api). This will allow the library to take full advantage of swift optimizations. Otherwise, it's just using the Objective-C runtime, and is an ergonomic choice.

    opened by drkibitz 13
  • Not support deployment ios 9.0 ?

    Not support deployment ios 9.0 ?

    Why is not available deployment target 9.0 in CocoaPods?

    use_frameworks!

    source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0'

    pod 'ObjectBox'

    run command^

    pod install
    

    error in terminal:

    Analyzing dependencies
    [!] CocoaPods could not find compatible versions for pod "ObjectBox":
      In Podfile:
        ObjectBox
    
    Specs satisfying the `ObjectBox` dependency were found, but they required a higher minimum deployment target.
    

    What is the reason for this? Is it possible to downgrade version? I am developing an application with support for iOS 9.0 ((

    opened by fedorovoleg00 11
  • ObjectBox bitcode support

    ObjectBox bitcode support

    I have an error when trying to compile the project:

    'Pods/ObjectBox/Carthage/Build/iOS/ObjectBox.framework/ObjectBox' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file 'Pods/ObjectBox/Carthage/Build/iOS/ObjectBox.framework/ObjectBox' for architecture arm64

    ObjectBox was added via CocoaPods. The issue is related to 1.0.1 and 1.0 version (I didn't check the previous ones).

    When compiling ObjectBox.framework you need to enable bitcode for your project and all dependencies.

    Can you fix this issue? I would like to use ObjectBox in my future projects, but because of that, I need to disable bitcode in the whole project.

    enhancement 
    opened by KarolMajka 10
  • ConflictStrategy.REPLACE

    ConflictStrategy.REPLACE

    In the android version, together with the Unique annotation, we have the option to define the Overlay strategy @Unique(onConflict = ConflictStrategy.REPLACE). It needs to have this same option for Swift. If it exists, it is not documented, please show us.

    enhancement 
    opened by jonasrotilli 9
  • Demo project not compiling

    Demo project not compiling

    Hi,

    This issue was resolved because the following output was generated.

    Robs-iMac:Example robertnash$ pod install
    Analyzing dependencies
    Downloading dependencies
    Installing ObjectBox (0.5.2)
    Installing Sourcery (0.15.0)
    Generating Pods project
    Integrating client project
    Sending stats
    Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.
    

    However, the project doesn't run.

    screenshot 2018-11-25 at 09 01 13 screenshot 2018-11-25 at 10 26 33
    error: /Users/robertnash/Downloads/objectbox-swift-master/Example/Pods/Pods/Target Support Files/Pods-NotesExample-iOS/Pods-NotesExample-iOS.debug.xcconfig: unable to open file (in target "NotesExample-iOS" in project "NotesExample") (in target 'NotesExample-iOS')
    

    I have performed a clean build and I have purged the Xcode build folder but rebuilding produces the same error.

    Side-note: I don't have a great relationship with the Cocapods team.

    opened by ghost 9
  • Code generation doesn't work

    Code generation doesn't work

    Describe the bug It used to work several months ago when I was using version 1.1 but now the code for the entities won't get generated on build anymore.

    Basic info (please complete the following information):

    • ObjectBox version 1.3.1
    • Reproducibility: always
    • Device: iPhone 11 (simulator)
    • OS: iOS 13

    To Reproduce Steps to reproduce the behavior:

    1. Follow instructions on https://swift.objectbox.io/install
    2. run Pods/ObjectBox/setup.rb and got "🔸 No changes made to project. "
    MacBook-Pro:CoreIOS HaiNguyen$ pod install
    Analyzing dependencies
    Downloading dependencies
    Installing Alamofire (5.0.2)
    Installing ColorThiefSwift (0.4.0)
    Installing Crashlytics (3.14.0)
    Installing Fabric (1.10.2)
    Installing Firebase (6.19.0)
    Installing FirebaseAnalytics (6.3.1)
    Installing FirebaseAuth (6.4.3)
    Installing FirebaseAuthInterop (1.1.0)
    Installing FirebaseCore (6.6.4)
    Installing FirebaseCoreDiagnostics (1.2.2)
    Installing FirebaseCoreDiagnosticsInterop (1.2.0)
    Installing FirebaseDatabase (6.1.4)
    Installing FirebaseInstallations (1.1.0)
    Installing GTMSessionFetcher (1.3.1)
    Installing GoogleAppMeasurement (6.3.1)
    Installing GoogleDataTransport (5.0.0)
    Installing GoogleDataTransportCCTSupport (2.0.0)
    Installing GoogleUtilities (6.5.1)
    Installing ObjectBox (1.3.1)
    Installing PromisesObjC (1.2.8)
    Installing leveldb-library (1.22)
    Installing nanopb (0.3.9011)
    Generating Pods project
    Integrating client project
    Pod installation complete! There are 10 dependencies from the Podfile and 22 total pods installed.
    MacBook-Pro:CoreIOS HaiNguyen$ Pods/ObjectBox/setup.rb
     ObjectBox Project Setup 
    
    🔸 Looking for project files in the current directory ...
    🔸 Found a single project.
    🔸 Using "/Users/HaiNguyen/Documents/githubProject/JournalIt/journal_it/ios/CoreIOS/CoreIOS.xcodeproj"
    
     🔸 No changes made to project. 
    
     💬 Please remember to use the .xcworkspace CocoaPods created from now on instead of your project.
    
    1. Comment the test function (below) -> build -> uncomment the test function -> "Type 'User' does not conform to protocol 'EntityInspectable'"

    Code

    import Foundation
    import ObjectBox
    // objectbox: entity
     class User {
        var id: Id = 0
    
        var name: String = "fdf"
        
        init() {
            
        }
        
     static func test(box: Box<User>){
     }
     }
    

    Additional context

    • It's in a Swift module that shared to another iOS project
    • No file was generated in the generated folder
    opened by thanhhai08sk 8
  • Link error with Xcode 12.3

    Link error with Xcode 12.3

    The following error is generated when building ObjectBox projects with Xcode 12.3. I do not see this error when building with previous releases of Xcode.

    error: Building for iOS, but the linked and embedded framework 'ObjectBox.framework' was built for iOS + iOS Simulator. …

    Basic info:

    • ObjectBox version - 1.4.1 - Manual setup, no CocoaPods or Carthage
    • Reproducibility - Always in Xcode 12.3, never in previous releases
    • Device: iPad Pro 12.9 3rd Gen, x86 Simulator
    • OS: iOS 14.3, macOS 11.1

    Steps to reproduce the behavior:

    1. Build project with Xcode 12.2
    2. Note success
    3. Build project with Xcode 12.3
    4. Note error

    Expected behavior: Expect successful build (link) in Xcode 12.3 as with previous Xcode releases.

    Logs, stack traces:

    Showing All Messages
    
    Prepare build
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Using build description from memory
    
    Build target … with configuration Debug
    error: Building for iOS, but the linked and embedded framework 'ObjectBox.framework' was built for iOS + iOS Simulator.…
    
    Build failed    12/15/20, 8:51 AM    0.1 seconds
    

    Additional context:

    • I have reinstalled Xcode 12.2 under macOS 11.1 and confirmed that my project builds as expected. This appears to be specific to Xcode 12.3.
    • Note that I am NOT using either CocoaPods or Carthage. This was a 'manual' setup of ObjectBox.
    bug 
    opened by pfvernon2 7
  • Crash on property/distinct query

    Crash on property/distinct query

    Xcode 11.4.1, Swift 5.x, iOS 13.4.1

    I'm seeing a general protection fault when attempting a property/distinct query. This is occurring both on hardware and in the simulator.

    I've replicated this crash in the following trivial example.

    class ExampleEntity: Entity {
        var id: Id = 0
    
        // objectbox: index
        var test: String = ""
    }
    
    func test() {
        do {
            //Boilerplate… create store and open box
            let databaseName = "notes"
            let appSupport = try FileManager.default.url(for: .applicationSupportDirectory,
                                                         in: .userDomainMask,
                                                         appropriateFor: nil,
                                                         create: true)
                .appendingPathComponent(Bundle.main.bundleIdentifier!)
            let directory = appSupport.appendingPathComponent(databaseName)
            try FileManager.default.createDirectory(at: directory,
                                                    withIntermediateDirectories: true,
                                                    attributes: nil)
            let store = try Store(directoryPath: directory.path)
            let exampleEntityBox = store.box(for: ExampleEntity.self)
    
            //if box is empty add some random values
            var boxCount = try exampleEntityBox.count()
            if boxCount == 0 {
                let testCases = ["foo", "bar", "foobar", "barfoo"];
                for _ in 1...100 {
                    let exampleEntity = ExampleEntity()
                    exampleEntity.test = testCases.randomElement() ?? "default"
                    try exampleEntityBox.put(exampleEntity)
                }
                boxCount = try exampleEntityBox.count()
            }
    
            assert(boxCount > 0)
    
            //get distinct values the hard way
            let all = try exampleEntityBox.all()
            let testSet = Set(all.map { $0.test })
            print(testSet)
    
            //MARK: Crash - general protection fault
            //get distinct values the objectbox way
            let distinct: [String] = try exampleEntityBox.query().build()
                .property(ExampleEntity.test)
                .distinct(caseSensitiveCompare: false)
                .findStrings()
    
            print(distinct)
    
        } catch {
            print("error")
        }
    }
    

    Am I doing something incorrectly? Is this a known issue?

    opened by pfvernon2 7
  • Swift mutable structs `applyTODb` throws `cannotRelateToUnsavedEntities`

    Swift mutable structs `applyTODb` throws `cannotRelateToUnsavedEntities`

    Describe the bug applyToDb throws cannotRelateToUnsavedEntities(message: "Must put the entity before you can apply().") with mutable structs in Swift. Classes work just fine with code sequence.

    Basic info:

    • ObjectBox version: 1.7.0
    • Reproducibility: always
    • Device: iPhone 13 mini simulator
    • OS: iOS 16.0

    To Reproduce

    Classes work:

    class FC: Entity, Identifiable, CustomStringConvertible {
        var id: Id = 0
        var name = "none"
        // objectbox: backlink = "f"
        var ns: ToMany<NC> = nil
        required init() {}
        var description: String {
            return "FC: id = \(id); name = \(name); ns = \(ns)"
        }
    }
    
    class NC : Entity, Identifiable, CustomStringConvertible {
        var id: Id = 0
        var name = "none"
        var f: ToOne<FC> = nil
        required init() {}
        var description: String {
            return "NC: id = \(id); name = \(name); f = \(f)"
        }
    }
    
        func test4mini() throws { // This works.
            let path = NSTemporaryDirectory() + "/d2"
            let store = try Store(directoryPath: path)
            let fBox = store.box(for: FC.self)
            let nBox = store.box(for: NC.self)
            try fBox.removeAll()
            try nBox.removeAll()
            let f0 = FC()
            f0.name = "X"
            try fBox.put(f0)
            let n0 = NC()
            n0.name = "Y"
            f0.ns.append(n0)
            try f0.ns.applyToDb()
            print("f0 = \(f0)")
            print("n0 = \(n0)")
            print("n0.f = \(n0.f)")
        }
    

    The output is:

    f0 = FC: id = 2; name = X; ns = [NC: id = 2; name = Y; f = ToOne(FC: id = 2; name = X; ns = (unresolved))]
    n0 = NC: id = 2; name = Y; f = ToOne(FC: id = 2; name = X; ns = (unresolved))
    n0.f = ToOne(FC: id = 2; name = X; ns = (unresolved))
    

    That is, the backlink to the ToOne relations works when appending to the ToMany relationship.

    This does NOT work:

    struct F2: Entity, Identifiable {
        var id: Id
        var name: String
        // objectbox: backlink = "f"
        var ns: ToMany<N2>
    }
    struct N2: Entity, Identifiable {
        var id: Id
        var name: String
        var f: ToOne<F2>
    }
    
       func test2bmini() throws {
            let path = NSTemporaryDirectory() + "/dy"
            let store = try Store(directoryPath: path)
            let fBox = store.box(for: F2.self)
            let nBox = store.box(for: N2.self)
            try fBox.removeAll()
            try nBox.removeAll()
            var f0 = F2(id: 0, name: "X", ns: nil)
            try fBox.put(&f0)
            var n0 = try nBox.put(struct: N2(id: 0, name: "Y", f: nil))
            try nBox.put(&n0)
            f0.ns.append(n0)
            try fBox.put(&f0, mode: .update)
            try nBox.put(&n0, mode: .update)
            try f0.ns.applyToDb()
            print("f0 = \(f0)")
            print("n0 = \(n0)")
            print("n0.f = \(n0.f)")
        }
    

    The output is:

    cannotRelateToUnsavedEntities(message: "Must put the entity before you can apply().")
    

    Expected behavior Running applyToDb on aToMany relationship when both values have been put should not result in errors.

    Code See above.

    Logs, stack traces See above.

    Additional context

    Did you find any workarounds to prevent the issue? No.

    bug 
    opened by funcJeff 0
  • Need non-toy examples using Swift immutable structs

    Need non-toy examples using Swift immutable structs

    Describe the solution you'd like Full examples of how to achieve tasks using Swift immutable structs. It is very difficult to achieve even the simplest tasks. Example: https://stackoverflow.com/questions/73556044/how-to-get-objectbox-backlinks-to-save-with-swift-structs

    Or, if I am doing something wrong, then not enough runtime or compile time errors are thrown.

    Describe alternatives you've considered The NotesExample.xcworkspace contains only class examples.

    The docs say that:

    beyond having to use a special call the first time you write out an entity, everything is the same as with classes.

    This is not true. I have code that works for a class type but fails for immutable struct types.

    Additional context I love the stark simplicity of the architecture of ObjectBox, but without working examples to follow with Swift immutable structs, the documentation is suddenly too opaque. I am either seeing behavior that makes no sense or getting errors that I cannot understand why.

    enhancement 
    opened by funcJeff 0
  • Xcode 14 beta 4 build phase script warning

    Xcode 14 beta 4 build phase script warning

    In Xcode 14 beta 4 (14A5284g), building a toy example project will output this warning:

    warning: Run script build phase '[OBX] Update Sourcery Generated Files' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'MyApp' from project 'MyApp')
    

    I followed second instruction, and went to Target > Build Phases > [OBX] Update Sourcery Generated Files and unchecked "Based on dependency analysis". That made the warning go away on next build.

    I surmise that is the correct fix, yes?

    opened by funcJeff 1
  • Retrieve store from Box object

    Retrieve store from Box object

    In ObjectBox for java you can retrieve the store from an Box object to easily start transactions. In swift this field is not available so you have to keep a store reference around to make transactions.

    Describe the solution you'd like Add a store reference to Box objects like in java.

    enhancement 
    opened by Burtan 1
  • Error on compiling for Mac Catalyst

    Error on compiling for Mac Catalyst

    Trying to Compile my Project with Target Mac Catalyst but getting error shown below:

    Does objectBox Supports Compiling for Mac Catalyst? Should I use the Manual Method described in link below? https://swift.objectbox.io/advanced/manual-installation

    Error on Xcode Compile

    Showing All Messages
    ...Pods/ObjectBox/ObjectBox.xcframework:1:1: While building for Mac Catalyst, no library for this platform was found in '/Users/q/Ed/Projects/GIT/personalscrum/Pods/ObjectBox/ObjectBox.xcframework'.
    
    • ObjectBox version 1.7.0
    • Installed via pod file

    Podfile

    target 'XYFramework' do
    pod 'ObjectBox' 
    end
    
    bug 
    opened by ussu99 0
Releases(v1.8.0)
Owner
ObjectBox
ObjectBox object oriented database - up to 10x faster than SQLite
ObjectBox
Store and retrieve Codable objects to various persistence layers, in a couple lines of code!

tl;dr You love Swift's Codable protocol and use it everywhere, who doesn't! Here is an easy and very light way to store and retrieve Codable objects t

null 149 Dec 15, 2022
CodableFiles - Save and load Codable objects from DocumentDirectory on iOS Devices.

Welcome to CodableFiles, a simple library that provides an easier way to save, load or delete Codable objects in Documents directory. It’s primarily a

Egzon Pllana 36 Dec 20, 2022
CodableCloudKit allows you to easily save and retrieve Codable objects to iCloud Database (CloudKit)

CodableCloudKit CodableCloudKit allows you to easily save and retrieve Codable objects to iCloud Database (CloudKit) Features ℹ️ Add CodableCloudKit f

Laurent Grondin 65 Oct 23, 2022
Why not use UserDefaults to store Codable objects 😉

tl;dr You love Swift's Codable protocol and use it everywhere, who doesn't! Here is an easy and very light way to store and retrieve -reasonable amoun

Omar Albeik 452 Oct 17, 2022
PJAlertView - This library is to make your own custom alert views to match your apps look and feel

PJAlertView - This library is to make your own custom alert views to match your apps look and feel

prajeet 6 Nov 10, 2017
Check your Valorant store from your phone!

Valorant Store Checker Description VSC (Valorant Store Tracker) is an open source iOS app that allows you to track your store and preview your skins.

Gordon 20 Dec 29, 2022
🔍 Browse and edit UserDefaults on your app

UserDefaults-Browser Browse and edit UserDefaults on your app. (SwiftUI or UIKit) Browse Edit (as JSON) Edit (Date) Export Note: We recommend to use S

Yusuke Hosonuma 25 Nov 3, 2022
CRRateLimitTester - Simple Clash Royale Rate Limit Tester Written Using HummingBird and Swift

CRRateLimitTester Simple Clash Royale Rate Limit Tester Written Using HummingBir

Mahdi Bahrami 0 Jan 16, 2022
Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Saoud Rizwan 3k Jan 3, 2023
Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS

简体中文 DefaultsKit leverages Swift 4's powerful Codable capabilities to provide a Simple and Strongly Typed wrapper on top of UserDefaults. It uses less

Nuno Dias 1.4k Dec 26, 2022
Sort import statements in your Swift source code

Sort Swift Imports Sort import statements in your Swift source code. ?? Swift Li

Dariusz Rybicki 2 Dec 19, 2022
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux).

Analytics-Swift The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your

Segment 53 Dec 16, 2022
Easy direct access to your database 🎯

OHMySQL ★★ Every star is appreciated! ★★ The library supports Objective-C and Swift, iOS and macOS. You can connect to your remote MySQL database usin

Oleg 210 Dec 28, 2022
Your Data Storage Troubleshooter 🛠

Your Data Storage Troubleshooter ?? Introduction StorageKit is a framework which reduces the complexity of managing a persistent layer. You can easily

StorageKit 231 Dec 29, 2022
Stuff application – keep track of your stuff.

stuff-app Stuff application – keep track of your stuff. Platforms App to be released for iOS 15, iPadOS 15 and macOS 12 Monterey. Purpose Project is d

Danis Tazetdinov 1 Dec 15, 2021
Stuff application – keep track of your stuff

stuff-app Stuff application – keep track of your stuff. Platforms App to be released for iOS 15, iPadOS 15 and macOS 12 Monterey. Purpose Project is d

Danis Tazetdinov 1 Dec 15, 2021
A CLI tool for the survey of the SSH-Key strength in your GitHub organization members.

GitHub organization SSH-keys checker A CLI tool for the survey of the SSH-Key strength in your GitHub organization members. Requirements macOS 12.0+ S

hugehoge 1 Dec 11, 2021
Check your emails before someone else does

Checkpoint Proofread your emails before your mom does ?? Have you ever meant to

Linus Skucas 9 Nov 15, 2022
Innova CatchKennyGame - The Image Tap Fun Game with keep your scores using Core Database

Innova_CatchKennyGame The Image Tap Fun Game with keep your scores using Core Da

Alican Kurt 0 Dec 31, 2021