Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: Unexpectedly found nil while unwrapping an Optional value #42

Closed
2 tasks done
genki-iosdev opened this issue Sep 11, 2023 · 5 comments
Closed
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@genki-iosdev
Copy link

👟 Reproduction steps

AppwriteModels/User.swift:130: Fatal error: Unexpectedly found nil while unwrapping an Optional value

👍 Expected behavior

It should return the User object normally.

👎 Actual Behavior

When I started calling the user registration interface according to the official documentation, an error occurred when the interface returned.

func signUp(email: String, password: String) async -> AppwriteModels.User<[String: AnyCodable]>? {
        // Register User
        var user: AppwriteModels.User<[String: AnyCodable]>?
        do{
            let account = Account(client)
            user = try await account.create(
                userId: ID.unique(),
                email: email,
                password: password
            )
        } catch {
            print(error.localizedDescription)
        }
        return user
    }

I found that the problem is that during the conversion of User, the default value of the labels field is missing.

public static func from(map: [String: Any] ) -> User {
        return User(
            id: map["$id"] as! String,
            createdAt: map["$createdAt"] as! String,
            updatedAt: map["$updatedAt"] as! String,
            name: map["name"] as! String,
            password: map["password"] as? String?,
            hash: map["hash"] as? String?,
            hashOptions: map["hashOptions"] as? Any?,
            registration: map["registration"] as! String,
            status: map["status"] as! Bool,
            labels: map["labels"] as! [Any],
            passwordUpdate: map["passwordUpdate"] as! String,
            email: map["email"] as! String,
            phone: map["phone"] as! String,
            emailVerification: map["emailVerification"] as! Bool,
            phoneVerification: map["phoneVerification"] as! Bool,
            prefs: Preferences.from(map: map["prefs"] as! [String: Any]),
            accessedAt: map["accessedAt"] as! String
        )
    }

🎲 Appwrite version

Version 0.10.x

💻 Operating system

MacOS

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@genki-iosdev genki-iosdev added the bug Something isn't working label Sep 11, 2023
@stnguyen90 stnguyen90 changed the title 🐛 Bug Report: 🐛 Bug Report: Unexpectedly found nil while unwrapping an Optional value Sep 12, 2023
@stnguyen90 stnguyen90 self-assigned this Sep 12, 2023
@stnguyen90
Copy link
Contributor

@genki-iosdev, thanks for raising this issue! Are you connecting to Appwrite Cloud? And what version of the Appwrite Apple SDK are you using?

@genki-iosdev
Copy link
Author

I'm currently using version 4.0.0 of the Appwrite Apple SDK, I'm not sure if I'm using the Appwrite Cloud

@stnguyen90
Copy link
Contributor

stnguyen90 commented Sep 14, 2023

@genki-iosdev, how are you accessing your Appwrite instance? What are you using for the endpoint with the SDK?

@genki-iosdev
Copy link
Author

let client = Client()
        .setEndpoint("https://cloud.appwrite.io/v1")
        .setProject("64fef667da79d01b78fe")
        .setSelfSigned(true)

I used this endpoint.

@stnguyen90
Copy link
Contributor

@genki-iosdev, you're using Appwrite Cloud (notice the endpoint is https://cloud.appwrite.io/v1). Since Appwrite is on version 1.1.2 (see the bottom of the Appwrite Console), please try version 1.1.0 of the Apple SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants