Commit 0498fb9a by Dmitry Stepanets

[IOS-256]: Added ability to skip invalid items while parsing

parent cfb7e5cc
......@@ -6,13 +6,15 @@
//
import Foundation
import OneWeatherCore
private struct Data: Codable {
let weatherCardObjectCollection: WeatherCardObjectCollection
}
private struct WeatherCardObjectCollection: Codable {
let items: [WeatherCardItem]
@LossyCodableList
var items: [WeatherCardItem]
}
struct GrapQLResponse: Codable {
......
......@@ -6,6 +6,7 @@
//
import Foundation
import OneWeatherCore
struct MediaArrayObjectCollection: Codable {
let items: [MediaObjectItem]
......
......@@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
CD2D4C6126BD65F80016A180 /* LossyCodableList.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2D4C6026BD65F80016A180 /* LossyCodableList.swift */; };
CD2D4C6326BD67790016A180 /* GlancesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2D4C6226BD67790016A180 /* GlancesList.swift */; };
CD427D1F266F657900B4350A /* OneWeatherCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD427D1E266F657900B4350A /* OneWeatherCore.framework */; };
CD427D23266F715900B4350A /* OneWeatherAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD427D22266F715900B4350A /* OneWeatherAnalytics.framework */; };
......@@ -35,7 +34,6 @@
/* Begin PBXFileReference section */
CD2C227E2670AC6D001ADA9A /* InMobiShortsPG.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = InMobiShortsPG.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
CD2D4C6026BD65F80016A180 /* LossyCodableList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LossyCodableList.swift; sourceTree = "<group>"; };
CD2D4C6226BD67790016A180 /* GlancesList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlancesList.swift; sourceTree = "<group>"; };
CD427D1E266F657900B4350A /* OneWeatherCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OneWeatherCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CD427D22266F715900B4350A /* OneWeatherAnalytics.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OneWeatherAnalytics.framework; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -133,7 +131,6 @@
CDAEC2082679F70600818A2A /* GlanceOverlayImage.swift */,
CDFE3F2B266E519E00E72910 /* PeekData.swift */,
CDFE3F2D266E51B400E72910 /* Peek.swift */,
CD2D4C6026BD65F80016A180 /* LossyCodableList.swift */,
CD2D4C6226BD67790016A180 /* GlancesList.swift */,
);
path = Models;
......@@ -249,7 +246,6 @@
buildActionMask = 2147483647;
files = (
CDFE3F2E266E51B400E72910 /* Peek.swift in Sources */,
CD2D4C6126BD65F80016A180 /* LossyCodableList.swift in Sources */,
CD2D4C6326BD67790016A180 /* GlancesList.swift in Sources */,
CDFE3F23266E453500E72910 /* InMobiShortSource.swift in Sources */,
CDFE3F29266E489E00E72910 /* GlanceImage.swift in Sources */,
......
......@@ -6,6 +6,7 @@
//
import Foundation
import OneWeatherCore
struct GlancesList: Codable {
@LossyCodableList
......
......@@ -59,6 +59,7 @@
CD615FC52655295C00B717DB /* CLAuthorizationStatus+Localized.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD615FB22655293100B717DB /* CLAuthorizationStatus+Localized.swift */; };
CD6C22F026677E0200D75659 /* PushNotificationsManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6C22EF26677E0200D75659 /* PushNotificationsManagerProtocol.swift */; };
CD71B9C6265E629D00803DBB /* String+NewLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD71B9C5265E629D00803DBB /* String+NewLine.swift */; };
CD8B659127047ED800343897 /* LossyCodableList.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8B659027047ED700343897 /* LossyCodableList.swift */; };
CD8E48A526651414008E7F8D /* NWSCurrentEventsReponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8E48A426651414008E7F8D /* NWSCurrentEventsReponse.swift */; };
CD91685726552FAE00EC04EF /* MulticastDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD91685626552FAE00EC04EF /* MulticastDelegate.swift */; };
CD91685826552FD000EC04EF /* DefaultSettingsFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD615FCE265529DE00B717DB /* DefaultSettingsFactory.swift */; };
......@@ -171,6 +172,7 @@
CD6C22EF26677E0200D75659 /* PushNotificationsManagerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationsManagerProtocol.swift; sourceTree = "<group>"; };
CD71B9C4265E5F7300803DBB /* OneWeatherCorePlayground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = OneWeatherCorePlayground.playground; path = ../OneWeatherCorePlayground.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
CD71B9C5265E629D00803DBB /* String+NewLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+NewLine.swift"; sourceTree = "<group>"; };
CD8B659027047ED700343897 /* LossyCodableList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LossyCodableList.swift; sourceTree = "<group>"; };
CD8E48A426651414008E7F8D /* NWSCurrentEventsReponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSCurrentEventsReponse.swift; sourceTree = "<group>"; };
CD91685626552FAE00EC04EF /* MulticastDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulticastDelegate.swift; sourceTree = "<group>"; };
CD91685D26552FEC00EC04EF /* Global.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Global.swift; sourceTree = "<group>"; };
......@@ -434,6 +436,7 @@
children = (
CD2D55D42655336F007B70F4 /* PropertyWrappers */,
CD91685D26552FEC00EC04EF /* Global.swift */,
CD8B659027047ED700343897 /* LossyCodableList.swift */,
CD11AFEA26651D1D00EC4BA0 /* Constants.swift */,
CD91685626552FAE00EC04EF /* MulticastDelegate.swift */,
CD2D55D7265533F3007B70F4 /* UserDefaultsWrapper.swift */,
......@@ -783,6 +786,7 @@
CD615F9D265526E700B717DB /* DayTimeWeather.swift in Sources */,
CD615F9E265526E700B717DB /* Health.swift in Sources */,
CD2D55DE2655377F007B70F4 /* NWSSeverityLevel.swift in Sources */,
CD8B659127047ED800343897 /* LossyCodableList.swift in Sources */,
CEC363AD26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift in Sources */,
CD615F9F265526E700B717DB /* AirQuality.swift in Sources */,
CDD2F8EF2665102B00B48322 /* LocationManager.swift in Sources */,
......
......@@ -8,14 +8,15 @@
import Foundation
@propertyWrapper
struct LossyCodableList<Element> {
var elements: [Element]
public struct LossyCodableList<Element> {
public var elements: [Element]
var wrappedValue: [Element] {
public var wrappedValue: [Element] {
get { elements }
set { elements = newValue }
}
}
extension LossyCodableList: Decodable where Element: Decodable {
private struct ElementWrapper: Decodable {
var element: Element?
......@@ -26,7 +27,7 @@ extension LossyCodableList: Decodable where Element: Decodable {
}
}
init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let wrappers = try container.decode([ElementWrapper].self)
elements = wrappers.compactMap(\.element)
......@@ -34,7 +35,7 @@ extension LossyCodableList: Decodable where Element: Decodable {
}
extension LossyCodableList: Encodable where Element: Encodable {
func encode(to encoder: Encoder) throws {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
for element in elements {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment