NEW: Learn to build the incredible iOS 15 Weather app today! >>

Server-Side Swift Vapor Editon, project 2, code update for Swift 5.2 on pp351

Forums > Books

In project2 (page 351 in the PDF) the code from the book introduces a fatal error that won't let the server run. I tried running the code from the sample files and it produces the same error.

var migrationConfig = MigrationConfig()
migrationConfig.add(model: Poll.self, database: .sqlite)
services.register(migrationConfig)

the migrationConfig.add line introduces a fatal error that highlights .sqlite and says "Reference to member 'sqlite' cannot be resolved without a contextual type"

Am I missing some sort of dependecy to make it work? everything worked fine up until this step.

1      

I found a place on the internets (over at the raywenderlich forums) that suggests it's a new thing with Swift 5.2, so the book isn't really in error, Swift is just constantly evolving.

the post said to "provide the full database identifier" which turns out to be

DatabaseIdentifier<Poll.Database>.sqlite

So those three lines above become

    var migrationConfig = MigrationConfig()
    migrationConfig.add(model: Poll.self, database: DatabaseIdentifier<Poll.Database>.sqlite)
    services.register(migrationConfig)

and that appears to fix the problem. Everything compiles now, back to learnin... :)

   

Hi, I had the same issue and this post helped. Thanks. I am not getting a response on the create curl line:

curl -X POST localhost:8080/polls/create -d "title=What's the best color?" -d "option1=Jet Black" -d "option2=Rose Gold" -d "votes1=0" -d "votes2=0”

I tried removing the "http://", made sure that I didn't misspell any vars in the Poll struct. Also, I tried it on the project2 file from Paul's projects. Nothing. I am very inexperienced with the command line tool and just not sure if I am doing it right.

Any help appreciated?

1      

I had a problem with project2 as well. On page 158 the book instructed to build and run. Got a "build successful" but nothing after that. Didn't get "Server starting on http://localhost:8080" on console.

Checked the code several times... no luck. Deleted and rewrote the whole thing again. Still nothing.

Help!

Edit: I found the problem. I forgot to change the default scheme.

Went to menu Product>Scheme.. was set on “project2-Package”. Changed it to “Run”. Now it works!! This was explained in the first project of the book but wasn’t mentioned again in project2. I didn’t realize it.

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.