├── .gitignore
├── LICENSE.txt
├── Package.swift
├── README.md
├── Sample
├── MyPlayground.playground
│ ├── Contents.swift
│ └── contents.xcplayground
├── Sample.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ ├── IDEWorkspaceChecks.plist
│ │ └── swiftpm
│ │ └── Package.resolved
├── Sample
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ ├── Info.plist
│ └── ItemsController.swift
└── SampleTests
│ ├── Info.plist
│ └── SampleTests.swift
├── Sources
├── Channel.swift
├── Entry.swift
├── Feed.swift
├── Item.swift
└── TIFeedParser.swift
└── TIFeedParser.podspec
/.gitignore:
--------------------------------------------------------------------------------
1 | # Mac OS X
2 | .DS_Store
3 |
4 | # Xcode
5 | build/
6 | *.pbxuser
7 | !default.pbxuser
8 | *.mode1v3
9 | !default.mode1v3
10 | *.mode2v3
11 | !default.mode2v3
12 | *.perspectivev3
13 | !default.perspectivev3
14 | xcuserdata
15 | *.xccheckout
16 | *.moved-aside
17 | DerivedData
18 | *.hmap
19 | *.ipa
20 | *.xcuserstate
21 |
22 | # Carthage
23 | Carthage/Build
24 | Sample/Podfile.lock
25 | Sample/Pods/*
26 |
27 | Sample/Sample.xcworkspace/contents.xcworkspacedata
28 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tichise/TIFeedParser/2461710862b942eea09530c0e5e4a914b2725b7b/LICENSE.txt
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.4
2 | import PackageDescription
3 |
4 | let package = Package(
5 | name: "TIFeedParser",
6 | platforms: [.iOS(.v14),
7 | .watchOS(.v5)],
8 | products: [
9 | .library(name: "TIFeedParser", targets: ["TIFeedParser"])
10 | ],
11 | dependencies: [
12 | .package(url: "https://github.com/tadija/AEXML.git", from: "4.6.1"),
13 | .package(url: "https://github.com/malcommac/SwiftDate.git", from: "7.0.0"),
14 | ],
15 | targets: [
16 | .target(name: "TIFeedParser", dependencies: ["AEXML", "SwiftDate"], path: "Sources"),
17 |
18 | ],
19 | swiftLanguageVersions: [.v5]
20 | )
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #### TIFeedParser   
2 |
3 | TIFeedParser is a parser for RSS, built on Alamofire and AEXML.
4 |
5 | TIFeedParser is a very simple RSS parser written in Swift, supporting Atom, RSS1.0 and RSS2.0. You can download it from cocoapods and use [it](http://qiita.com/tichise/items/b9f55ce924159f4ad0cd).
6 |
7 |
8 | #### Examples
9 |
10 | #### RSS1.0, RSS2.0
11 | ```
12 | func loadRSS() {
13 |
14 | let feedString:String = "https://news.google.com/news?hl=us&ned=us&ie=UTF-8&oe=UTF-8&output=rss"
15 |
16 | AF.request(.GET, feedUrlString, parameters:nil)
17 | .response {request, response, xmlData, error in
18 |
19 | if (xmlData == nil) {
20 | return
21 | }
22 |
23 | TIFeedParser.parseRSS(xmlData, completionHandler: {(isSuccess, channel, error) -> Void in
24 |
25 | if (isSuccess) {
26 | // self.items = channel.items!
27 | // self.tableView.reloadData()
28 | } else {
29 | if (error != nil) {
30 | print(error?.localizedDescription)
31 | }
32 | }
33 | })
34 | }
35 | }
36 | ```
37 |
38 | #### Atom
39 | ```
40 | func loadAtom() {
41 |
42 | let feedString:String = "https://news.google.com/news?ned=us&ie=UTF-8&oe=UTF-8&q=nasa&output=atom&num=3&hl=ja"
43 |
44 | AF.request(.GET, feedUrlString, parameters:nil)
45 | .response {request, response, xmlData, error in
46 |
47 | if (xmlData == nil) {
48 | return
49 | }
50 |
51 | TIFeedParser.parseAtom(xmlData, completionHandler: {(isSuccess, feed, error) -> Void in
52 |
53 | if (isSuccess) {
54 | // self.entries = feed.entries!
55 | // self.tableView.reloadData()
56 | } else {
57 | if (error != nil) {
58 | print(error?.localizedDescription)
59 | }
60 | }
61 | })
62 | }
63 | }
64 | ```
65 |
66 | #### Installation (CocoaPods)
67 | `pod TIFeedParser`
68 |
--------------------------------------------------------------------------------
/Sample/MyPlayground.playground/Contents.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import SwiftDate
3 |
4 | /*
5 | // RSS1
6 | // dc:date
7 | let pubDateRss11 = "2018-12-13T22:56:19Z".toDate()?.date
8 | let pubDateRss12 = "2000-01-01T12:00+00:00".toDate(DateFormats.autoFormats, region: Region.current)
9 |
10 |
11 | // RSS2
12 | // DateはRFC 822
13 | let pubDateRSS21 = "Mon, 10 Dec 2018 00:30:50 +0000".toDate(style: StringToDateStyles.rss)?.date
14 | let pubDateRSS22 = "Sat, 07 Sep 2002 0:00:01 GMT".toDate(style: StringToDateStyles.rss)?.date
15 |
16 |
17 | // ATOM
18 | let pubDateATOM11 = "2018-12-14T10:23:00+09:00".toDate()?.date
19 | let pubDateATOM12 = "2018-11-20T08:00:00.000000000Z".toDate()?.date
20 | */
21 |
22 |
--------------------------------------------------------------------------------
/Sample/MyPlayground.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Sample/Sample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 52;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 3C2E27742951D97000F47388 /* TIFeedParser in Frameworks */ = {isa = PBXBuildFile; productRef = 3C2E27732951D97000F47388 /* TIFeedParser */; };
11 | 3C2E27772951DA9500F47388 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 3C2E27762951DA9500F47388 /* Alamofire */; };
12 | B02B1C8B1C9AEB39006760BF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B02B1C8A1C9AEB39006760BF /* AppDelegate.swift */; };
13 | B02B1C901C9AEB39006760BF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B02B1C8E1C9AEB39006760BF /* Main.storyboard */; };
14 | B02B1C921C9AEB39006760BF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B02B1C911C9AEB39006760BF /* Assets.xcassets */; };
15 | B02B1C951C9AEB39006760BF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B02B1C931C9AEB39006760BF /* LaunchScreen.storyboard */; };
16 | B02B1CA01C9AEB39006760BF /* SampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B02B1C9F1C9AEB39006760BF /* SampleTests.swift */; };
17 | B08CA0C21C9AF31A006637AD /* ItemsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B08CA0C11C9AF31A006637AD /* ItemsController.swift */; };
18 | EFEC46C51F4BA92AF24FCC6E /* Pods_SampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 915CEFFBA682E1D9B1029A8B /* Pods_SampleTests.framework */; };
19 | /* End PBXBuildFile section */
20 |
21 | /* Begin PBXContainerItemProxy section */
22 | B02B1C9C1C9AEB39006760BF /* PBXContainerItemProxy */ = {
23 | isa = PBXContainerItemProxy;
24 | containerPortal = B02B1C7F1C9AEB39006760BF /* Project object */;
25 | proxyType = 1;
26 | remoteGlobalIDString = B02B1C861C9AEB39006760BF;
27 | remoteInfo = Sample;
28 | };
29 | /* End PBXContainerItemProxy section */
30 |
31 | /* Begin PBXFileReference section */
32 | 3C2E27722951D8E700F47388 /* TIFeedParser */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = TIFeedParser; path = ..; sourceTree = ""; };
33 | 79CDEE8421C35934003E67BC /* MyPlayground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = MyPlayground.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
34 | 8AF4D290399D9C2A459A2205 /* Pods_Sample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Sample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
35 | 915CEFFBA682E1D9B1029A8B /* Pods_SampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
36 | B02B1C871C9AEB39006760BF /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; };
37 | B02B1C8A1C9AEB39006760BF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
38 | B02B1C8F1C9AEB39006760BF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
39 | B02B1C911C9AEB39006760BF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
40 | B02B1C941C9AEB39006760BF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
41 | B02B1C961C9AEB39006760BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
42 | B02B1C9B1C9AEB39006760BF /* SampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
43 | B02B1C9F1C9AEB39006760BF /* SampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleTests.swift; sourceTree = ""; };
44 | B02B1CA11C9AEB39006760BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
45 | B08CA0C11C9AF31A006637AD /* ItemsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemsController.swift; sourceTree = ""; };
46 | /* End PBXFileReference section */
47 |
48 | /* Begin PBXFrameworksBuildPhase section */
49 | B02B1C841C9AEB39006760BF /* Frameworks */ = {
50 | isa = PBXFrameworksBuildPhase;
51 | buildActionMask = 2147483647;
52 | files = (
53 | 3C2E27742951D97000F47388 /* TIFeedParser in Frameworks */,
54 | 3C2E27772951DA9500F47388 /* Alamofire in Frameworks */,
55 | );
56 | runOnlyForDeploymentPostprocessing = 0;
57 | };
58 | B02B1C981C9AEB39006760BF /* Frameworks */ = {
59 | isa = PBXFrameworksBuildPhase;
60 | buildActionMask = 2147483647;
61 | files = (
62 | EFEC46C51F4BA92AF24FCC6E /* Pods_SampleTests.framework in Frameworks */,
63 | );
64 | runOnlyForDeploymentPostprocessing = 0;
65 | };
66 | /* End PBXFrameworksBuildPhase section */
67 |
68 | /* Begin PBXGroup section */
69 | 3C2E27712951D8E700F47388 /* Packages */ = {
70 | isa = PBXGroup;
71 | children = (
72 | 3C2E27722951D8E700F47388 /* TIFeedParser */,
73 | );
74 | name = Packages;
75 | sourceTree = "";
76 | };
77 | 60F62FCD1BB1176FF9096B3A /* Frameworks */ = {
78 | isa = PBXGroup;
79 | children = (
80 | 8AF4D290399D9C2A459A2205 /* Pods_Sample.framework */,
81 | 915CEFFBA682E1D9B1029A8B /* Pods_SampleTests.framework */,
82 | );
83 | name = Frameworks;
84 | sourceTree = "";
85 | };
86 | B02B1C7E1C9AEB39006760BF = {
87 | isa = PBXGroup;
88 | children = (
89 | 3C2E27712951D8E700F47388 /* Packages */,
90 | 79CDEE8421C35934003E67BC /* MyPlayground.playground */,
91 | B02B1C891C9AEB39006760BF /* Sample */,
92 | B02B1C9E1C9AEB39006760BF /* SampleTests */,
93 | B02B1C881C9AEB39006760BF /* Products */,
94 | 60F62FCD1BB1176FF9096B3A /* Frameworks */,
95 | );
96 | sourceTree = "";
97 | };
98 | B02B1C881C9AEB39006760BF /* Products */ = {
99 | isa = PBXGroup;
100 | children = (
101 | B02B1C871C9AEB39006760BF /* Sample.app */,
102 | B02B1C9B1C9AEB39006760BF /* SampleTests.xctest */,
103 | );
104 | name = Products;
105 | sourceTree = "";
106 | };
107 | B02B1C891C9AEB39006760BF /* Sample */ = {
108 | isa = PBXGroup;
109 | children = (
110 | B02B1C8A1C9AEB39006760BF /* AppDelegate.swift */,
111 | B08CA0C11C9AF31A006637AD /* ItemsController.swift */,
112 | B02B1C8E1C9AEB39006760BF /* Main.storyboard */,
113 | B02B1C911C9AEB39006760BF /* Assets.xcassets */,
114 | B02B1C931C9AEB39006760BF /* LaunchScreen.storyboard */,
115 | B02B1C961C9AEB39006760BF /* Info.plist */,
116 | );
117 | path = Sample;
118 | sourceTree = "";
119 | };
120 | B02B1C9E1C9AEB39006760BF /* SampleTests */ = {
121 | isa = PBXGroup;
122 | children = (
123 | B02B1C9F1C9AEB39006760BF /* SampleTests.swift */,
124 | B02B1CA11C9AEB39006760BF /* Info.plist */,
125 | );
126 | path = SampleTests;
127 | sourceTree = "";
128 | };
129 | /* End PBXGroup section */
130 |
131 | /* Begin PBXNativeTarget section */
132 | B02B1C861C9AEB39006760BF /* Sample */ = {
133 | isa = PBXNativeTarget;
134 | buildConfigurationList = B02B1CA41C9AEB39006760BF /* Build configuration list for PBXNativeTarget "Sample" */;
135 | buildPhases = (
136 | B02B1C831C9AEB39006760BF /* Sources */,
137 | B02B1C841C9AEB39006760BF /* Frameworks */,
138 | B02B1C851C9AEB39006760BF /* Resources */,
139 | );
140 | buildRules = (
141 | );
142 | dependencies = (
143 | );
144 | name = Sample;
145 | packageProductDependencies = (
146 | 3C2E27732951D97000F47388 /* TIFeedParser */,
147 | 3C2E27762951DA9500F47388 /* Alamofire */,
148 | );
149 | productName = Sample;
150 | productReference = B02B1C871C9AEB39006760BF /* Sample.app */;
151 | productType = "com.apple.product-type.application";
152 | };
153 | B02B1C9A1C9AEB39006760BF /* SampleTests */ = {
154 | isa = PBXNativeTarget;
155 | buildConfigurationList = B02B1CA71C9AEB39006760BF /* Build configuration list for PBXNativeTarget "SampleTests" */;
156 | buildPhases = (
157 | B02B1C971C9AEB39006760BF /* Sources */,
158 | B02B1C981C9AEB39006760BF /* Frameworks */,
159 | B02B1C991C9AEB39006760BF /* Resources */,
160 | );
161 | buildRules = (
162 | );
163 | dependencies = (
164 | B02B1C9D1C9AEB39006760BF /* PBXTargetDependency */,
165 | );
166 | name = SampleTests;
167 | productName = SampleTests;
168 | productReference = B02B1C9B1C9AEB39006760BF /* SampleTests.xctest */;
169 | productType = "com.apple.product-type.bundle.unit-test";
170 | };
171 | /* End PBXNativeTarget section */
172 |
173 | /* Begin PBXProject section */
174 | B02B1C7F1C9AEB39006760BF /* Project object */ = {
175 | isa = PBXProject;
176 | attributes = {
177 | LastSwiftUpdateCheck = 0720;
178 | LastUpgradeCheck = 1420;
179 | ORGANIZATIONNAME = tichise;
180 | TargetAttributes = {
181 | B02B1C861C9AEB39006760BF = {
182 | CreatedOnToolsVersion = 7.2.1;
183 | DevelopmentTeam = T33NHY384Q;
184 | LastSwiftMigration = 1000;
185 | ProvisioningStyle = Automatic;
186 | };
187 | B02B1C9A1C9AEB39006760BF = {
188 | CreatedOnToolsVersion = 7.2.1;
189 | DevelopmentTeam = T33NHY384Q;
190 | LastSwiftMigration = 1000;
191 | TestTargetID = B02B1C861C9AEB39006760BF;
192 | };
193 | };
194 | };
195 | buildConfigurationList = B02B1C821C9AEB39006760BF /* Build configuration list for PBXProject "Sample" */;
196 | compatibilityVersion = "Xcode 3.2";
197 | developmentRegion = en;
198 | hasScannedForEncodings = 0;
199 | knownRegions = (
200 | en,
201 | Base,
202 | );
203 | mainGroup = B02B1C7E1C9AEB39006760BF;
204 | packageReferences = (
205 | 3C2E27752951DA9500F47388 /* XCRemoteSwiftPackageReference "Alamofire" */,
206 | );
207 | productRefGroup = B02B1C881C9AEB39006760BF /* Products */;
208 | projectDirPath = "";
209 | projectRoot = "";
210 | targets = (
211 | B02B1C861C9AEB39006760BF /* Sample */,
212 | B02B1C9A1C9AEB39006760BF /* SampleTests */,
213 | );
214 | };
215 | /* End PBXProject section */
216 |
217 | /* Begin PBXResourcesBuildPhase section */
218 | B02B1C851C9AEB39006760BF /* Resources */ = {
219 | isa = PBXResourcesBuildPhase;
220 | buildActionMask = 2147483647;
221 | files = (
222 | B02B1C951C9AEB39006760BF /* LaunchScreen.storyboard in Resources */,
223 | B02B1C921C9AEB39006760BF /* Assets.xcassets in Resources */,
224 | B02B1C901C9AEB39006760BF /* Main.storyboard in Resources */,
225 | );
226 | runOnlyForDeploymentPostprocessing = 0;
227 | };
228 | B02B1C991C9AEB39006760BF /* Resources */ = {
229 | isa = PBXResourcesBuildPhase;
230 | buildActionMask = 2147483647;
231 | files = (
232 | );
233 | runOnlyForDeploymentPostprocessing = 0;
234 | };
235 | /* End PBXResourcesBuildPhase section */
236 |
237 | /* Begin PBXSourcesBuildPhase section */
238 | B02B1C831C9AEB39006760BF /* Sources */ = {
239 | isa = PBXSourcesBuildPhase;
240 | buildActionMask = 2147483647;
241 | files = (
242 | B02B1C8B1C9AEB39006760BF /* AppDelegate.swift in Sources */,
243 | B08CA0C21C9AF31A006637AD /* ItemsController.swift in Sources */,
244 | );
245 | runOnlyForDeploymentPostprocessing = 0;
246 | };
247 | B02B1C971C9AEB39006760BF /* Sources */ = {
248 | isa = PBXSourcesBuildPhase;
249 | buildActionMask = 2147483647;
250 | files = (
251 | B02B1CA01C9AEB39006760BF /* SampleTests.swift in Sources */,
252 | );
253 | runOnlyForDeploymentPostprocessing = 0;
254 | };
255 | /* End PBXSourcesBuildPhase section */
256 |
257 | /* Begin PBXTargetDependency section */
258 | B02B1C9D1C9AEB39006760BF /* PBXTargetDependency */ = {
259 | isa = PBXTargetDependency;
260 | target = B02B1C861C9AEB39006760BF /* Sample */;
261 | targetProxy = B02B1C9C1C9AEB39006760BF /* PBXContainerItemProxy */;
262 | };
263 | /* End PBXTargetDependency section */
264 |
265 | /* Begin PBXVariantGroup section */
266 | B02B1C8E1C9AEB39006760BF /* Main.storyboard */ = {
267 | isa = PBXVariantGroup;
268 | children = (
269 | B02B1C8F1C9AEB39006760BF /* Base */,
270 | );
271 | name = Main.storyboard;
272 | sourceTree = "";
273 | };
274 | B02B1C931C9AEB39006760BF /* LaunchScreen.storyboard */ = {
275 | isa = PBXVariantGroup;
276 | children = (
277 | B02B1C941C9AEB39006760BF /* Base */,
278 | );
279 | name = LaunchScreen.storyboard;
280 | sourceTree = "";
281 | };
282 | /* End PBXVariantGroup section */
283 |
284 | /* Begin XCBuildConfiguration section */
285 | B02B1CA21C9AEB39006760BF /* Debug */ = {
286 | isa = XCBuildConfiguration;
287 | buildSettings = {
288 | ALWAYS_SEARCH_USER_PATHS = NO;
289 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
290 | CLANG_CXX_LIBRARY = "libc++";
291 | CLANG_ENABLE_MODULES = YES;
292 | CLANG_ENABLE_OBJC_ARC = YES;
293 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
294 | CLANG_WARN_BOOL_CONVERSION = YES;
295 | CLANG_WARN_COMMA = YES;
296 | CLANG_WARN_CONSTANT_CONVERSION = YES;
297 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
298 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
299 | CLANG_WARN_EMPTY_BODY = YES;
300 | CLANG_WARN_ENUM_CONVERSION = YES;
301 | CLANG_WARN_INFINITE_RECURSION = YES;
302 | CLANG_WARN_INT_CONVERSION = YES;
303 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
304 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
305 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
306 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
307 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
308 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
309 | CLANG_WARN_STRICT_PROTOTYPES = YES;
310 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
311 | CLANG_WARN_UNREACHABLE_CODE = YES;
312 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
313 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
314 | COPY_PHASE_STRIP = NO;
315 | DEBUG_INFORMATION_FORMAT = dwarf;
316 | ENABLE_STRICT_OBJC_MSGSEND = YES;
317 | ENABLE_TESTABILITY = YES;
318 | GCC_C_LANGUAGE_STANDARD = gnu99;
319 | GCC_DYNAMIC_NO_PIC = NO;
320 | GCC_NO_COMMON_BLOCKS = YES;
321 | GCC_OPTIMIZATION_LEVEL = 0;
322 | GCC_PREPROCESSOR_DEFINITIONS = (
323 | "DEBUG=1",
324 | "$(inherited)",
325 | );
326 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
327 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
328 | GCC_WARN_UNDECLARED_SELECTOR = YES;
329 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
330 | GCC_WARN_UNUSED_FUNCTION = YES;
331 | GCC_WARN_UNUSED_VARIABLE = YES;
332 | IPHONEOS_DEPLOYMENT_TARGET = 12.0;
333 | MTL_ENABLE_DEBUG_INFO = YES;
334 | ONLY_ACTIVE_ARCH = YES;
335 | SDKROOT = iphoneos;
336 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
337 | SWIFT_SWIFT3_OBJC_INFERENCE = Off;
338 | };
339 | name = Debug;
340 | };
341 | B02B1CA31C9AEB39006760BF /* Release */ = {
342 | isa = XCBuildConfiguration;
343 | buildSettings = {
344 | ALWAYS_SEARCH_USER_PATHS = NO;
345 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
346 | CLANG_CXX_LIBRARY = "libc++";
347 | CLANG_ENABLE_MODULES = YES;
348 | CLANG_ENABLE_OBJC_ARC = YES;
349 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
350 | CLANG_WARN_BOOL_CONVERSION = YES;
351 | CLANG_WARN_COMMA = YES;
352 | CLANG_WARN_CONSTANT_CONVERSION = YES;
353 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
354 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
355 | CLANG_WARN_EMPTY_BODY = YES;
356 | CLANG_WARN_ENUM_CONVERSION = YES;
357 | CLANG_WARN_INFINITE_RECURSION = YES;
358 | CLANG_WARN_INT_CONVERSION = YES;
359 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
360 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
361 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
362 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
363 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
364 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
365 | CLANG_WARN_STRICT_PROTOTYPES = YES;
366 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
367 | CLANG_WARN_UNREACHABLE_CODE = YES;
368 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
369 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
370 | COPY_PHASE_STRIP = NO;
371 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
372 | ENABLE_NS_ASSERTIONS = NO;
373 | ENABLE_STRICT_OBJC_MSGSEND = YES;
374 | GCC_C_LANGUAGE_STANDARD = gnu99;
375 | GCC_NO_COMMON_BLOCKS = YES;
376 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
377 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
378 | GCC_WARN_UNDECLARED_SELECTOR = YES;
379 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
380 | GCC_WARN_UNUSED_FUNCTION = YES;
381 | GCC_WARN_UNUSED_VARIABLE = YES;
382 | IPHONEOS_DEPLOYMENT_TARGET = 12.0;
383 | MTL_ENABLE_DEBUG_INFO = NO;
384 | SDKROOT = iphoneos;
385 | SWIFT_COMPILATION_MODE = wholemodule;
386 | SWIFT_OPTIMIZATION_LEVEL = "-O";
387 | SWIFT_SWIFT3_OBJC_INFERENCE = Off;
388 | VALIDATE_PRODUCT = YES;
389 | };
390 | name = Release;
391 | };
392 | B02B1CA51C9AEB39006760BF /* Debug */ = {
393 | isa = XCBuildConfiguration;
394 | buildSettings = {
395 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
396 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
397 | DEVELOPMENT_TEAM = T33NHY384Q;
398 | INFOPLIST_FILE = Sample/Info.plist;
399 | IPHONEOS_DEPLOYMENT_TARGET = 14.0;
400 | LD_RUNPATH_SEARCH_PATHS = (
401 | "$(inherited)",
402 | "@executable_path/Frameworks",
403 | );
404 | PRODUCT_BUNDLE_IDENTIFIER = ichise.Sample;
405 | PRODUCT_NAME = "$(TARGET_NAME)";
406 | PROVISIONING_PROFILE_SPECIFIER = "";
407 | SWIFT_VERSION = 4.2;
408 | };
409 | name = Debug;
410 | };
411 | B02B1CA61C9AEB39006760BF /* Release */ = {
412 | isa = XCBuildConfiguration;
413 | buildSettings = {
414 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
415 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
416 | DEVELOPMENT_TEAM = T33NHY384Q;
417 | INFOPLIST_FILE = Sample/Info.plist;
418 | IPHONEOS_DEPLOYMENT_TARGET = 14.0;
419 | LD_RUNPATH_SEARCH_PATHS = (
420 | "$(inherited)",
421 | "@executable_path/Frameworks",
422 | );
423 | PRODUCT_BUNDLE_IDENTIFIER = ichise.Sample;
424 | PRODUCT_NAME = "$(TARGET_NAME)";
425 | PROVISIONING_PROFILE_SPECIFIER = "";
426 | SWIFT_VERSION = 4.2;
427 | };
428 | name = Release;
429 | };
430 | B02B1CA81C9AEB39006760BF /* Debug */ = {
431 | isa = XCBuildConfiguration;
432 | buildSettings = {
433 | BUNDLE_LOADER = "$(TEST_HOST)";
434 | DEVELOPMENT_TEAM = T33NHY384Q;
435 | INFOPLIST_FILE = SampleTests/Info.plist;
436 | LD_RUNPATH_SEARCH_PATHS = (
437 | "$(inherited)",
438 | "@executable_path/Frameworks",
439 | "@loader_path/Frameworks",
440 | );
441 | PRODUCT_BUNDLE_IDENTIFIER = ichise.SampleTests;
442 | PRODUCT_NAME = "$(TARGET_NAME)";
443 | SWIFT_VERSION = 4.2;
444 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample";
445 | };
446 | name = Debug;
447 | };
448 | B02B1CA91C9AEB39006760BF /* Release */ = {
449 | isa = XCBuildConfiguration;
450 | buildSettings = {
451 | BUNDLE_LOADER = "$(TEST_HOST)";
452 | DEVELOPMENT_TEAM = T33NHY384Q;
453 | INFOPLIST_FILE = SampleTests/Info.plist;
454 | LD_RUNPATH_SEARCH_PATHS = (
455 | "$(inherited)",
456 | "@executable_path/Frameworks",
457 | "@loader_path/Frameworks",
458 | );
459 | PRODUCT_BUNDLE_IDENTIFIER = ichise.SampleTests;
460 | PRODUCT_NAME = "$(TARGET_NAME)";
461 | SWIFT_VERSION = 4.2;
462 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample";
463 | };
464 | name = Release;
465 | };
466 | /* End XCBuildConfiguration section */
467 |
468 | /* Begin XCConfigurationList section */
469 | B02B1C821C9AEB39006760BF /* Build configuration list for PBXProject "Sample" */ = {
470 | isa = XCConfigurationList;
471 | buildConfigurations = (
472 | B02B1CA21C9AEB39006760BF /* Debug */,
473 | B02B1CA31C9AEB39006760BF /* Release */,
474 | );
475 | defaultConfigurationIsVisible = 0;
476 | defaultConfigurationName = Release;
477 | };
478 | B02B1CA41C9AEB39006760BF /* Build configuration list for PBXNativeTarget "Sample" */ = {
479 | isa = XCConfigurationList;
480 | buildConfigurations = (
481 | B02B1CA51C9AEB39006760BF /* Debug */,
482 | B02B1CA61C9AEB39006760BF /* Release */,
483 | );
484 | defaultConfigurationIsVisible = 0;
485 | defaultConfigurationName = Release;
486 | };
487 | B02B1CA71C9AEB39006760BF /* Build configuration list for PBXNativeTarget "SampleTests" */ = {
488 | isa = XCConfigurationList;
489 | buildConfigurations = (
490 | B02B1CA81C9AEB39006760BF /* Debug */,
491 | B02B1CA91C9AEB39006760BF /* Release */,
492 | );
493 | defaultConfigurationIsVisible = 0;
494 | defaultConfigurationName = Release;
495 | };
496 | /* End XCConfigurationList section */
497 |
498 | /* Begin XCRemoteSwiftPackageReference section */
499 | 3C2E27752951DA9500F47388 /* XCRemoteSwiftPackageReference "Alamofire" */ = {
500 | isa = XCRemoteSwiftPackageReference;
501 | repositoryURL = "https://github.com/Alamofire/Alamofire";
502 | requirement = {
503 | kind = upToNextMajorVersion;
504 | minimumVersion = 5.0.0;
505 | };
506 | };
507 | /* End XCRemoteSwiftPackageReference section */
508 |
509 | /* Begin XCSwiftPackageProductDependency section */
510 | 3C2E27732951D97000F47388 /* TIFeedParser */ = {
511 | isa = XCSwiftPackageProductDependency;
512 | productName = TIFeedParser;
513 | };
514 | 3C2E27762951DA9500F47388 /* Alamofire */ = {
515 | isa = XCSwiftPackageProductDependency;
516 | package = 3C2E27752951DA9500F47388 /* XCRemoteSwiftPackageReference "Alamofire" */;
517 | productName = Alamofire;
518 | };
519 | /* End XCSwiftPackageProductDependency section */
520 | };
521 | rootObject = B02B1C7F1C9AEB39006760BF /* Project object */;
522 | }
523 |
--------------------------------------------------------------------------------
/Sample/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Sample/Sample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Sample/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved:
--------------------------------------------------------------------------------
1 | {
2 | "object": {
3 | "pins": [
4 | {
5 | "package": "AEXML",
6 | "repositoryURL": "https://github.com/tadija/AEXML.git",
7 | "state": {
8 | "branch": null,
9 | "revision": "38f7d00b23ecd891e1ee656fa6aeebd6ba04ecc3",
10 | "version": "4.6.1"
11 | }
12 | },
13 | {
14 | "package": "Alamofire",
15 | "repositoryURL": "https://github.com/Alamofire/Alamofire",
16 | "state": {
17 | "branch": null,
18 | "revision": "78424be314842833c04bc3bef5b72e85fff99204",
19 | "version": "5.6.4"
20 | }
21 | },
22 | {
23 | "package": "SwiftDate",
24 | "repositoryURL": "https://github.com/malcommac/SwiftDate",
25 | "state": {
26 | "branch": null,
27 | "revision": "5d943224c3bb173e6ecf27295611615eba90c80e",
28 | "version": "7.0.0"
29 | }
30 | }
31 | ]
32 | },
33 | "version": 1
34 | }
35 |
--------------------------------------------------------------------------------
/Sample/Sample/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // Sample
4 | //
5 | // Created by tichise on 2016年3月17日 16/03/17.
6 | // Copyright © 2016年 tichise. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(_ application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(_ application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(_ application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(_ application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(_ application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/Sample/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | }
43 | ],
44 | "info" : {
45 | "version" : 1,
46 | "author" : "xcode"
47 | }
48 | }
--------------------------------------------------------------------------------
/Sample/Sample/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Sample/Sample/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
36 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/Sample/Sample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | NSAppTransportSecurity
26 |
27 | NSAllowsArbitraryLoads
28 |
29 |
30 | UILaunchStoryboardName
31 | LaunchScreen
32 | UIMainStoryboardFile
33 | Main
34 | UIRequiredDeviceCapabilities
35 |
36 | armv7
37 |
38 | UISupportedInterfaceOrientations
39 |
40 | UIInterfaceOrientationPortrait
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Sample/Sample/ItemsController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ItemsController.swift
3 | // Sample
4 | //
5 | // Created by tichise on 2016年3月17日 16/03/17.
6 | // Copyright © 2016年 tichise. All rights reserved.
7 | //
8 |
9 |
10 | import UIKit
11 | import SafariServices
12 | import TIFeedParser
13 | import Alamofire
14 |
15 | class ItemsController: UITableViewController {
16 |
17 | var items : Array- = []
18 | var entries : Array = []
19 |
20 | override func viewDidLoad() {
21 | super.viewDidLoad()
22 |
23 | loadRSS()
24 | loadAtom()
25 | }
26 |
27 | override func didReceiveMemoryWarning() {
28 | super.didReceiveMemoryWarning()
29 | }
30 |
31 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
32 | return items.count
33 | }
34 |
35 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
36 | let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
37 |
38 | let item = self.items[indexPath.row]
39 | cell.textLabel?.text = item.title
40 |
41 | if let pubDate = item.pubDate {
42 | cell.detailTextLabel?.text = self.getPubDateString(pubDate: pubDate)
43 | }
44 |
45 | return cell
46 | }
47 |
48 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
49 |
50 | let item = self.items[indexPath.row]
51 |
52 | guard let link = item.link else {
53 | return
54 | }
55 |
56 | guard let url = URL(string: link) else {
57 | return
58 | }
59 |
60 | let safariViewController = SFSafariViewController(url: url)
61 | present(safariViewController, animated: true, completion: nil)
62 | }
63 |
64 | func loadRSS() {
65 |
66 | let feedUrlString = "https://news.google.com/_/rss/topics/CAAqKAgKIiJDQkFTRXdvSkwyMHZNR1ptZHpWbUVnSnFZUm9DU2xBb0FBUAE?hl=ja&gl=JP&ceid=JP:ja"
67 |
68 | AF.request(feedUrlString).responseData { (response) in
69 | if 200 != response.response?.statusCode {
70 | return
71 | }
72 |
73 | guard let data = response.data else {
74 | return
75 | }
76 |
77 | TIFeedParser.parseRSS(xmlData: data, onSuccess: { (channel) in
78 | self.items = channel.items
79 | self.tableView.reloadData()
80 | }, onNotFound: {
81 | print("onNotFound")
82 | }, onFailure: { (error) in
83 | })
84 | }
85 | }
86 |
87 | func loadAtom() {
88 |
89 | let feedUrlString = "https://news.google.com/_/atom/topics/CAAqKAgKIiJDQkFTRXdvSkwyMHZNR1ptZHpWbUVnSnFZUm9DU2xBb0FBUAE?hl=ja&gl=JP&ceid=JP:ja"
90 |
91 |
92 | AF.request(feedUrlString).responseData { (response) in
93 | if 200 != response.response?.statusCode {
94 | return
95 | }
96 |
97 | guard let data = response.data else {
98 | return
99 | }
100 |
101 | TIFeedParser.parseRSS(xmlData: data, onSuccess: { (channel) in
102 | self.items = channel.items
103 | self.tableView.reloadData()
104 | }, onNotFound: {
105 | print("onNotFound")
106 | }, onFailure: { (error) in
107 | })
108 |
109 | }
110 | }
111 |
112 | func getPubDateString(pubDate: Date) ->String {
113 | let format = DateFormatter()
114 | format.dateFormat = "yyyy/M/d HH:mm"
115 |
116 | let pubDateString = format.string(from: pubDate)
117 | return pubDateString
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/Sample/SampleTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Sample/SampleTests/SampleTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SampleTests.swift
3 | // SampleTests
4 | //
5 | // Created by tichise on 2016年3月17日 16/03/17.
6 | // Copyright © 2016年 tichise. All rights reserved.
7 | //
8 |
9 | import XCTest
10 | import TIFeedParser
11 | import Alamofire
12 |
13 | @testable import Sample
14 |
15 | class SampleTests: XCTestCase {
16 |
17 | override func setUp() {
18 | super.setUp()
19 |
20 | // 失敗後も続ける
21 | continueAfterFailure = true
22 | }
23 |
24 | override func tearDown() {
25 | super.tearDown()
26 | }
27 |
28 | func testRSS2() {
29 | let expectation = self.expectation(description: "testRSS2.0")
30 |
31 | let feedUrlString:String = "https://news.google.com/news?ned=us&ie=UTF-8&oe=UTF-8&q=nasa&output=rss&num=3&hl=ja"
32 |
33 | Alamofire.request(feedUrlString).response { response in
34 | if let data = response.data, let _ = String(data: data, encoding: .utf8) {
35 |
36 | TIFeedParser.parseRSS(xmlData: data, onSuccess: { (channel) in
37 |
38 | XCTAssertNotNil(channel.title)
39 | XCTAssertNotNil(channel.link)
40 | XCTAssertNotNil(channel.description)
41 | XCTAssertNotNil(channel.items)
42 | XCTAssertTrue(channel.items.count > 0)
43 |
44 | if let title = channel.title {print(title)}
45 | if let link = channel.link {print(link)}
46 | if let description = channel.description {print(description)}
47 |
48 | let item = channel.items[0]
49 |
50 | XCTAssertNotNil(item.title)
51 | XCTAssertNotNil(item.link)
52 | XCTAssertNotNil(item.description)
53 | // XCTAssertNotNil(item.contentEncoded)
54 | XCTAssertNotNil(item.categories)
55 | // XCTAssertNotNil(item.thumbnail)
56 | XCTAssertNotNil(item.pubDate)
57 |
58 | if let title = item.title {print(title)}
59 | if let link = channel.link {print(link)}
60 | if let description = item.description {print(description)}
61 | if let thumbnail = item.thumbnail {print(thumbnail)}
62 |
63 | print(item.categories)
64 |
65 | XCTAssertTrue(true)
66 | expectation.fulfill()
67 |
68 | }, onNotFound: {
69 | }, onFailure: { (error) in
70 | })
71 | }
72 | }
73 |
74 | waitForExpectations(timeout: 5.0, handler: nil)
75 | }
76 |
77 |
78 | func testRSS1() {
79 | let expectation = self.expectation(description: "testRSS1.0")
80 |
81 | let feedUrlString:String = "http://feeds.feedburner.com/hatena/b/hotentry"
82 |
83 | Alamofire.request(feedUrlString).response { response in
84 | if let data = response.data, let _ = String(data: data, encoding: .utf8) {
85 |
86 | TIFeedParser.parseRSS(xmlData: data, onSuccess: { (channel) in
87 | XCTAssertNotNil(channel.title)
88 | XCTAssertNotNil(channel.link)
89 | XCTAssertNotNil(channel.description)
90 | XCTAssertNotNil(channel.items)
91 |
92 | if let title = channel.title {print(title)}
93 | if let link = channel.link {print(link)}
94 | if let description = channel.description {print(description)}
95 |
96 | XCTAssertTrue(channel.items.count > 0)
97 |
98 | let item = channel.items[0]
99 |
100 | XCTAssertNotNil(item.title)
101 | XCTAssertNotNil(item.link)
102 | XCTAssertNotNil(item.description)
103 | XCTAssertNotNil(item.contentEncoded)
104 |
105 | if let title = item.title {print(title)}
106 | if let link = channel.link {print(link)}
107 | if let description = item.description {print(description)}
108 | if let thumbnail = item.thumbnail {print(thumbnail)}
109 |
110 | XCTAssertTrue(true)
111 | expectation.fulfill()
112 | }, onNotFound: {
113 | }, onFailure: { (error) in
114 | })
115 | }
116 | }
117 |
118 | waitForExpectations(timeout: 5.0, handler: nil)
119 | }
120 |
121 | func testAtomGihyo() {
122 | let expectation = self.expectation(description: "testAtom")
123 |
124 | let feedUrlString:String = "http://gihyo.jp/feed/atom"
125 |
126 | Alamofire.request(feedUrlString).response { response in
127 | if let data = response.data, let _ = String(data: data, encoding: .utf8) {
128 |
129 |
130 | TIFeedParser.parseAtom(xmlData: data, onSuccess: { (feed) in
131 | XCTAssertNotNil(feed.id)
132 | XCTAssertNotNil(feed.title)
133 | XCTAssertNotNil(feed.updated)
134 |
135 | if let id = feed.id {print(id)}
136 | if let title = feed.title {print(title)}
137 | if let updated = feed.updated {print(updated)}
138 |
139 | XCTAssertNotNil(feed.entries)
140 | XCTAssertTrue(feed.entries.count > 0)
141 |
142 | let entry = feed.entries[0]
143 |
144 | XCTAssertNotNil(entry.id)
145 | XCTAssertNotNil(entry.title)
146 | XCTAssertNotNil(entry.updated)
147 | XCTAssertNotNil(entry.summary)
148 |
149 | if let id = entry.id {print(id)}
150 | if let title = entry.title {print(title)}
151 | if let updated = entry.updated {print(updated)}
152 | if let summary = entry.summary {print(summary)}
153 |
154 | XCTAssertTrue(true)
155 | expectation.fulfill()
156 | }, onNotFound: {
157 |
158 | }, onFailure: { (error) in
159 |
160 | })
161 | }
162 | }
163 |
164 | waitForExpectations(timeout: 5.0, handler: nil)
165 | }
166 |
167 | func testAtomGoogle() {
168 | let expectation = self.expectation(description: "testAtom")
169 |
170 | let feedUrlString:String = "https://news.google.com/news?ned=us&ie=UTF-8&oe=UTF-8&q=nasa&output=atom&num=3&hl=ja"
171 |
172 | Alamofire.request(feedUrlString).response { response in
173 | if let data = response.data, let _ = String(data: data, encoding: .utf8) {
174 |
175 | TIFeedParser.parseAtom(xmlData: data, onSuccess: { (feed) in
176 | XCTAssertNotNil(feed.id)
177 | XCTAssertNotNil(feed.title)
178 | XCTAssertNotNil(feed.updated)
179 |
180 | if let id = feed.id {print(id)}
181 | if let title = feed.title {print(title)}
182 | if let updated = feed.updated {print(updated)}
183 |
184 | XCTAssertNotNil(feed.entries)
185 | XCTAssertTrue(feed.entries.count > 0)
186 |
187 | let entry = feed.entries[0]
188 |
189 | XCTAssertNotNil(entry.id)
190 | XCTAssertNotNil(entry.title)
191 | XCTAssertNotNil(entry.updated)
192 |
193 | if let id = entry.id {print(id)}
194 | if let title = entry.title {print(title)}
195 | if let updated = entry.updated {print(updated)}
196 |
197 | XCTAssertTrue(true)
198 | expectation.fulfill()
199 |
200 | }, onNotFound: {
201 | }, onFailure: { (error) in
202 | })
203 | }
204 | }
205 |
206 | waitForExpectations(timeout: 5.0, handler: nil)
207 | }
208 | }
209 |
--------------------------------------------------------------------------------
/Sources/Channel.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Channel.swift
3 | //
4 | // Created by tichise on 2016/03/17.
5 | // Copyright © 2016年 tichise. All rights reserved.
6 | //
7 |
8 | import Foundation
9 |
10 | public struct Channel {
11 |
12 | public internal(set) var title: String?
13 | public internal(set) var link: String?
14 | public internal(set) var description: String?
15 | public internal(set) var items: Array
- = []
16 |
17 | init() {}
18 |
19 | init(title: String?, link: String?, description: String?, items: Array
- ){
20 |
21 | self.title = title
22 | self.link = link
23 | self.description = description
24 | self.items = items
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/Entry.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Entry.swift
3 | //
4 | // Created by tichise on 2016/03/17.
5 | // Copyright © 2016年 tichise. All rights reserved.
6 | //
7 |
8 | import Foundation
9 |
10 | public struct Entry {
11 |
12 | public internal(set) var id:String?
13 | public internal(set) var title:String?
14 | public internal(set) var link:String?
15 | public internal(set) var updated:Date?
16 | public internal(set) var summary:String?
17 |
18 | init(id: String?, title: String?, link: String?, updated: Date?, summary: String?){
19 |
20 | self.id = id
21 | self.title = title
22 | self.link = link
23 | self.updated = updated
24 | self.summary = summary
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/Feed.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Feed.swift
3 | //
4 | // Created by tichise on 2016/03/17.
5 | // Copyright © 2016年 tichise. All rights reserved.
6 | //
7 |
8 | import Foundation
9 |
10 | public struct Feed {
11 |
12 | public internal(set) var id: String?
13 | public internal(set) var title: String?
14 | public internal(set) var updated: Date?
15 | public internal(set) var entries: Array = []
16 |
17 | init() {}
18 |
19 | init(id: String?, title: String?, updated: Date?, entries: Array){
20 |
21 | self.id = id
22 | self.title = title
23 | self.updated = updated
24 | self.entries = entries
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/Item.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Item.swift
3 | //
4 | // Created by tichise on 2016/03/17.
5 | // Copyright © 2016年 tichise. All rights reserved.
6 | //
7 |
8 | import Foundation
9 |
10 | public struct Item: Identifiable {
11 | public let id = UUID()
12 | public internal(set) var title: String?
13 | public internal(set) var link: String?
14 | public internal(set) var pubDate: Date?
15 | public internal(set) var description: String?
16 | public internal(set) var contentEncoded: String?
17 | public internal(set) var thumbnail: String?
18 | public internal(set) var categories: Array = []
19 |
20 | public init(title: String?, link: String?, pubDate: Date?, description: String?, contentEncoded: String?, thumbnail: String?, categories: Array){
21 |
22 | self.title = title
23 | self.link = link
24 | self.pubDate = pubDate
25 | self.description = description
26 | self.contentEncoded = contentEncoded
27 | self.thumbnail = thumbnail
28 | self.categories = categories
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Sources/TIFeedParser.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TIFeedParser.swift
3 | //
4 | // Created by tichise on 2016/03/17.
5 | // Copyright © 2016年 tichise. All rights reserved.
6 | //
7 |
8 | import Foundation
9 | import AEXML
10 | import SwiftDate
11 |
12 | public class TIFeedParser {
13 |
14 | public static func parseRSS(xmlData:Data, onSuccess: @escaping (Channel) -> (), onNotFound: @escaping () -> (), onFailure: @escaping (Error?) -> ()) {
15 |
16 |
17 | DispatchQueue.global(qos: .default).async {
18 | // サブスレッド(バックグラウンド)で実行する方を書く
19 | do {
20 |
21 | let xmlDoc = try AEXMLDocument(xml: xmlData)
22 | var existChannel = false
23 |
24 | for child in xmlDoc.root.children {
25 | if (child.name == "channel") {
26 | existChannel = true
27 | }
28 | }
29 |
30 |
31 | if (existChannel) {
32 | if (xmlDoc.root.children.count == 1) {
33 | // rss2.0
34 | let channel = parseRSS2(xmlDoc: xmlDoc)
35 |
36 | DispatchQueue.main.async {
37 | onSuccess(channel)
38 | }
39 | } else {
40 | // rss1.0
41 | let channel = parseRSS1(xmlDoc: xmlDoc)
42 |
43 | DispatchQueue.main.async {
44 | onSuccess(channel)
45 | }
46 | }
47 | } else {
48 | DispatchQueue.main.async {
49 | onNotFound()
50 | }
51 | }
52 | }
53 | catch let error {
54 | DispatchQueue.main.async {
55 | onFailure(error)
56 | }
57 | }
58 | }
59 | }
60 |
61 | public static func parseAtom(xmlData: Data, onSuccess: @escaping (Feed) -> (), onNotFound: @escaping () -> (), onFailure: @escaping (Error?) -> ()) {
62 |
63 | DispatchQueue.global(qos: .default).async {
64 | do {
65 |
66 | let xmlDoc = try AEXMLDocument(xml: xmlData)
67 | var existChannel = false
68 |
69 | for child in xmlDoc.root.children {
70 | if (child.name == "channel") {
71 | existChannel = true
72 | }
73 | }
74 |
75 | if (existChannel) {
76 | DispatchQueue.main.async {
77 | onNotFound()
78 | }
79 | } else {
80 | // atom
81 | let feed = parseAtom(xmlDoc: xmlDoc)
82 |
83 | DispatchQueue.main.async {
84 | onSuccess(feed)
85 | }
86 | }
87 | }
88 | catch let error {
89 | DispatchQueue.main.async {
90 | onFailure(error)
91 | }
92 | }
93 | }
94 | }
95 |
96 | private static func parseRSS1(xmlDoc: AEXMLDocument) -> Channel {
97 | var items:Array
- = []
98 |
99 | if let all = xmlDoc.root["item"].all {
100 | for itemObject in all {
101 |
102 | let title = itemObject["title"].value
103 | let link = itemObject["link"].value
104 |
105 | var dcDate: Date? = nil
106 |
107 | if let dcDateString = itemObject["dc:date"].value {
108 | dcDate = dcDateString.toDate()?.date
109 | }
110 |
111 | let description = itemObject["description"].value
112 | let contentEncoded = itemObject["content:encoded"].value
113 |
114 | let item = Item(title: title, link: link, pubDate: dcDate, description: description, contentEncoded:contentEncoded, thumbnail:nil, categories:[])
115 | items.append(item)
116 | }
117 | }
118 |
119 | let title = xmlDoc.root["channel"]["title"].value
120 | let link = xmlDoc.root["channel"]["link"].value
121 | let description = xmlDoc.root["channel"]["description"].value
122 |
123 | let channel = Channel(title: title, link: link, description: description, items: items)
124 |
125 | return channel
126 | }
127 |
128 | private static func parseRSS2(xmlDoc:AEXMLDocument) -> Channel {
129 | var items:Array
- = Array()
130 |
131 | if let all = xmlDoc.root["channel"]["item"].all {
132 | for itemObject in all {
133 |
134 | let title = itemObject["title"].value
135 | let link = itemObject["link"].value
136 |
137 | var pubDate: Date? = nil
138 |
139 | if let pubDateString = itemObject["pubDate"].value {
140 | pubDate = pubDateString.toDate(style: StringToDateStyles.rss)?.date
141 | }
142 |
143 | let description = itemObject["description"].value
144 |
145 | var categories:Array = []
146 |
147 | if let all = itemObject["category"].all {
148 | for category in all {
149 | if let categoryTitle = category.value {
150 | categories.append(categoryTitle)
151 | }
152 | }
153 | }
154 |
155 | let contentEncoded = itemObject["content:encoded"].value
156 |
157 | var thumbnail:String?
158 |
159 | if let mediaThumbnail = itemObject["media:thumbnail"].value {
160 |
161 | if (mediaThumbnail != "element not found") {
162 |
163 | if let mediaThumbnails = itemObject["media:thumbnail"].all {
164 | if (mediaThumbnails.count > 0) {
165 | thumbnail = mediaThumbnails[1].attributes["url"]
166 | }
167 | }
168 | }
169 | }
170 |
171 | let item = Item(title: title, link: link, pubDate: pubDate, description: description, contentEncoded: contentEncoded, thumbnail:thumbnail, categories:categories)
172 |
173 | items.append(item)
174 | }
175 | }
176 |
177 | let title = xmlDoc.root["channel"]["title"].value
178 | let link = xmlDoc.root["channel"]["link"].value
179 | let description = xmlDoc.root["channel"]["description"].value
180 |
181 | let channel = Channel(title: title, link: link, description: description, items: items)
182 |
183 | return channel
184 | }
185 |
186 | private static func parseAtom(xmlDoc:AEXMLDocument) -> Feed {
187 | var entries:Array = Array()
188 |
189 | if let all = xmlDoc.root["entry"].all {
190 | for entryObject in all {
191 |
192 | let id = entryObject["id"].value
193 | let title = entryObject["title"].value
194 | let link = entryObject["link"].attributes["href"]
195 |
196 | var updated: Date? = nil
197 |
198 | if let updatedString = entryObject["updated"].value {
199 | updated = updatedString.toDate()?.date
200 | }
201 |
202 | let summary = entryObject["summary"].value
203 |
204 | let entry = Entry(id: id, title: title, link: link, updated: updated, summary: summary)
205 | entries.append(entry)
206 | }
207 | }
208 |
209 | let id = xmlDoc.root["id"].value
210 | let title = xmlDoc.root["title"].value
211 |
212 |
213 | var updated: Date? = nil
214 |
215 | if let updatedString = xmlDoc.root["updated"].value {
216 | updated = updatedString.toDate()?.date
217 | }
218 |
219 | let feed = Feed(id: id, title: title, updated: updated, entries: entries)
220 |
221 | return feed
222 | }
223 | }
224 |
--------------------------------------------------------------------------------
/TIFeedParser.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = 'TIFeedParser'
3 | s.version = '2.3.1'
4 | s.swift_versions = '5.0'
5 | s.license = {
6 | :type => "MIT",
7 | :text => <<-LICENSE
8 | Copyright (c) 2015 - 2022 Takuya Ichise
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 | LICENSE
13 | }
14 | s.summary = 'TIFeedParser is an parser for RSS, built on AEXML.'
15 | s.homepage = 'https://github.com/tichise/TIFeedParser'
16 | s.social_media_url = 'http://twitter.com/tichise'
17 | s.author = "Takuya Ichise"
18 | s.source = { :git => 'https://github.com/tichise/TIFeedParser.git', :tag => s.version }
19 |
20 | s.ios.deployment_target = '14.0'
21 |
22 | s.source_files = 'Sources/*.swift'
23 | s.requires_arc = true
24 |
25 | s.dependency 'AEXML'
26 | s.dependency 'SwiftDate'
27 | end
28 |
--------------------------------------------------------------------------------