Created
June 4, 2020 03:40
-
-
Save League2EB/5f1f0091f68895a25abed9790984e0c6 to your computer and use it in GitHub Desktop.
RealmSwift + Rx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func delete<T>(type: T.Type, code: String) -> Observable<()> where T: Object { | |
return Observable.create { observer in | |
do { | |
let realm = try Realm() | |
guard let object = realm.objects(type).filter(code).first else { return Disposables.create() } | |
realm.delete(object) | |
observer.onNext(()) | |
observer.onCompleted() | |
} catch let error { | |
observer.onError(error) | |
} | |
return Disposables.create() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@League2EB
thanks for your questions.
I think the first thing to do is to specify a
T: Object
and prepare a deletable method.Next I thought it would be good to create a method if you want to filter by items other than keys
example)
(* I have not actually operated it)
Thank you!