I set the default string value using the operator. But am I getting an optional string?
request(.GET, CUSTOMER_URL, parameters: params, encoding: .URL).responseJSON { (request, response, result) -> Void in
var message = JSON(result.value ?? "")["message"].string ?? "Default value to make it nonOptional"
switch(result) {
case .Success(let json):
if let customer = JSON(json)["customer"].dictionaryObject {
GlobalCache.sharedInstance.setCustomer(customer)
}
completion(succeed: response?.statusCode == 200, message: message)
case .Failure(_,_):
completion(succeed: false, message: message)
}
}

Expected Behavior

Unexpected behavior

source
share