Skip to content
Back

Swift: Create Document: first attempt

  • 0
  • Apple
Jay
4 May, 2025, 16:14

Hello. We are trying out Appwrite. We've gone through the getting started and setup guide and are attempting to create a document, copy/paste from the Getting started website here https://appwrite.io/docs/products/databases/quick-start except we've moved the createDocument to it's own function

func createDocument() async throws { do { let document = try await databases.createDocument( databaseId: databaseId, collectionId: collectionId, documentId: ID.unique(), data: ["title", "hamlet"] ) print(document) } catch { print(error) } }

the My Books collection has an empty database with a single attribute "title" as String. When calling the function the return value is vague:

Invalid document structure: Unknown attribute: "0"

and the data is not written. Not sure where the "0" is generated from.

We think the api endpoint is correct "https://fra.cloud.appwrite.io/v1" however, the documentation does not match the website so we cannot verify.

One other note is that in the Quick Start guide, it says "You can skip optional steps." but it doesn't indicate which are optional, all of the steps following that statement? Perhaps some are required?

TL;DR
Developers are unclear about the format of returned data in Swift using a specific query. They are unsure about optional steps in the guide but suspect certain parts might be optional. One developer points out a mistake in the code involving a comma instead of a colon. The issue with the vague return value "Invalid document structure: Unknown attribute: '0'" is discussed, potentially related to incorrect data format. The discrepancy between the documentation and the website endpoint is mentioned. The concern about which steps are optional or required in the guide is raised.
Axistro
4 May, 2025, 16:20

I can ans about the endpoint The new endpoint added few weeks ago the fra indicating the server location Although using the old one (the one in the documentation) will also work

Axistro
4 May, 2025, 16:21

Also Your code has a mistake data: ["title" : "hamlet"] You have written , instead of :

Jay
4 May, 2025, 16:24

awesome. I think the , was the issue! OE on that one. Thank you for catching my typo

Axistro
4 May, 2025, 16:24

I couldnt determine which optional steps you were talking about. Could you tell me about this step/s mentioned?

Axistro
4 May, 2025, 16:24

So its working now?

Axistro
4 May, 2025, 16:28

"Optionally, add a custom database ID" If you were talking about these part then this indicates either you can use ID.unique or just give a unique id according to your wish. So, lets say you have a collection and kind of want to have same id as the collection name You could do that.

Jay
4 May, 2025, 16:34

Thanks for the followup. The guide here https://appwrite.io/docs/quick-starts/apple about 1/2 way down says "You can skip optional steps". We assume everything below that statement are "option steps" but were not sure.

Axistro
4 May, 2025, 16:43

Maybe they ment the account creation stuff I dont know about swift Maybe the data related to using Oauth by Apple is optional 🤷‍♂️ Like you could go without sign in if your app doesnt need it 🤷‍♂️

Jay
4 May, 2025, 16:50

Got it. Thanks. It's 'working' but we are still trying to figure out what is returned from the queries. e.g. in Swift let documents = try await databases.listDocuments and we are not sure the format of the returned data. Will keep digging in trying to find out.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more