add two-way translation between existing Profile class and new PersistedProfile CoreData class

This commit is contained in:
Bryan Montz
2023-05-12 07:19:43 -05:00
parent 76c57af548
commit 7027b7016c
2 changed files with 24 additions and 0 deletions

View File

@@ -21,4 +21,16 @@ final class PersistedProfile: NSManagedObject {
@NSManaged var lud16: String?
@NSManaged var nip05: String?
@NSManaged var last_update: Date?
func copyValues(from profile: Profile) {
name = profile.name
display_name = profile.display_name
about = profile.about
picture = profile.picture
banner = profile.banner
website = profile.website
lud06 = profile.lud06
lud16 = profile.lud16
nip05 = profile.nip05
}
}

View File

@@ -23,6 +23,18 @@ class Profile: Codable {
self.nip05 = nip05
}
convenience init(persisted_profile: PersistedProfile) {
self.init(name: persisted_profile.name,
display_name: persisted_profile.display_name,
about: persisted_profile.about,
picture: persisted_profile.picture,
banner: persisted_profile.banner,
website: persisted_profile.website,
lud06: persisted_profile.lud06,
lud16: persisted_profile.lud16,
nip05: persisted_profile.nip05)
}
private func str(_ str: String) -> String? {
return get_val(str)
}