### Install CocoaPods and Run Setup Script Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Install the ObjectBox pod and execute the setup script to configure the project for the ObjectBox generator. ```bash pod install --repo-update Pods/ObjectBox/setup.rb ``` -------------------------------- ### Example Package.swift Configuration Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md An example showing how to configure dependencies and targets in Package.swift for ObjectBox. ```swift dependencies: [ .package(url: "https://github.com/objectbox/objectbox-swift-spm.git", from: "INSERT_VERSION"), ], targets: [ .executableTarget( name: "YourApp", dependencies: [ .product(name: "ObjectBox.xcframework", package: "objectbox-swift-spm") ]) ] ``` -------------------------------- ### Clone ObjectBox Swift Repository and Open Example Source: https://github.com/objectbox/objectbox-swift/blob/main/Example/README.md Clone the ObjectBox Swift repository and navigate to the example directory to open the Xcode project. This setup is required to run the iOS and macOS example applications. ```bash git clone --depth=1 https://github.com/objectbox/objectbox-swift cd objectbox-swift/Example open NotesExample.xcodeproj ``` -------------------------------- ### Troubleshoot CocoaPods and Xcode Setup Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Update xcodeproj and cocoapods gems, and update the pod repo to resolve installation or configuration issues. ```bash gem update xcodeproj && gem update cocoapods && pod repo update ``` -------------------------------- ### Update ObjectBox CocoaPod and Run Setup Script Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Update the ObjectBox pod to a new version and re-run the setup script to apply changes. ```bash pod repo update pod update ObjectBox Pods/ObjectBox/setup.rb ``` -------------------------------- ### ObjectBox Swift CRUD and Query Example Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Demonstrates basic Create, Read, Update, Delete (CRUD) operations and querying for Person objects using ObjectBox Swift. Ensure the Store and Box are properly initialized before use. ```swift // objectbox: entity class Person { var id: Id = 0 var firstName: String = "" var lastName: String = "" init() {} init(id: Id = 0, firstName: String, lastName: String) { self.id = id self.firstName = firstName self.lastName = lastName } } let store = try Store(directoryPath: "person-db") let box = store.box(for: Person.self) var person = Person(firstName: "Joe", lastName: "Green") let id = try box.put(person) // Create person = try box.get(id)! person.lastName = "Black" try box.put(person) // Update try box.remove(person.id) // Delete let query = try box.query { Person.firstName == "Joe" && Person.lastName.startsWith("B") }.build() let people: [Person] = try query.find() ``` -------------------------------- ### Install Ruby Version with rbenv Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/README.md Install a specific Ruby version using rbenv and ruby-build. This is necessary to manage Ruby versions for tools like Cocoapods. ```shell # Print current version ruby -v # Install rbenv and build plugin to install ruby versions brew update && brew install rbenv ruby-build # Print the version configured in .ruby-version rbenv local # Install that version, e.g. rbenv install 3.0.5 # Ensure it is the expected version ruby -v ``` -------------------------------- ### Update CocoaPods Gems on Apple Silicon Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Ensure the latest gems for CocoaPods are installed on Apple Silicon (M1) machines. ```bash gem update ffi ethon ``` -------------------------------- ### Basic Swift File for a Command Line Tool Target Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/ios-framework/CodeGenTests/README.md This Swift file serves as the entry point for a command line tool target. It includes placeholders for entity classes and the main test logic. The function should return 0 on success and a non-zero value on failure. ```swift import ObjectBox // TODO Add entity classes func main(_ args: [String]) throws -> Int32 { // TODO Add test code, may print on error or throw return 0 // on success return 1 // or any value > 0 on failure (make sure to print error details) } ``` -------------------------------- ### Common Development Commands Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/README.md Essential commands for fetching dependencies, building the framework, and running tests within the ios-framework directory. ```shell # Enter the framework directory cd ios-framework/ # Download the ObjectBox database libraries make fetch_dependencies # Build the framework make build_framework # Run unit tests make u_tests # Build a debug version of the generator make build_generator_debug # Run generator tests make g_tests ``` -------------------------------- ### Generate Documentation with Jazzy Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/README.md Generate project documentation using jazzy. This command should be run from the ios-framework directory. ```shell cd ios-framework/ make generate_docs ``` -------------------------------- ### Run Specific Unit Test with xcpretty Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/README.md Execute a specific unit test and format the output using xcpretty. Adjust the test filter to target different tests or groups. ```shell xcodebuild -derivedDataPath ./DerivedData test -project ObjectBox.xcodeproj -scheme ObjectBox-macOS -destination 'platform=OS X,arch=x86_64' -only-testing ObjectBoxTests-macOS/StoreTests/test32vs64BitForOs | xcpretty ``` ```shell xcodebuild -derivedDataPath ./DerivedData test -project ObjectBox.xcodeproj -scheme ObjectBox-iOS -destination 'platform=iOS Simulator,name=iPhone 11' -only-testing ObjectBoxTests-iOS/StoreTests/test32vs64BitForOs | xcpretty ``` -------------------------------- ### Add ObjectBox Binary Dependency to Cartfile Source: https://github.com/objectbox/objectbox-swift/blob/main/cartspec/README.md Add this line to your Cartfile to include the ObjectBox binary framework. This method is faster and uses less disk space than source distributions. ```shell binary "https://raw.githubusercontent.com/objectbox/objectbox-swift/master/cartspec/ObjectBox.json" ``` -------------------------------- ### Basic Property Equality Query Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/ios-framework/docs/texts/Query Syntax.md Demonstrates how to query for a specific string value using the generated property object and its isEqual method. Case sensitivity can be controlled. ```swift try store.box(for: Person.self).query { Person.name.isEqual(to: "Steve", caseSensitiveCompare: true) }.build() ``` -------------------------------- ### Run Unit Tests with In-Memory Database Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/README.md Enable in-memory database mode for unit tests by setting the OBX_IN_MEMORY environment variable before running tests. ```shell export OBX_IN_MEMORY=true make u_tests ``` -------------------------------- ### Configure Xcode Build Settings for Bitcode Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Set 'Enable Bitcode' to 'No' in Xcode's 'Build Settings' to avoid errors related to ObjectBox Swift not including Bitcode. ```text In that tab, ensure "All" is active and search for "bitcode". You will find the "Enable Bitcode" setting which you set to "No". ``` -------------------------------- ### Add ObjectBox-Sync.xcframework to Target Dependencies Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Specify the ObjectBox-Sync.xcframework as a product dependency for your target if using ObjectBox Sync. ```swift .product(name: "ObjectBox-Sync.xcframework", package: "objectbox-swift-spm") ``` -------------------------------- ### Add Swift Package Dependency to Xcode Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Search for this URL in Xcode to add the ObjectBox Swift Package dependency. ```text https://github.com/objectbox/objectbox-swift-spm ``` -------------------------------- ### Concise Property Equality Query Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/ios-framework/docs/texts/Query Syntax.md Shows a more succinct way to perform a property equality query using the overloaded == operator. ```swift try store.box(for: Person.self).query { .name == "Steve" }.build() ``` -------------------------------- ### Add ObjectBox CocoaPod to Podfile Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Add the 'ObjectBox' pod to your project's Podfile to include it as a dependency. ```ruby pod 'ObjectBox' ``` -------------------------------- ### Add ObjectBox.xcframework to Target Dependencies Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Specify the ObjectBox.xcframework as a product dependency for your target in Package.swift. ```swift .product(name: "ObjectBox.xcframework", package: "objectbox-swift-spm") ``` -------------------------------- ### Query with Operators and Aliases Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/ios-framework/docs/texts/Query Syntax.md Illustrates using standard Swift operators (>, &&) and the property alias operator (.=) for complex query conditions. Ensure the operators are supported for the property's value type. ```swift try store.box(for: Person.self).query { return "AgeRestriction" .= Person.age > 18 && Person.name.startsWith("St") }.build() ``` -------------------------------- ### Running a Test Target in RunToolTests.sh Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/ios-framework/CodeGenTests/README.md Use this command in RunToolTests.sh to run a test target when the code generator is expected to succeed. The first argument is the test name, and the second is the target number. ```bash # If the code generator should succeed test_target_num "Test Name" || ((FAIL++)) ``` -------------------------------- ### Add ObjectBox Swift Package to Package.swift Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Include the ObjectBox Swift Package repository in your Package.swift file's dependencies. ```swift .package(url: "https://github.com/objectbox/objectbox-swift-spm.git", from: "INSERT_VERSION"), ``` -------------------------------- ### Running a Failing Test Target in RunToolTests.sh Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/ios-framework/CodeGenTests/README.md Use this command in RunToolTests.sh to run a test target when the code generator is expected to fail. The first argument is the test name, and the second is the target number. ```bash # If the code generator should fail fail_codegen_target_num "Test Name" || ((FAIL++)) ``` -------------------------------- ### Disable User Script Sandboxing in Xcode Source: https://github.com/objectbox/objectbox-swift/blob/main/README.md Disable the 'User Script Sandboxing' build setting in Xcode to allow the ObjectBox generator script to run. ```text Disable the User Script Sandboxing option in your Xcode project build settings ``` -------------------------------- ### Schema Definition for BusRoute Entity Source: https://github.com/objectbox/objectbox-swift/blob/main/Source/ios-framework/CodeGenTests/expected/schema-dump/schemaDump3.txt Defines the 'BusRoute' entity with its ID property. This configuration is crucial for ObjectBox to manage and index data for this entity. ```swift Schema { entities = [SchemaEntity { modelId = Optional(1) modelUid = Optional(5107964062888457216) className = BusRoute dbName = nil properties = [SchemaProperty { modelId = Optional(IdUid(1:7895576389419683840)) propertyName = id propertyType = long propertyFlags = [SourceryLib.PropertyFlags.id] propertySwiftType = EntityId entityName = BusRoute unwrappedPropertyType = EntityId dbName = nil modelIndexId = nil backlinkName = nil backlinkType = nil isObjectId = true isBuiltInType = true isStringType = false isRelation = false }] indexes = [] relations = [] toManyRelations = [] lastPropertyId = Optional(IdUid(2:6687926154759915520)) isEntitySubclass = false isValueType = false hasStringProperties = false idProperty = Optional(SchemaProperty { modelId = Optional(IdUid(1:7895576389419683840)) propertyName = id propertyType = long propertyFlags = [SourceryLib.PropertyFlags.id] propertySwiftType = EntityId entityName = BusRoute unwrappedPropertyType = EntityId dbName = nil modelIndexId = nil backlinkName = nil backlinkType = nil isObjectId = true isBuiltInType = true isStringType = false isRelation = false }) idCandidates = [SchemaProperty { modelId = Optional(IdUid(1:7895576389419683840)) propertyName = id propertyType = long propertyFlags = [SourceryLib.PropertyFlags.id] propertySwiftType = EntityId entityName = BusRoute unwrappedPropertyType = EntityId dbName = nil modelIndexId = nil backlinkName = nil backlinkType = nil isObjectId = true isBuiltInType = true isStringType = false isRelation = false }] }) ] lastEntityId = IdUid(1:5107964062888457216) lastRelationId = IdUid(0:0) lastIndexId = IdUid(0:0) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.