@@ -29,9 +29,9 @@ public class LclJSONSerialization {
29
29
private static let NULL = NSString ( string: " null " )
30
30
31
31
32
- public class func isValidJSONObject( obj: Any ) -> Bool {
32
+ public class func isValidJSONObject( _ obj: Any ) -> Bool {
33
33
// TODO: - revisit this once bridging story gets fully figured out
34
- func isValidJSONObjectInternal( obj: Any ) -> Bool {
34
+ func isValidJSONObjectInternal( _ obj: Any ) -> Bool {
35
35
// object is Swift.String or NSNull
36
36
if obj is String || obj is Int || obj is Bool || obj is NSNull {
37
37
return true
@@ -97,29 +97,29 @@ public class LclJSONSerialization {
97
97
return isValidJSONObjectInternal ( obj)
98
98
}
99
99
100
- public class func dataWithJSONObject( obj: Any , options: NSJSONWritingOptions ) throws -> NSData
100
+ public class func dataWithJSONObject( _ obj: Any , options: NSJSONWritingOptions ) throws -> NSData
101
101
{
102
102
let result = NSMutableData ( )
103
103
104
104
try writeJson ( obj, options: options) { ( str: NSString ? ) in
105
105
if let str = str {
106
- result. appendBytes ( str. cStringUsingEncoding ( NSUTF8StringEncoding) , length: str. lengthOfBytesUsingEncoding ( NSUTF8StringEncoding) )
106
+ result. appendBytes ( str. cStringUsingEncoding ( NSUTF8StringEncoding) ! , length: str. lengthOfBytesUsingEncoding ( NSUTF8StringEncoding) )
107
107
}
108
108
}
109
109
110
110
return result
111
111
}
112
112
113
113
/* Helper function to enable writing to NSData as well as NSStream */
114
- private static func writeJson( obj: Any , options opt: NSJSONWritingOptions , writer: ( NSString ? ) -> Void ) throws {
114
+ private static func writeJson( _ obj: Any , options opt: NSJSONWritingOptions , writer: ( NSString ? ) -> Void ) throws {
115
115
let prettyPrint = opt. rawValue & NSJSONWritingOptions . PrettyPrinted. rawValue != 0
116
116
let padding : NSString ? = prettyPrint ? NSString ( string: " " ) : nil
117
117
118
118
try writeJsonValue ( obj, padding: padding, writer: writer)
119
119
}
120
120
121
121
/* Write out a JSON value (simple value, object, or array) */
122
- private static func writeJsonValue( obj: Any , padding: NSString ? , writer: ( NSString ? ) -> Void ) throws {
122
+ private static func writeJsonValue( _ obj: Any , padding: NSString ? , writer: ( NSString ? ) -> Void ) throws {
123
123
if obj is String {
124
124
writer ( " \" " )
125
125
writer ( ( obj as! String ) . bridge ( ) )
@@ -153,7 +153,7 @@ public class LclJSONSerialization {
153
153
}
154
154
155
155
/* Write out a dictionary as a JSON object */
156
- private static func writeJsonObject( pairs: Array < Any > , padding: NSString ? , writer: ( NSString ? ) -> Void ) throws {
156
+ private static func writeJsonObject( _ pairs: Array < Any > , padding: NSString ? , writer: ( NSString ? ) -> Void ) throws {
157
157
let ( nestedPadding, startOfLine, endOfLine) = setupPadding ( padding)
158
158
let nameValueSeparator = NSString ( string: padding != nil ? " : " : " : " )
159
159
@@ -186,7 +186,7 @@ public class LclJSONSerialization {
186
186
}
187
187
188
188
/* Write out an array as a JSON Array */
189
- private static func writeJsonArray( obj: Array < Any > , padding: NSString ? , writer: ( NSString ? ) -> Void ) throws {
189
+ private static func writeJsonArray( _ obj: Array < Any > , padding: NSString ? , writer: ( NSString ? ) -> Void ) throws {
190
190
let ( nestedPadding, startOfLine, endOfLine) = setupPadding ( padding)
191
191
writer ( " [ " )
192
192
@@ -209,7 +209,7 @@ public class LclJSONSerialization {
209
209
210
210
Note: if padding is nil, then all padding, newlines etc., are suppressed
211
211
*/
212
- private static func setupPadding( padding: NSString ? ) -> ( NSString ? , NSString ? , NSString ? ) {
212
+ private static func setupPadding( _ padding: NSString ? ) -> ( NSString ? , NSString ? , NSString ? ) {
213
213
let nestedPadding : NSString ?
214
214
let startOfLine : NSString ?
215
215
let endOfLine : NSString ?
@@ -229,7 +229,7 @@ public class LclJSONSerialization {
229
229
return ( nestedPadding, startOfLine, endOfLine)
230
230
}
231
231
232
- private static func createWriteError( reason: String ) -> NSError {
232
+ private static func createWriteError( _ reason: String ) -> NSError {
233
233
let userInfo : [ String : Any ] = [ NSLocalizedDescriptionKey: JSON_WRITE_ERROR,
234
234
NSLocalizedFailureReasonErrorKey: reason]
235
235
return NSError ( domain: LclErrorDomain, code: 1 , userInfo: userInfo)
0 commit comments