Code: String (describing: nsnumbervalue ) (or) String (nsnumbervalue ) The above code is used to convert the NsNumber to String. NSDate To String String (describing: Date ) Combine NsNumber and string to String Code: String ( " \ ( nsnumbervalue ) km" ) Convert Float to String Code: String (describing: floatvalue )
Problem: How to parse the string that contains the json value? Solution: extension String { var parseJSONString : AnyObject? { let data = self .data(using: String .Encoding.utf8, allowLossyConversion: false ) if let jsonData = data { // Will return an object or nil if JSON decoding fails do { let message = try JSONSerialization.jsonObject(with: jsonData, options:.mutableContainers) if let jsonResult = message as ? NSMutableDictionary { return jsonResult //Will return the json array output ...
We cannot convert string directly to NSNumber. So we will convert string to Int then convert Int to NSNumber. Code: NSNumber (value: Int ( "String" )!)
Comments
Post a Comment