This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9261385-alamofire/lessons/1
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9261385-alamofire/lessons/1
Hello,
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
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)
Just to add, the videos that this affects (episodes 1-4) should now all be updated with code that builds
Hello,
I need some explanation regarding two points.
-
What is the importance of using
Session
while making requests? -
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 self.tableView.reloadData() }
-
Session
is used to store all the request configuration stuff. When usingURLSession
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). -
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> 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
In file included from /Users/gangi/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio-ssl/Sources/CNIOOpenSSL/helpers.c:14:
/Users/gangi/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio-ssl/Sources/CNIOOpenSSL/include/c_nio_openssl.h:17:10: fatal error: âopenssl/conf.hâ file not found
In file included from /Users/gangi/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/crypto/Sources/CCryptoOpenSSL/shim.c:1:
/Users/gangi/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/crypto/Sources/CCryptoOpenSSL/include/c_crypto_openssl.h:4:10: fatal error: âopenssl/conf.hâ file not found
In file included from /Users/gangi/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio-ssl/Sources/CNIOOpenSSL/shims.c:16:
/Users/gangi/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio-ssl/Sources/CNIOOpenSSL/include/10: fatal error: âopenssl/conf.hâ file not found
#include <openssl/conf.h>
^~~~~~~~~~~~~~~~
#include <openssl/conf.h>
^~~~~~~~~~~~~~~~
#include <openssl/conf.h>
^~~~~~~~~~~~~~~~
1 error generated.
1 error generated.
[3/20] Compiling CNIOSHA1 c_nio_sha1.c
error: fatalError
Ah the Alamofire example still uses Vapor 3 IIRC which contains some breaking changes. Try running brew install pkg-config libressl
- that should install the necessary libraries to get it to build from the command line
Hi,
Iâm getting this error when I run âswift runâ:
âswift-nio-ssl-supportâ: warning: ignoring declared target(s) âswift-nio-ssl-supportâ in the system package
âswift-nio-zlib-supportâ: warning: ignoring declared target(s) âswift-nio-zlib-supportâ in the system package
Building for debuggingâŠ
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/ContiguousCollection.swift:21:1: error: type âStaticStringâ does not conform to protocol âCollectionâ
extension StaticString: Collection {
^
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/ContiguousCollection.swift:21:1: error: unavailable subscript âsubscript(:)â was used to satisfy a requirement of protocol âCollectionâ
extension StaticString: Collection {
^
Swift.Collection:3:12: note: 'subscript(:)â declared here
public subscript(bounds: Range<Self.Index>) â Self.SubSequence { get }
^
Swift.Collection:12:5: note: requirement âsubscript(:)â declared here
subscript(bounds: Range<Self.Index>) â Self.SubSequence { get }
^
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/ContiguousCollection.swift:21:1: error: type âStaticStringâ does not conform to protocol âCollectionâ
extension StaticString: Collection {
^
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/ContiguousCollection.swift:21:1: error: unavailable subscript 'subscript(:)â was used to satisfy a requirement of protocol âCollectionâ
extension StaticString: Collection {
^
Swift.Collection:3:12: note: âsubscript(:)â declared here
public subscript(bounds: Range<Self.Index>) â Self.SubSequence { get }
^
Swift.Collection:12:5: note: requirement 'subscript(:)â declared here
subscript(bounds: Range<Self.Index>) â Self.SubSequence { get }
^
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/Selector.swift:60:16: warning: static property â_noneâ produces an empty option set
static let _none = SelectorEventSet(rawValue: 0)
^
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/Selector.swift:60:16: note: use [] to silence this warning
static let _none = SelectorEventSet(rawValue: 0)
^ ~~~~~~~~~~~~~
([])
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/Selector.swift:89:16: warning: static property â_noneâ produces an empty option set
static let _none = KQueueEventFilterSet(rawValue: 0)
^
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/Selector.swift:89:16: note: use [] to silence this warning
static let _none = KQueueEventFilterSet(rawValue: 0)
^ ~~~~~~~~~~~~~
([])
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/Selector.swift:112:16: warning: static property â_noneâ produces an empty option set
static let _none = EpollFilterSet(rawValue: 0)
^
/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/swift-nio/Sources/NIO/Selector.swift:112:16: note: use [] to silence this warning
static let _none = EpollFilterSet(rawValue: 0)
^ ~~~~~~~~~~~~~
([])
[2/3] Emitting module NIO
Run swift package update
and then try swift run
again
Thanks for your quick reply but it still doesnât work.
âswift package updateâ rises that warnings:
âswift-nio-ssl-supportâ: warning: ignoring declared target(s) âswift-nio-ssl-supportâ in the system package
âswift-nio-zlib-supportâ: warning: ignoring declared target(s) âswift-nio-zlib-supportâ in the system package
âswift runâ outputs a lot but server is not running. Hope that extracted dump helps:
Generic signature <Ï_0_0 where Ï_0_0 : SQLConnectable, Ï_0_0.Connection.Query.AlterTable == SQLiteAlterTable> exceeds maximum completion depth
Rewrite system: {
-
[SQLConnectable].[SQLConnectable] => [SQLConnectable] [permanent]
-
[SQLConnectable].Connection => [SQLConnectable:Connection] [permanent]
-
[SQLConnection].[SQLConnection] => [SQLConnection] [permanent]
[âŠ]
- Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
- Compiling with effective version 4.1.50
- While evaluating request TypeCheckSourceFileRequest(source_file â/Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/sqlite/Sources/SQLite/SQL/SQLiteAlterTableBuilder.swiftâ)
- While type-checking extension of SQLAlterTableBuilder (at /Users/ralf/Downloads/P01 Use Alamofire/starter/TILApp/.build/checkouts/sqlite/Sources/SQLite/SQL/SQLiteAlterTableBuilder.swift:1:1)
- While evaluating request RequirementRequest(extension of SQLAlterTableBuilder, 0, interface)
- While evaluating request ResolveTypeRequest(while resolving type , Connectable.Connection.Query.AlterTable, (null))
- While building rewrite system for generic signature <Ï_0_0 where Ï_0_0 : SQLConnectable, Ï_0_0.Connection.Query.AlterTable == SQLiteAlterTable>
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment varLLVM_SYMBOLIZER_PATH
to point to it):
0 swift-frontend 0x0000000104872f88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000104871f9c llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000104873618 SignalHandler(int) + 344
3 libsystem_platform.dylib 0x000000019a7194c4 _sigtramp + 56
4 libsystem_pthread.dylib 0x000000019a701ee0 pthread_kill + 288
5 libsystem_c.dylib 0x000000019a63c340 abort + 168
6 swift-frontend 0x00000001013a2158 swift::rewriting::RuleBuilder::~RuleBuilder() + 0
7 swift-frontend 0x00000001013a1574 swift::rewriting::RequirementMachine::computeCompletion(swift::rewriting::RewriteSystem::ValidityPolicy) + 84
8 swift-frontend 0x00000001013a1448 swift::rewriting::RequirementMachine::initWithGenericSignature(swift::CanGenericSignature) + 892
9 swift-frontend 0x00000001013a849c swift::rewriting::RewriteContext::getRequirementMachine(swift::CanGenericSignature) + 240
10 swift-frontend 0x00000001012cecc8 swift::GenericSignatureImpl::lookupNestedType(swift::Type, swift::Identifier) const + 544
11 swift-frontend 0x0000000100fa59a0 (anonymous namespace)::TypeResolver::resolveIdentifierType(swift::IdentTypeRepr*, swift::TypeResolutionOptions) + 1716
12 swift-frontend 0x0000000100fa2008 (anonymous namespace)::TypeResolver::resolveType(swift::TypeRepr*, swift::TypeResolutionOptions) + 228
13 swift-frontend 0x0000000100fa1d8c swift::ResolveTypeRequest::evaluate(swift::Evaluator&, swift::TypeResolution const*, swift::TypeRepr*, swift::GenericParamList*) const + 104
14 swift-frontend 0x0000000100fb0f2c llvm::Expectedswift::ResolveTypeRequest::OutputType swift::Evaluator::getResultUncachedswift::ResolveTypeRequest(swift::ResolveTypeRequest const&) + 484
15 swift-frontend 0x0000000100fa1c9c swift::TypeResolution::resolveType(swift::TypeRepr*, swift::GenericParamList*) const + 96
16 swift-frontend 0x0000000100f21bf0 swift::RequirementRequest::evaluate(swift::Evaluator&, swift::WhereClauseOwner, unsigned int, swift::TypeResolutionStage) const + 508
17 swift-frontend 0x00000001013e1aa0 llvm::Expectedswift::RequirementRequest::OutputType swift::Evaluator::getResultUncachedswift::RequirementRequest(swift::RequirementRequest const&) + 1044
18 swift-frontend 0x00000001013df524 swift::WhereClauseOwner::visitRequirements(swift::TypeResolutionStage, llvm::function_ref<bool (swift::Requirement, swift::RequirementRepr*)>) const && + 936
19 swift-frontend 0x0000000100f01f84 checkGenericParams(swift::GenericContext*) + 292
20 swift-frontend 0x0000000100efd350 swift::ASTVisitor<(anonymous namespace)::DeclChecker, void, void, void, void, void, void>::visit(swift::Decl*) + 15096
21 swift-frontend 0x0000000100ef6a7c (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 400
22 swift-frontend 0x0000000100ef68e0 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 204
23 swift-frontend 0x0000000100fb283c swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 540
24 swift-frontend 0x0000000100fb55e0 llvm::Expectedswift::TypeCheckSourceFileRequest::OutputType swift::Evaluator::getResultUncachedswift::TypeCheckSourceFileRequest(swift::TypeCheckSourceFileRequest const&) + 564
25 swift-frontend 0x0000000100fb25cc swift::performTypeChecking(swift::SourceFile&) + 120
26 swift-frontend 0x00000001002875d0 swift::CompilerInstance::performSema() + 256
27 swift-frontend 0x0000000100114348 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4072
28 swift-frontend 0x00000001000dc130 swift::mainEntry(int, char const**) + 808
29 dyld 0x0000000106f69088 start + 516
ralf@MBP-von-Ralf-2 TILApp %
Ok so it looks like an issues with SQLite on 5.6. Unfortunately Vapor 3 is EOL now. Iâll see if I can get some time to update the project to Vapor 4 but for now if you edit the docker-compose.yml
file so it looks like
version: '3'
services:
til-app:
depends_on:
- postgres
build: .
environment:
- DATABASE_HOSTNAME=postgres
- DATABASE_PORT=5432
ports:
- "8080"
postgres:
image: "postgres"
environment:
- POSTGRES_DB=vapor-test
- POSTGRES_USER=vapor
- POSTGRES_PASSWORD=password
Then run
docker-compose up
That should run the server in Docker for you and all work
Thank you for your answer. I changed docker-compose.yml as requested but I got an error during the building:
=> ERROR [internal] load metadata for docker.io/library/swift:4.2 7.9s
------
> [internal] load metadata for docker.io/library/swift:4.2:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest
Could it be that Iâm in trouble as Iâm using a M1 MacBook instead an Intel one?
@ralfm yep itâs because itâs an M1
Iâve built a Vapor 4 version of the starter project at GitHub - 0xTim/AlamofireServer
That should work instead
@0xtim That works! Thanks a lot.