Using SQLite with XCode/Swift

I found this tutorial here:

but, I am unsure about it. I started to be afraid when I read:

Add the following function in your playground

Either it is an innocent word (but in that case, why using it ?) or they forget to tell something at the beginning of the tutorial (requirements for example).

Anyway: what do you think about this tutorial ? Is it worth the time to follow it ?

Sorry folks, on a second read , I discovered that this is for iOS: not what I want.

However, I hope this will help some people.

@DaveS has done some translation to use SQLite in Swift as you would with Xojo. I haven’t yet used it, but I will need to do so when I convert a later project.

Thank you Sam.

This is for a personal project, so no money is involved.

On GitHub, you have some good wrappers
I like this one:

Vapor is FOSS and provides an ORM that makes handling DBs in Swift easier.

If it is for a personal app, you may also take SwiftData.

Uhm CoreData ?

CoreData is the old API. SwiftData is new and brings data binding to SwiftUI.

1 Like

Oh silly me of COURSE there’s a new API

Apple is doing their best to imitate Xojo here :stuck_out_tongue:

1 Like

Of course, DBKit is so much better and mature :sweat_smile:

1 Like

Well said

SwiftData looks absolutely insane, and I can’t wait to give it a proper go.

1 Like

I remember earlier today that Bard can have some help.

So, I asked " How to create a ListBox using XCode" and get:

Create ListBox in Xcode

How to create a ListBox using XCode

To create a ListBox using Xcode, you can either use the Interface Builder or create it programmatically.

Using the Interface Builder:

  1. Open your Xcode project and create a new view controller.
  2. Drag an NSScrollView object from the Object Library onto your view controller.
  3. Click and hold the Control key, and then drag from the top edge of the NSScrollView to the bottom edge of the NSScrollView. This will create an NSTableView object inside the NSScrollView.
  4. Resize the NSScrollView and NSTableView as needed.
  5. Select the NSTableView in the Object Library and click the Show Editor button in the bottom right corner of the Xcode window.
  6. In the Attributes Inspector, set the Style property of the NSTableView to List.
  7. In the Controller Connection Inspector, connect the dataSource and delegate properties of the NSTableView to your view controller.

Creating a ListBox Programmatically:

  1. Create an instance of the NSTableView class.
  2. Set the frame of the NSTableView.
  3. Add the NSTableView to your view hierarchy.
  4. Implement the dataSource and delegate methods of the NSTableView.

Here is an example of how to create a ListBox programmatically:

`Swiftimport Cocoa

class ViewController: NSViewController {

@IBOutlet var scrollView: NSScrollView!

override func viewDidLoad() {

    let tableView = NSTableView(frame: scrollView.bounds) = .list
    tableView.dataSource = self
    tableView.delegate = self


// MARK: - NSTableViewDataSource

func numberOfRows(in tableView: NSTableView) -> Int {
    return 10

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
    return "Row \(row)"


Utilisez le code avec précaution. En savoir plus

This code will create a ListBox with 10 rows. Each row will display the text “Row N”, where N is the row number.

Bard peut afficher des informations inexactes, y compris sur des personnes. Vérifiez donc ses réponses. Votre confidentialité et Bard S’ouvre dans une nouvelle fenêtre

With SwiftUI, you can use a List, Grid, LazyVStack or Table. Oops… I forgot Form!

List {
    for index in 1...10 {
        Text( "Row \(index)" )

I just typed this code into the forum and haven’t checked it as I don’t have Xcode on this Mac.

1 Like

You need to decide whether your app shall take the SwiftUI or the UIKit way. SwiftUI is much more approachable and easier to code, imho.

1 Like

for the time being I will disagree 100%. SwiftUI may have ways to do things “easier”, but there are still places where it has yet to mature. So I will stick with UIKit for now