diff --git a/Frameworks/RSParser/Feeds/JSON/JSONTypes.swift b/Frameworks/RSParser/JSON/JSONTypes.swift similarity index 65% rename from Frameworks/RSParser/Feeds/JSON/JSONTypes.swift rename to Frameworks/RSParser/JSON/JSONTypes.swift index aa65ae52e..fa3039a31 100644 --- a/Frameworks/RSParser/Feeds/JSON/JSONTypes.swift +++ b/Frameworks/RSParser/JSON/JSONTypes.swift @@ -8,5 +8,5 @@ import Foundation -typealias JSONDictionary = [String: Any] -typealias JSONArray = [JSONDictionary] +public typealias JSONDictionary = [String: Any] +public typealias JSONArray = [JSONDictionary] diff --git a/Frameworks/RSParser/JSON/JSONUtilities.swift b/Frameworks/RSParser/JSON/JSONUtilities.swift new file mode 100644 index 000000000..2319e0389 --- /dev/null +++ b/Frameworks/RSParser/JSON/JSONUtilities.swift @@ -0,0 +1,27 @@ +// +// JSONUtilities.swift +// RSParser +// +// Created by Brent Simmons on 12/10/17. +// Copyright © 2017 Ranchero Software, LLC. All rights reserved. +// + +import Foundation + +public struct JSONUtilities { + + public static func object(with data: Data) -> Any? { + + return try? JSONSerialization.jsonObject(with: data) + } + + public static func dictionary(with data: Data) -> JSONDictionary? { + + return object(with: data) as? JSONDictionary + } + + public static func array(with data: Data) -> JSONArray? { + + return object(with: data) as? JSONArray + } +} diff --git a/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj b/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj index f70b12ee9..623f113bd 100644 --- a/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj +++ b/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 840FDCB61F0217D20041F61B /* AtomParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840FDCB51F0217D20041F61B /* AtomParserTests.swift */; }; 840FDCB81F0218670041F61B /* DaringFireball.atom in Resources */ = {isa = PBXBuildFile; fileRef = 840FDCB71F0218670041F61B /* DaringFireball.atom */; }; 840FDCBA1F02186D0041F61B /* DaringFireball.json in Resources */ = {isa = PBXBuildFile; fileRef = 840FDCB91F02186D0041F61B /* DaringFireball.json */; }; + 84245C881FDDDC6D0074AFBB /* JSONUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C871FDDDC6D0074AFBB /* JSONUtilities.swift */; }; 84285AA81F005D53002E8708 /* RSSParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84285AA71F005D53002E8708 /* RSSParser.swift */; }; 84285AAA1F006456002E8708 /* RSParsedFeedTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84285AA91F006456002E8708 /* RSParsedFeedTransformer.swift */; }; 84285AAC1F006754002E8708 /* AtomParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84285AAB1F006754002E8708 /* AtomParser.swift */; }; @@ -115,6 +116,7 @@ 840FDCB51F0217D20041F61B /* AtomParserTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AtomParserTests.swift; sourceTree = ""; }; 840FDCB71F0218670041F61B /* DaringFireball.atom */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DaringFireball.atom; sourceTree = ""; }; 840FDCB91F02186D0041F61B /* DaringFireball.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = DaringFireball.json; sourceTree = ""; }; + 84245C871FDDDC6D0074AFBB /* JSONUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONUtilities.swift; sourceTree = ""; }; 84285AA71F005D53002E8708 /* RSSParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RSSParser.swift; sourceTree = ""; }; 84285AA91F006456002E8708 /* RSParsedFeedTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RSParsedFeedTransformer.swift; sourceTree = ""; }; 84285AAB1F006754002E8708 /* AtomParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AtomParser.swift; sourceTree = ""; }; @@ -162,7 +164,7 @@ 84469D341EFF1190004A6B28 /* NSData+RSParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+RSParser.m"; sourceTree = ""; }; 84469D371EFF2645004A6B28 /* RSSInJSONParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RSSInJSONParser.swift; path = Feeds/JSON/RSSInJSONParser.swift; sourceTree = ""; }; 84469D3F1EFF29A9004A6B28 /* FeedParserError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedParserError.swift; path = Feeds/FeedParserError.swift; sourceTree = ""; }; - 84469D411EFF2B2D004A6B28 /* JSONTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JSONTypes.swift; path = Feeds/JSON/JSONTypes.swift; sourceTree = ""; }; + 84469D411EFF2B2D004A6B28 /* JSONTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONTypes.swift; sourceTree = ""; }; 84469D431F002CEF004A6B28 /* JSONFeedParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JSONFeedParser.swift; path = Feeds/JSON/JSONFeedParser.swift; sourceTree = ""; }; 845213241FCB3C75003B6E93 /* coco.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = coco.html; sourceTree = ""; }; 845213261FCB4042003B6E93 /* RSHTMLTag.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RSHTMLTag.h; sourceTree = ""; }; @@ -226,6 +228,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 84245C861FDDDC470074AFBB /* JSON */ = { + isa = PBXGroup; + children = ( + 84469D411EFF2B2D004A6B28 /* JSONTypes.swift */, + 84245C871FDDDC6D0074AFBB /* JSONUtilities.swift */, + ); + path = JSON; + sourceTree = ""; + }; 84285AA61F004879002E8708 /* Dates */ = { isa = PBXGroup; children = ( @@ -340,7 +351,6 @@ 84469D391EFF2649004A6B28 /* JSON */ = { isa = PBXGroup; children = ( - 84469D411EFF2B2D004A6B28 /* JSONTypes.swift */, 84469D371EFF2645004A6B28 /* RSSInJSONParser.swift */, 84469D431F002CEF004A6B28 /* JSONFeedParser.swift */, ); @@ -383,6 +393,7 @@ 84D81BDA1EFA28E700652332 /* RSParser.h */, 84E7E69D1F85780D0046719D /* ParserData.h */, 84E7E69E1F85780D0046719D /* ParserData.m */, + 84245C861FDDDC470074AFBB /* JSON */, 84469CE31EFA2FB0004A6B28 /* Feeds */, 84285AA61F004879002E8708 /* Dates */, 84469CE41EFA3000004A6B28 /* OPML */, @@ -584,6 +595,7 @@ 84469CF01EFA3000004A6B28 /* RSOPMLAttributes.m in Sources */, 84469D381EFF2645004A6B28 /* RSSInJSONParser.swift in Sources */, 84E7E6A01F85780D0046719D /* ParserData.m in Sources */, + 84245C881FDDDC6D0074AFBB /* JSONUtilities.swift in Sources */, 84469D301EFA3134004A6B28 /* RSRSSParser.m in Sources */, 84469D191EFA30A2004A6B28 /* RSDateParser.m in Sources */, 84469CFD1EFA3069004A6B28 /* RSSAXParser.m in Sources */,