1
1
//
2
- // main.swift
3
- // update
4
- //
5
2
// Created by Apollo Zhu on 3/12/17.
6
- // Copyright © 2017 WWITDC. All rights reserved.
3
+ // This work is licensed under a
4
+ // Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
7
5
//
8
6
9
7
import Foundation
@@ -47,7 +45,7 @@ struct Resource: CustomStringConvertible {
47
45
} else if let resType = ResourceType . all. first ( where: { title. contains ( $0. rawValue) } ) {
48
46
type = resType
49
47
} else {
50
- fatalError ( " Unknown Raw Type " )
48
+ fatalError ( " Unknown Raw Type \( rawType ) " )
51
49
}
52
50
53
51
var parts : [ String ]
@@ -109,7 +107,11 @@ class ParsingDelegate: NSObject, XMLParserDelegate {
109
107
110
108
func parser( _ parser: XMLParser , foundCDATA CDATABlock: Data ) {
111
109
if isParsingTitle {
112
- title = String ( data: CDATABlock, encoding: . utf8) !
110
+ if let title = String ( data: CDATABlock, encoding: . utf8) {
111
+ self . title = title
112
+ } else {
113
+ fatalError ( " Unable to parse title from \( CDATABlock) " )
114
+ }
113
115
}
114
116
}
115
117
@@ -132,10 +134,9 @@ class ParsingDelegate: NSObject, XMLParserDelegate {
132
134
133
135
var out = " [返回主页](../README.md) / [Back to Main Page](../en/README.md) \n \n "
134
136
for (index, type) in ResourceType . all. enumerated ( ) {
135
- if sorted [ index] . count > 0 {
136
- out += " # \( type) \n \n "
137
- + " \( sorted [ index] . reduce ( " " ) { " \( $0) \( $1) \n " } ) \n "
138
- }
137
+ guard !sorted[ index] . isEmpty else { fatalError ( " Missing Resources of Type \( type) " ) }
138
+ out += " # \( type) \n \n "
139
+ + " \( sorted [ index] . reduce ( " " ) { " \( $0) \( $1) \n " } ) \n "
139
140
}
140
141
141
142
let cwd = CommandLine . arguments. first { $0. contains ( #file) } ?? FileManager . default. currentDirectoryPath
0 commit comments