diff --git a/Data/models/Bookmark.swift b/Data/models/Bookmark.swift index fe0895af154..d49ad6c5a52 100644 --- a/Data/models/Bookmark.swift +++ b/Data/models/Bookmark.swift @@ -379,6 +379,16 @@ public final class Bookmark: NSManagedObject, WebsitePresentable, Syncable, CRUD delete() } + /// Removes a single Bookmark of a given URL. + /// In case of having two bookmarks with the same url, a bookmark to delete is chosen randomly. + public class func remove(forUrl url: URL) { + let context = DataController.newBackgroundContext() + let predicate = isFavoriteOrBookmarkByUrlPredicate(url: url, getFavorites: false) + + let record = first(where: predicate, context: context) + record?.remove() + } + private func removeFolderAndSendSyncRecords(uuid: [Int]?) { if !isFolder { return } @@ -452,14 +462,6 @@ extension Bookmark { return all(where: predicate) ?? [] } - public class func remove(forUrl url: URL) { - let context = DataController.newBackgroundContext() - let predicate = isFavoriteOrBookmarkByUrlPredicate(url: url, getFavorites: false) - - let record = first(where: predicate, context: context) - record?.delete() - } - /// Gets all nested bookmarks recursively. public static func getRecursiveChildren(forFolderUUID syncUUID: [Int]?, context: NSManagedObjectContext = DataController.viewContext) -> [Bookmark]? {