Slow Swift Progress

Got some time to work on my iOS app today, and made some decent progress. I’ve currently got a task that will read through the photo library and call an HTTP endpoint with the response. It also has the beginnings of a storage mechanism with sqlite.

I like XCode. The fonts look nice, it does a good job popping up dialogue boxes in appropriate places, and the debugger works pretty well. So far I’ve been pretty happy using it. I wish it would have first-class support for Python, because aesthetically it’s a lot more pleasing than PyCharm.

I blew some time figuring out how to do something “the right way” with a background task, and even though I got it mostly working, in the end I found it easier to just call my test method synchronously on load.
Once I made some progress there a lot of things fell into place pretty quickly.

Swift as a language is still pretty young, which sometimes blends in interesting ways with a fairly mature developer ecosystem. There’s a lot of good documentation out there about “iPhone” development, and it’s kind of interesting that some of the Swift posts are already out of date. The language is changing enough between version 2,3,4 and 5 that entire API libraries are out of date or have been renamed.

In the camp of things I like, Closures are very cool. I love that they’re a first-class citizen of the APIs.

uploadTask = session.uploadTask(with: request, from: data, completionHandler: {
    data, response, error in
        print("Response \(response) - \(error)")
})

For some reason, I find the in syntax there incredibly confusing. In general, Swift reads a lot like Python, but the differences sometimes trip me up.

I haven’t been doing any work with any external libraries, and I already feel annoyed by that, so I think I’ll be rectifying that soon. This Stack Overflow post about submitting post requests is a good example.
That’s basically a nightmare for someone used to the Python ecosystem and requests. Or, for example, my SQLite create table method:

func createTable() {
    let createTableString = """
    create table if not exists photos(
        uuid varchar,
        hidden boolean,
        width int,
        height int,
        location varchar,
        mediaType int
    );
    """
    var createTableStatement: OpaquePointer?
    // 2
    if sqlite3_prepare_v2(db, createTableString, -1, &createTableStatement, nil) ==
        SQLITE_OK {
      // 3
      if sqlite3_step(createTableStatement) == SQLITE_DONE {
        print("\nTable created.")
      } else {
        print("\nTable is not created.")
      }
    } else {
        print("\nCREATE TABLE statement is not prepared.")
    }
    // 4
    sqlite3_finalize(createTableStatement)

}

Opaque C pointers? SQL string interpolation? Gross.

Between HTTP requests and the default SQLite behavior, I think figuring out how to include AFNetworking and FMDB or SQLite.swift is coming up on the docket pretty soon.

Working:

  • Iterating over photos and saving data to a SQLite database
  • Retrieving image and calling something via HTTP

Not working:

  • Actually uploading data to HTTP
  • Determine what albums a photo is in

Up Next:

  • SQLite, HTTP library
  • Finish HTTP requests

social