Generate model files
With the basic setup complete, next you will model the data that your application will store. Amplify DataStore will use this model to persist data to your local device that will be synchronized to a backend API without writing any additional code.
These models are specified as GraphQL schemas. If you'd like, first learn more about GraphQL schemas and data modeling.
-
To begin, you need to edit the
schema.graphql
file. To find it, first navigate to your project folder and then intoamplify/backend/api/amplifyDatasource/schema.graphql
.Open the file with any text editor and replace its contents with the following schema:
enum Priority {LOWNORMALHIGH}type Todo @model @auth(rules: [{ allow: public }]) {id: ID!name: String!priority: Prioritydescription: String}This schema creates a model called
Todo
with four properties:- id: an auto-generated identifier field for a Todo item
- name: a non-optional string field that is the title of the Todo item
- priority: an optional enumeration type field that indicates the importance of a Todo item; its only available values being LOW, NORMAL, or HIGH
- description: an optional string field that holds more information about a Todo item
-
Next, you need to generate the Swift objects for these models by running this command on the terminal:
amplify codegen models
The generated models will be added to your project under the AmplifyModels
group.
- Finally, open Xcode and build (
Cmd+b
) your project to compile the newly generated files.