File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
templates/swift/guides/search Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import Foundation
2+ #if os(Linux) // For linux interop
3+ import FoundationNetworking
4+ #endif
5+
6+ import Core
7+ { {> snippets/import} }
8+
9+ func saveObjectsModified() async throws {
10+ do {
11+ {{> snippets/init} }
12+
13+ let path = URL(string: #file)!.deletingLastPathComponent()
14+ .appendingPathComponent("products.json")
15+ let data = try Data(contentsOf: URL(fileURLWithPath: path.absoluteString))
16+ let products = try JSONDecoder().decode([[String: AnyCodable]].self, from: data)
17+
18+ let records = products.map { (product) -> [String: AnyCodable] in
19+ var reference = product[" product_reference" ]?.value as! String
20+ var suffixes: [String] = []
21+
22+ while reference.count > 1 {
23+ reference = String(reference.dropFirst())
24+ suffixes.append(reference)
25+ }
26+ var record: [String: AnyCodable] = product
27+ record["product_reference_suffixes"] = AnyCodable(suffixes)
28+ return record
29+ }
30+
31+ { {#dynamicSnippet} }saveObjectsRecords{ {/dynamicSnippet} }
32+ } catch {
33+ print(error)
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments