-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: apply UserTags decoding to the entire related struct
- Loading branch information
Showing
6 changed files
with
59 additions
and
50 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
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,46 @@ | ||
// | ||
// UserTagModel.swift | ||
// VRCKit | ||
// | ||
// Created by makinosp on 2024/08/04. | ||
// | ||
|
||
public struct UserTags: Codable, Hashable { | ||
let systemTags: [SystemTag] | ||
var languageTags: [LanguageTag] | ||
let unknownTags: [String] | ||
} | ||
|
||
public extension UserTags { | ||
init() { | ||
systemTags = [] | ||
languageTags = [] | ||
unknownTags = [] | ||
} | ||
} | ||
|
||
public extension UserTags { | ||
init(from decoder: Decoder) throws { | ||
var systemTags: [SystemTag] = [] | ||
var languageTags: [LanguageTag] = [] | ||
var unknownTags: [String] = [] | ||
var container = try decoder.unkeyedContainer() | ||
while !container.isAtEnd { | ||
let systemTag = try? container.decode(SystemTag.self) | ||
let languageTag = try? container.decode(LanguageTag.self) | ||
if systemTag == nil, languageTag == nil { | ||
unknownTags.append(try container.decode(String.self)) | ||
continue | ||
} | ||
if let systemTag = systemTag { | ||
systemTags.append(systemTag) | ||
} | ||
if let languageTag = languageTag { | ||
languageTags.append(languageTag) | ||
} | ||
} | ||
self.systemTags = systemTags | ||
self.languageTags = languageTags | ||
self.unknownTags = unknownTags | ||
} | ||
} |
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