dariopellegrini / StorageDone-iOS

Swift library to make easy using local document-oriented database in iOS apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delete event

gaurang12bhatore opened this issue · comments

Please provide me the procedure to delete event which is created by me
I am using this method to delete the event: self.localDatabase.delete(element: )
when i am passing primary key we get the error

error: StorageDone.StorageDoneDatabase:14:17: note: where 'T' = 'Int'
public func delete(element: T) throws where T : StorageDone.PrimaryKey

when i am using this to delete the event nothing is happen: self.localDatabase --= eventType

Hello @gaurang12bhatore.
Sorry for the delayed response.
Could you please provide the struct saved, and the code you use to insert an object of this struct?

I'll check it out.

Thank you.

Maybe @gaurang12bhatore the problem is that you're passing the primary key as the argument of this call.

self.localDatabase.delete(element: 1)

This is not the right way to delete an element.

If for example, you have

struct Teacher: Codable, PrimaryKey {
   let id: Int
   let name: String
   let surname: String

  func primaryKey() -> String {
         return "id"
    }
}

In order to delete an object, you have 2 ways.

  1. Delete using a query.
database.delete(Teacher.self, "id".equal(1))
  1. Delete using PrimaryKey, which only works if Teacher implements PrimaryKey.
database.delete(element: teacher)

I hope this could help.

Thanks for your reply