-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Tom <[email protected]>
- Loading branch information
1 parent
7be54dc
commit 5c62780
Showing
7 changed files
with
100 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// RealmExtension.swift | ||
// FlowCrypt | ||
// | ||
// Created by Ivan Ushakov on 09.11.2021 | ||
// Copyright © 2017-present FlowCrypt a. s. All rights reserved. | ||
// | ||
|
||
import Realm | ||
import RealmSwift | ||
|
||
protocol RealmListDetachable { | ||
func detached() -> Self | ||
} | ||
|
||
extension List: RealmListDetachable where Element: Object { | ||
func detached() -> List<Element> { | ||
let detached = self.detached | ||
let result = List<Element>() | ||
result.append(objectsIn: detached) | ||
return result | ||
} | ||
} | ||
|
||
extension Object { | ||
// TODO Temporary solution from StackOverflow for https://github.com/FlowCrypt/flowcrypt-ios/issues/877 | ||
func detached() -> Self { | ||
let detached = type(of: self).init() | ||
for property in objectSchema.properties { | ||
guard | ||
property != objectSchema.primaryKeyProperty, | ||
let value = value(forKey: property.name) | ||
else { continue } | ||
|
||
if let detachable = value as? Object { | ||
detached.setValue(detachable.detached(), forKey: property.name) | ||
} else if let list = value as? RealmListDetachable { | ||
detached.setValue(list.detached(), forKey: property.name) | ||
} else { | ||
detached.setValue(value, forKey: property.name) | ||
} | ||
} | ||
return detached | ||
} | ||
} | ||
|
||
extension Sequence where Iterator.Element: Object { | ||
var detached: [Element] { | ||
return self.map({ $0.detached() }) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ export const CommonData = { | |
email: '[email protected]', | ||
name: 'Dima' | ||
}, | ||
secondContact: { | ||
email: '[email protected]', | ||
name: 'Demo' | ||
}, | ||
bundleId: { | ||
id: 'com.flowcrypt.as.ios.debug', | ||
}, | ||
|
This file contains 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
This file contains 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