Я пытаюсь удалить все объекты области, кроме одного, используя этот код, который я основал в стеке:
let realm = RealmGetData.realmShared
let typeToBeKept = MyObject.self
do {
realm.configuration.objectTypes?.filter{$0 != typeToBeKept}.forEach{ type in
try! realm.write {
realm.delete(realm.objects(type.self))
}
}
} catch let error as NSError {
// handle error
print ("***********Delete-RLMException : \(error.description)")
}
}
Но я получаю эту ошибку, которую я не понял:
Could not cast value of type 'Element' (0x1035532e8) to 'RealmSwift.Object' (0x105084bc0
Элемент является объективной C моделью области
#import <Foundation/Foundation.h>
#import <Realm/Realm.h>
@interface Element : RLMObject
@property(nonatomic) int idElement;
@property(nonatomic) int type;
@property(nonatomic) NSString *contentElement;
@property(nonatomic) int orderContent;
@property(nonatomic) int idPoi;
Я думаю, что realmSwift не может удалить модель данных области Obj c. Любая помощь, пожалуйста