This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Taxonomy model for Label is not correct, estimated design from C…
…ategory.swift
- Loading branch information
1 parent
0d8a43a
commit e896c8e
Showing
6 changed files
with
116 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Label.swift | ||
// OpenFoodFacts | ||
// | ||
// Created by Alexander Scott Beaty on 8/23/20. | ||
// | ||
|
||
import Foundation | ||
import RealmSwift | ||
import ObjectMapper | ||
|
||
class Label: Object { | ||
|
||
@objc dynamic var code = "" | ||
|
||
let parents = List<String>() | ||
let children = List<String>() | ||
let names = List<Tag>() | ||
|
||
@objc dynamic var mainName = "" // name in the language of the app, for sorting | ||
@objc dynamic var indexedNames = "" // all names concatenated, for search | ||
|
||
convenience init(code: String, parents: [String], children: [String], names: [Tag]) { | ||
self.init() | ||
self.code = code | ||
|
||
self.parents.removeAll() | ||
self.parents.append(objectsIn: parents) | ||
|
||
self.children.removeAll() | ||
self.children.append(objectsIn: children) | ||
|
||
self.names.removeAll() | ||
self.names.append(objectsIn: names) | ||
|
||
self.mainName = names.chooseForCurrentLanguage()?.value ?? "" | ||
self.indexedNames = names.map({ (tag) -> String in | ||
return tag.languageCode.appending(":").appending(tag.value) | ||
}).joined(separator: " ||| ") // group all names to be able to query on only one field, independently of language | ||
} | ||
|
||
override static func primaryKey() -> String? { | ||
return "code" | ||
} | ||
|
||
override static func indexedProperties() -> [String] { | ||
return ["mainName", "indexedNames"] | ||
} | ||
} |
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
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