Quickstarters
CRUD Samples

How to Develop a CRUD App for iOS using Swift?

27min

Overview

This walkthrough will guide you in building a simple CRUD (Create, Read, Update, Delete) application for iOS.

Using Back4app as your cloud backend, you'll learn how to configure your project, design a flexible data model, and implement CRUD functionality with Swift.

This tutorial demonstrates how to integrate your iOS app with Back4app, leveraging either the Parse iOS SDK or REST API, ensuring smooth data management and secure authentication.

Initially, you'll set up a Back4app project—named Basic-CRUD-App-iOS—that provides a scalable, non-relational database for your app. You will define your data structures by creating classes and fields either manually or by using Back4app’s AI Agent.

Next, you’ll explore how to manage your backend using the intuitive Back4app Admin App, a drag-and-drop tool designed to simplify data manipulation.

Finally, you’ll connect your iOS application with the backend, using either the Parse iOS SDK (when applicable) or REST/GraphQL API calls, and incorporate secure user authentication.

By the end of this guide, you will have built a production-ready iOS application that performs core CRUD operations, including secure user sign-in and data handling.

Main Insights

  • Learn to create an iOS CRUD application with an efficient backend.
  • Understand how to architect a scalable backend and connect it seamlessly with an iOS app.
  • Discover how to use the Back4app Admin App for streamlined data creation, retrieval, modification, and deletion.
  • Explore options for containerized deployment and further enhancements for your iOS project.


Prerequisites

Before you begin, ensure you have:

  • A Back4app account with an active project. Need help? See Getting Started with Back4app.
  • An iOS development setup. Use Xcode (version 12 or later) and ensure your development environment is up-to-date.
  • A solid grasp of Swift, object-oriented programming, and REST API fundamentals. Refer to the Swift documentation for more details.


Step 1 – Setting Up Your Project

Creating a New Back4app Project

  1. Log in to your Back4app account.
  2. Click on the “New App” button from your dashboard.
  3. Name your project: Basic-CRUD-App-iOS and follow the on-screen instructions to complete the setup.
Create New Project
Create New Project


After the project is created, it will appear in your dashboard, laying the foundation for your backend configuration.



Step 2 – Crafting Your Data Model

Defining Your Data Structures

For this iOS CRUD application, you will establish several classes (collections) in your Back4app project. Below are the primary classes and their fields required to support your CRUD operations.

1. Items Class

This class will store information about each item.

Field

Data Type

Description

_id

ObjectId

Automatically generated unique identifier.

title

String

The name or title of the item.

description

String

A brief summary or details about the item.

createdAt

Date

Timestamp marking when the item was created.

updatedAt

Date

Timestamp marking the last update to the item.

2. Users Class

This class manages user credentials and authentication data.

Field

Data Type

Description

_id

ObjectId

Auto-generated unique identifier.

username

String

Unique identifier for the user.

email

String

Unique email address of the user.

passwordHash

String

Encrypted password for secure authentication.

createdAt

Date

Timestamp of when the account was created.

updatedAt

Date

Timestamp of the latest account update.

You can define these classes and fields directly in the Back4app dashboard.

Create New Class
Create New Class


You can add columns by selecting a data type, naming the field, setting a default value, and marking it as required if needed.

Create Column
Create Column


Utilizing the Back4app AI Agent for Schema Configuration

The integrated AI Agent in your dashboard can automatically generate your data schema from a description. This helps streamline the setup and ensures your data model supports all necessary CRUD operations.

How to Use the AI Agent:

  1. Open the AI Agent: Access it via your project settings in the Back4app dashboard.
  2. Describe Your Data Model: Provide a comprehensive prompt detailing the classes and their respective fields.
  3. Review and Implement: Examine the proposed schema and confirm to apply the configuration.

Example Prompt

Text


This AI-powered approach saves time and ensures a consistent, optimized data structure for your iOS app.



Step 3 – Launching the Admin App & Managing CRUD Operations

Overview of the Admin App

The Back4app Admin App provides a no-code interface to efficiently manage your backend data. Its user-friendly drag-and-drop features simplify the process of creating, reading, updating, and deleting records.

Enabling the Admin App

  1. Go to the “More” section in your Back4app dashboard.
  2. Select “Admin App” and click “Enable Admin App.”
  3. Set up your admin credentials by creating the initial admin account, which will also establish system roles (such as B4aAdminUser).
Enable Admin App
Enable Admin App


After activation, log into the Admin App to manage your data.

Admin App Dashboard
Admin App Dashboard


Managing Data with the Admin App

Within the Admin App you can:

  • Insert Records: Use the “Add Record” feature within any class (e.g., Items) to introduce new entries.
  • Review/Edit Records: Select a record to view its details or modify its fields.
  • Remove Records: Delete entries that are no longer needed.

This intuitive interface simplifies backend management and enhances productivity.



Step 4 – Connecting Your iOS App with Back4app

With your backend ready, the next step is to link your iOS application to Back4app.

Option A: Utilizing the Parse iOS SDK

  1. Install the Parse iOS SDK: You can integrate the SDK using Swift Package Manager or CocoaPods. For CocoaPods, add the following to your Podfile:

    Ruby
    
  2. Initialize Parse in Your App: In your AppDelegate, configure Parse by inserting the following code:

    Swift
    
  3. Implement CRUD Operations: Create a service class in Swift to handle your data operations. For example, a service to fetch and display items:

    Swift
    

Option B: Using REST or GraphQL

If the Parse iOS SDK does not suit your needs, you can execute CRUD operations via REST calls. For instance, to fetch items using REST in Swift:

Swift


Integrate these API methods into your Swift classes as necessary.



Step 5 – Securing Your Backend

Configuring Access Control Lists (ACLs)

Safeguard your data by setting up ACLs. For instance, to create an item that only its owner can access:

Swift


Class-Level Permissions (CLPs)

Within the Back4app dashboard, adjust the CLPs for your classes to enforce default security measures. This ensures that only authenticated users or designated roles have access to specific data.



Step 6 – Implementing User Authentication

Setting Up User Accounts

Back4app uses the built-in Parse User class to manage authentication. In your iOS application, handle user registration and login as illustrated below:

Swift


A similar approach can be implemented for managing sessions, password resets, and other authentication features.



Step 7 – Conclusion and Future Enhancements

Congratulations! You have successfully built an iOS-based CRUD application that integrates with Back4app.

You configured a project named Basic-CRUD-App-iOS, designed the Items and Users classes, and managed your data using the Back4app Admin App.

Additionally, you connected your iOS app through the Parse SDK (or via REST/GraphQL) and implemented essential security measures.

Future Steps:

  • Expand the Application: Consider adding features like advanced filtering, detailed item views, or real-time updates.
  • Enhance Backend Capabilities: Experiment with cloud functions, third-party API integrations, or more granular role-based access control.
  • Deepen Your Expertise: Visit the Back4app documentation and explore additional tutorials to further optimize your application.

Happy coding and best wishes on your journey to building robust iOS applications!