Skip to main content

Around2Me – Instantly Discover Nearby Essentials

In today’s fast-paced world, finding what you need — exactly when you need it — should be effortless. That’s where Around2Me comes in. Whether you're navigating a new city, running errands, or just looking for a bite nearby, Around2Me helps you instantly find nearby essentials like ATMs, restaurants, hospitals, gas stations , and much more. Around2Me 🚀 What Makes Around2Me Different? Unlike many location-based apps that are bloated with unnecessary features or force users to sign up, Around2Me is lightweight, private, and instant . Here's how: 📍 Location-Based Discovery The app instantly detects your current location and shows you relevant nearby places — from pharmacies to petrol pumps, cafes to banks. 🗺️ Map Integration Tap any place to view it on the map and get turn-by-turn directions in seconds. 🧩 Clean Categories Looking for something specific? Use quick-access filters like Hospitals , ATMs , Coffee Shops , or Parking . 🔐 No Signups, No Data Collection ...

How to Save, Fetch, Update and Delete data from Core Data using Swift 5.0

 

Getting Started Save, Fetch, Update and Delete Core Data in Swift 5.0

Core Data is NOT an SQLite database. it is a graphical and persistence framework.CURD in swift (Create, Update, Retrieve, Delete)

CURD in swift (Create, Update, Retrieve, Delete)


//MARK: - Save User Info Data

func addData(user_nameStringuser_emailStringuser_dobStringimageDataNSData) {

        

        guard let appDelegate = UIApplication.shared.delegate asAppDelegate else {

            return

        }

        let managedContext  = appDelegate.persistentContainer.viewContext

        let entity = NSEntityDescription.entity(forEntityName"UserInfo"in: managedContext)!

        

        let UserData = NSManagedObject(entity: entity, insertInto: managedContext)

        UserData.setValue(user_name, forKeyPath"user_name")

        UserData.setValue(user_email, forKeyPath"user_email")

        UserData.setValue(user_dob, forKeyPath"user_dob")

        UserData.setValue(imageData, forKeyPath"image")

        do {

            try managedContext.save()

            getUserInfo.append(UserData)

            print("save data.")

        catch let error as NSError {

            print("Could not save. \(error)\(error.userInfo)")

        }

    }


//MARK: - Fetch User Info Data


    func fetchData(){

        let context = (UIApplication.shared.delegate as!                 AppDelegate).persistentContainer.viewContext

        let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "UserInfo")

        do{

            let results = try context.fetch(fetchRequest)

            let  dateCreated = results as! [NSManagedObject]

            for _datecreated in dateCreated {

                userListData.append(_datecreated)

                tableView.reloadData()

            }

        }catch let err as NSError {

            print(err.debugDescription)

        }

    }



//MARK: - Delete User Info Data



    func deleteInfo(){

        let appDelegate = UIApplication.shared.delegate as! AppDelegate

        let context = appDelegate.persistentContainer.viewContext

        let requestDel = NSFetchRequest<NSFetchRequestResult>(entityName: "UserInfo")

        requestDel.returnsObjectsAsFaults = false

        let predicate = NSPredicate(format: "(user_name = %@)", deleteValue)

        requestDel.predicate = predicate

           do {

                let arrUsrObj = try context.fetch(requestDel)

                for usrObj in arrUsrObj as! [NSManagedObject] { // Fetching Object

                    context.delete(usrObj) // Deleting Object

               }

           } catch {

                print("Failed")

           }

           do {

               try context.save()

           } catch {

               print("Failed saving")

           }

    }



//MARK: - Update User Info Data


    func UpdateInfo(){

        let managedContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

        let entity = NSEntityDescription.entity(forEntityName: "UserInfo", in: managedContext)

                let request = NSFetchRequest<NSFetchRequestResult>()

                request.entity = entity

                let predicate = NSPredicate(format: "(user_name = %@)", userNameStr)

                request.predicate = predicate

                do {

                    let results =

                        try managedContext.fetch(request)

                    let objectUpdate = results[0] as! NSManagedObject

                    objectUpdate.setValue(userName_textField.text!, forKey: "user_name")

                    objectUpdate.setValue(userEmail_textField.text!, forKey: "user_email")

                    objectUpdate.setValue(userDOB_textField.text!, forKey: "user_dob")

                    do {

                        try managedContext.save()

                        userName_textField.text = ""

                        userEmail_textField.text = ""

                        userDOB_textField.text = ""

                        print("Update")

                    }catch _ as NSError {

                      print("Update")

                    }

                }

                catch _ as NSError {

                    print("Update")

                }

    }

Comments