1

The demo iOS application from GRDB on github runs great on the phone simulator of my iMac, but it's not clear how to get GRDB building in an iOS application of my own (part 1 of this question), with the minimal set of components (part 2 of this question).1

The GRDB installation instructions suggests offers as one option: "Swift Package Manager". Since I'm new to this programming environment, this sounded like "the right way", but after trying it, I was still left guessing at how to get my project building successfully.

Steps done so far:

  • Created a new project Applications > Xcode (9.4 beta) > Create a new Xcode project > Single View App > "FirstDb"
  • Put import GRDB in the view controller (obviously couldn't compile yet)
  • Applications > Utilities > Terminal
    • cd /Users/owner/documents/xcodeprojects/firstdb
    • mkdir GRDB
    • cd GRDB
    • swift package init --type library
  • Edit Package.swift, adding .package(url: "https://github.com/groue/GRDB.swift.git", from: "2.10.0") at the appropriate location
  • Applications > Utilities > Terminal
    • swift package resolve (resulting in 'Fetching', 'Cloning', 'Resolving')

Status After Product > Build, the import GRDB line still says no such module.

So part 1 of the question is still unresolved. I have not been able to address part 2 of the question yet. Sorry if either or both of these are brutally obvious to the well heeled Xcode developer, but after researching the problem, I found no specific guidance.

Using SPM is not a requirement, so if the other options to integrate GRDB are a better choice, I'd like to see how to integrate using one of those.

Footnote

  1. I would like to understand the steps required to add only the portions of GRDB that are required to use the Record object and to be able to execute SQL statements for an iOS project. The presumption is that much of the complete package (tests, watch, etc, is not required in the project using the GRDB basics, resulting in a more compact iOS application.
Kazunori Takaishi
  • 2,268
  • 1
  • 15
  • 27
Dale
  • 5,520
  • 4
  • 43
  • 79

2 Answers2

4

Cocoa Pods

As indicated by the author, Swift Package Manager is only one option and is "not known to integrate with existing Xcode projects", so probably not a good choice. So to address part one of the question, the technique for integrating GRDB using Cocoa Pods is shown below.

Cocoa Pods Install

Based on this tutorial, you should be able to install CocoaPods without downloading anything first if your OS is OS X 10.7 or newer.

  • Applications > Utilities > Terminal
    • sudo gem install cocoapods
    • pod setup --verbose

My install seemed to work fine, but generated more logging than the tutorial showed.

Integration with Existing Project

  • Created a new project Applications > Xcode (9.4 beta) > Create a new Xcode project > Single View App > "FirstDb"
  • This created /Users/owner/documents/xcodeprojects/FirstDb/FirstDb.xcodeproj
  • Put import GRDB in the view controller (obviously couldn't compile yet)
  • Close Xcode! (we will be accessing it later, through xcworkspace, not xcodeproj)
  • Applications > Utilities > Terminal
    • cd /Users/owner/documents/xcodeprojects/firstdb
    • pod init
    • open -a Xcode PodFile

Make your file specify GRDB:

platform :ios, '9.0'
target 'FirstDb' do
    use_frameworks!
    pod 'GRDB.swift'
end

That doesn't take advantage of the versioning function available, so it will be up to you to make sure there's no breaking changes by introduced by GRDB as it is enhanced.

Use Cocoa Pods to get GRDB

Now is when you download GRDB:

  • Applications > Utilities > Terminal
    • cd /Users/owner/documents/xcodeprojects/firstdb
    • pod install

You should see something like this:

Analyzing dependencies
Downloading dependencies
Installing GRDB.swift (2.10.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `FirstDb.xcworkspace` for this project from now on.
....

Build the Project with GRDB import

Now open the workspace file FirstDb.xcworkspace (not the proj file). In the left project outline, you should see your starter project and also Pods:

FirstDb
Pods

Build the workspace (Product > Build), and you should see that your import GRDB line in the ViewController is compiling without errors.

Dale
  • 5,520
  • 4
  • 43
  • 79
1

The complete GRDB installation instructions do not suggest using Swift Package Manager. They say that you can use SPM.

SPM is not known to integrate with existing Xcode projects. Instead, SPM can generate Xcode projects: grab information about this if you really need SPM. See, for example, https://www.raywenderlich.com/148832/introduction-swift-package-manager

But there are other options: GRDB installation instructions say that you can also use CocoaPods, and manual installation. Carthage is another possibility (but not quite recommended). I thus suggest that you switch to, say, CocoaPods, which is the easiest way to integrate GRDB and other libraries into your Xcode project.

I would like to understand the steps required to add only the portions of GRDB that are required to use the Record object and to be able to execute SQL statements for an iOS project. The presumption is that much of the complete package (tests, watch, etc, is not required in the project using the GRDB basics, resulting in a more compact iOS application.

Tests and support for Apple Watch won't bloat your application: GRDB only exposes to applications what they need. Tests, for example, are part of the GRDB repository (because you can't ship a robust library without testing), but they are not part of the library itself. Now GRDB is a whole library, and not an umbrella of several libraries: you can't split GRDB and pick only the parts you want. Record types and SQL support, for example, are always available. There are independent companion libraries, though, such as RxGRDB, which you can choose to use, or not.

Gwendal Roué
  • 3,949
  • 15
  • 34
  • 1
    Thanks Gwendal. I used that same wenderlich link to get as far as I originally got with SPM. I don't NEED SPM, but wanted to do it the "right way". I guess CocoaPods is "the right way". I must learn what actions are required to "specify in your podfile". – Dale May 09 '18 at 21:26