Group Group Group Group Group Group Group Group Group

Use Alamofire in iOS Apps |

This is a companion discussion topic for the original entry at


I am getting this error when I run swift run:

/TILApp/Sources/App/configure.swift:61:65: error: reference to member ‘sqlite’ cannot be resolved without a contextual type
migrations.add(model: AcronymCategoryPivot.self, database: .sqlite)

Argh this is a bug in Swift 5.2 that broke a lot of things. If you edit Sources/App/configure.swift and replace the migrations.add(model:) lines with the following:

migrations.add(model: User.self, database: DatabaseIdentifier<User.Database>.sqlite)
migrations.add(model: Acronym.self, database: DatabaseIdentifier<Acronym.Database>.sqlite)
migrations.add(model: TILCategory.self, database: DatabaseIdentifier<TILCategory.Database>.sqlite)
migrations.add(model: AcronymCategoryPivot.self, database: DatabaseIdentifier<AcronymCategoryPivot.Database>.sqlite)

Then it will work, I’ll get updated materials pushed out ASAP

1 Like

Thanks you for your help!

I was able to run the server after making above changes but now getting an error message when I try to open localhost:8080 on my browser.

[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)

Yeah there’s no route registered for /, so if you do /api/users instead you’ll get an array of users. (You also might see a 404 in the browser as it tries to get a favicon, but you can ignore these)

1 Like

Just to add, the videos that this affects (episodes 1-4) should now all be updated with code that builds

1 Like

I need some explanation regarding two points.

  1. What is the importance of using Session while making requests?

  2. The completion handler of responseDecodable runs on main thread by default. So why do we have to explicitly run the code on main thread in the success callback? Like in this case:

     case .success(let categories):
         DispatchQueue.main.async { [weak self] in
           guard let self = self else { return }
           self.categories = categories


  1. Session is used to store all the request configuration stuff. When using URLSession you normally configure it will some options, or use the default options. This is just a wrapper around that, and allows us to change it as we need going forward (for instance when doing SSL pinning).

  2. It’s good practice to always jump onto the main thread when changing anything to do with the UI. In this instance, we may be on the main thread when hitting that, but there could be a future instance where we aren’t and call reload on a background thread etc

Hope that helps!

1 Like

<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
I run simulator but acronyms data is nil
what should I do?

What does the Vapor app console say and is the Vapor app running on the same machine? 1004 means it can’t connect to the host