Quickstarters
CRUD Samples
How to Build a CRUD App for iOS with Objective-C?
27 min
overview in this walkthrough, you will discover how to create a simple crud (create, read, update, delete) application for ios using objective c we will utilize back4app as the backend to manage your data, ensuring a smooth integration of a backend with your ios app this guide covers everything from setting up a back4app project to implementing essential crud operations using the parse ios sdk initially, you'll set up a back4app project titled basic crud app ios this project will serve as your data repository and allow you to design a flexible data model with classes such as items and users you can define these classes manually in the back4app dashboard or leverage the integrated ai agent to streamline the process after configuring your backend, you will integrate it with your objective c ios application the tutorial includes code examples to initialize the parse sdk, perform crud operations, and implement secure user authentication by the end of this tutorial, you will have built a production ready ios application that performs fundamental crud functions along with secure user management key concepts learn how to develop an ios crud app using objective c with a robust backend understand how to design and integrate a scalable backend using back4app utilize back4app’s admin app for efficient data management implement secure data handling with acls and user authentication using the parse ios sdk prerequisites before you begin, ensure you have a back4app account with an active project need help? refer to getting started with back4app https //www back4app com/docs/get started/new parse app xcode installed with a configured ios development environment this tutorial assumes familiarity with objective c and ios development basic understanding of object oriented programming and rest apis brush up on the objective c documentation https //developer apple com/library/archive/documentation/cocoa/conceptual/programmingwithobjectivec/introduction/introduction html if needed step 1 – project initialization creating your back4app project log in to your back4app account click the “new app” button on your dashboard name your project basic crud app ios and follow the on screen prompts to complete the setup create new project once created, your project appears on the dashboard, serving as the backbone for your app’s data management step 2 – crafting the data model setting up your data structures for this ios crud app, you need to define key classes in your back4app project below are the primary classes and their fields 1\ items class this class stores details about each item field data type purpose id objectid auto generated unique identifier title string the item’s name description string a brief summary of the item createdat date timestamp when the item was created updatedat date timestamp for the last update 2\ users class this class manages user credentials and authentication field data type purpose id objectid automatically generated identifier username string unique username for the user email string user’s unique email address passwordhash string securely stored user password createdat date account creation timestamp updatedat date last modification timestamp you can set up these classes via the back4app dashboard create new class you add fields by selecting the data type, naming the field, assigning default values, and marking mandatory fields create column using the back4app ai agent for schema design the integrated ai agent can automatically build your data schema based on your description this feature simplifies the setup process and ensures your data model meets the app requirements how to use the ai agent access the ai agent open your back4app dashboard and navigate to the ai agent within your project settings detail your data model enter a prompt describing the required classes and fields review and confirm once the ai generates a schema proposal, review it and confirm to apply the changes example prompt create the following classes in my back4app project 1\) class items \ fields \ id objectid (auto generated) \ title string \ description string \ createdat date (auto generated) \ updatedat date (auto updated) 2\) class users \ fields \ id objectid (auto generated) \ username string (unique) \ email string (unique) \ passwordhash string \ createdat date (auto generated) \ updatedat date (auto updated) this method saves time and ensures consistency in your data structure step 3 – enabling the admin app & managing data overview of the admin app back4app's admin app provides a user friendly, no code interface for managing your backend data its drag and drop features allow you to easily create, view, modify, and delete records activating the admin app go to the “more” menu in your back4app dashboard select “admin app” and click “enable admin app ” establish your admin account by setting up initial credentials, which also configures system roles like b4aadminuser enable admin app after activation, log in to the admin app to manage your data efficiently admin app dashboard managing crud operations via the admin app within the admin app, you can add records click “add record” within a class (e g , items) to insert new data edit records select any record to view or update its fields delete records remove entries that are no longer required this streamlined interface significantly simplifies data management tasks step 4 – connecting your ios application with back4app with the backend set up, the next step is integrating your ios app with back4app using the parse ios sdk option a utilizing the parse ios sdk in objective c include the parse sdk add the parse framework to your xcode project you can use cocoapods by adding the following to your podfile pod 'parse' initialize parse in your appdelegate open your appdelegate m and add the initialization code in the application\ didfinishlaunchingwithoptions method // appdelegate m \#import \<parse/parse h> \ (bool)application (uiapplication )application didfinishlaunchingwithoptions (nsdictionary )launchoptions { \[parse initializewithconfiguration \[parseclientconfiguration configurationwithblock ^(id\<parsemutableclientconfiguration> configuration) { configuration applicationid = @"your application id"; configuration clientkey = @"your ios key"; configuration server = @"https //parseapi back4app com"; }]]; return yes; } implement crud methods in objective c create a service class, e g , itemsservice m , to handle crud operations // itemsservice m \#import "itemsservice h" \#import \<parse/parse h> @implementation itemsservice \ (void)createitemwithtitle (nsstring )title description (nsstring )description { pfobject item = \[pfobject objectwithclassname @"items"]; item\[@"title"] = title; item\[@"description"] = description; \[item saveinbackgroundwithblock ^(bool succeeded, nserror error) { if (succeeded) { nslog(@"item created successfully "); } else { nslog(@"error creating item %@", error localizeddescription); } }]; } \ (void)fetchitemswithcompletion (void (^)(nsarray items, nserror error))completion { pfquery query = \[pfquery querywithclassname @"items"]; \[query findobjectsinbackgroundwithblock ^(nsarray objects, nserror error) { completion(objects, error); }]; } \ (void)updateitemwithobjectid (nsstring )objectid newtitle (nsstring )newtitle newdescription (nsstring )newdescription { pfquery query = \[pfquery querywithclassname @"items"]; \[query getobjectinbackgroundwithid\ objectid block ^(pfobject item, nserror error) { if (item) { item\[@"title"] = newtitle; item\[@"description"] = newdescription; \[item saveinbackgroundwithblock ^(bool succeeded, nserror error) { if (succeeded) { nslog(@"item updated successfully "); } else { nslog(@"error updating item %@", error localizeddescription); } }]; } else { nslog(@"error fetching item %@", error localizeddescription); } }]; } \ (void)deleteitemwithobjectid (nsstring )objectid { pfquery query = \[pfquery querywithclassname @"items"]; \[query getobjectinbackgroundwithid\ objectid block ^(pfobject item, nserror error) { if (item) { \[item deleteinbackgroundwithblock ^(bool succeeded, nserror error) { if (succeeded) { nslog(@"item deleted successfully "); } else { nslog(@"error deleting item %@", error localizeddescription); } }]; } else { nslog(@"error fetching item %@", error localizeddescription); } }]; } @end option b employing rest or graphql if you prefer not to use the parse sdk, you can interact with back4app through restful api calls for instance, to retrieve items via rest \#import \<foundation/foundation h> @interface restclient nsobject \+ (void)fetchitems; @end @implementation restclient \+ (void)fetchitems { nsurl url = \[nsurl urlwithstring @"https //parseapi back4app com/classes/items"]; nsmutableurlrequest request = \[nsmutableurlrequest requestwithurl\ url]; \[request sethttpmethod @"get"]; \[request setvalue @"your application id" forhttpheaderfield @"x parse application id"]; \[request setvalue @"your rest api key" forhttpheaderfield @"x parse rest api key"]; nsurlsessiondatatask datatask = \[\[nsurlsession sharedsession] datataskwithrequest\ request completionhandler ^(nsdata data, nsurlresponse response, nserror error) { if (error) { nslog(@"error fetching items %@", error localizeddescription); } else { nsstring result = \[\[nsstring alloc] initwithdata\ data encoding\ nsutf8stringencoding]; nslog(@"response %@", result); } }]; \[datatask resume]; } @end choose the approach that best suits your project's needs step 5 – securing your backend configuring access control lists (acls) to safeguard your data, configure acls for your objects for instance, to create an item visible only to its owner \#import \<parse/parse h> \ (void)createprivateitemwithtitle (nsstring )title description (nsstring )description owner (pfuser )owner { pfobject item = \[pfobject objectwithclassname @"items"]; item\[@"title"] = title; item\[@"description"] = description; pfacl acl = \[pfacl aclwithuser\ owner]; \[acl setpublicreadaccess\ no]; \[acl setpublicwriteaccess\ no]; item acl = acl; \[item saveinbackgroundwithblock ^(bool succeeded, nserror error) { if (succeeded) { nslog(@"private item created "); } else { nslog(@"error saving item %@", error localizeddescription); } }]; } setting class level permissions (clps) use the back4app dashboard to adjust clps, ensuring that only authenticated users can access certain classes by default step 6 – implementing user authentication managing user accounts back4app leverages parse’s native user class for managing user authentication in your ios application, you can implement registration and login as follows \#import \<parse/parse h> @interface authservice nsobject \+ (void)signupwithusername (nsstring )username password (nsstring )password email (nsstring )email; \+ (void)loginwithusername (nsstring )username password (nsstring )password; @end @implementation authservice \+ (void)signupwithusername (nsstring )username password (nsstring )password email (nsstring )email { pfuser user = \[pfuser user]; user username = username; user password = password; user email = email; \[user signupinbackgroundwithblock ^(bool succeeded, nserror error) { if (succeeded) { nslog(@"user successfully registered!"); } else { nslog(@"sign up error %@", error localizeddescription); } }]; } \+ (void)loginwithusername (nsstring )username password (nsstring )password { \[pfuser loginwithusernameinbackground\ username password\ password block ^(pfuser user, nserror error) { if (user) { nslog(@"user logged in %@", user username); } else { nslog(@"login failed %@", error localizeddescription); } }]; } @end this approach also extends to session management, password resets, and additional authentication features step 7 – conclusion and future directions congratulations! you have successfully built an ios crud application using objective c, fully integrated with back4app throughout this guide, you set up a project named basic crud app ios , designed core classes for items and users, and managed your backend using the admin app additionally, you connected your app using the parse ios sdk, implemented crud operations, and secured your data with acls next steps expand the application incorporate additional features like advanced search, detailed item views, or real time updates enhance backend capabilities explore cloud functions, integrate third party apis, or refine role based access control deepen your expertise visit the back4app documentation https //www back4app com/docs for further insights and tutorials happy coding and best of luck with your ios crud project!