Type of expression is ambiguous without more context

var current_date = NSDate()

var dateFormatter = NSDateFormatter()

dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss"

var strDate = dateFormatter.stringFromDate(current_date)

dateFormatter.dateFromString(strDate)

var fname = personalFname.text

var lname = personalLname.text

var email = personalEmail.text

var gender = ""

var date = convDate

if personalGenderSwitch.on {

gender = "Female"

} else {

gender = "Male"

}

var country_code = personalCountryCode.text

var phone = personalPhoneNo.text

if personal_id == nil {

if let err = SD.executeChange("INSERT INTO personal_info(user_id, fname, lname, gender, dob, country_code, phone, created_at) values (?,?,?,?,?,?,?,?)", withArgs: [email, fname, lname, gender, date, country_code, phone, strDate]) {

let alert = UIAlertView()

alert.title = "Table"

alert.message = "Error inserting"

alert.addButtonWithTitle("Ok")

alert.show()

} else{

let alert = UIAlertView()

alert.title = "Table"

alert.message = "successfully inserted"

alert.addButtonWithTitle("Ok")

alert.show()

}

} else {

if let err_update = SD.executeChange("UPDATE personal_info SET fname = ?, lname = ?, gender = ?, dob = ?, country_code = ?, phone = ?, updated_at = ? WHERE personal_info_id = ?", withArgs: [fname, lname, gender, date, country_code, phone, strDate, personal_id!]) {

let alert = UIAlertView()

alert.title = "Table"

alert.message = "Error updating"

alert.addButtonWithTitle("Ok")

alert.show()

} else {

let alert = UIAlertView()

alert.title = "Table"

alert.message = "Record updated"

alert.addButtonWithTitle("Ok")

alert.show()

}

}




why am i getting the error "Type of expression is ambiguous without more context" in the place of withArgs[ ] ?? i got this error when i recently updated the xcode to 7.0.1 from version 6.4

var fname = personalFname.text
var lname = personalLname.text
var email = personalEmail.text


If these are UITextField's, they return Optional Strings. So the fname, lname and email become


var fname: String? = personalFname.text
var lname: String? = personalLname.text
var email: String? = personalEmail.text


I guess withArgs expects array of Strings. So you have to for example use empty strings if UITextField's text property is nil.


var fname = personalFname.text ?? ""
var lname = personalLname.text ?? ""
var email = personalEmail.text ?? ""

Regardless of everything else, your date formatter code has problems. QA1480 NSDateFormatter and Internet Dates explains the issue.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Type of expression is ambiguous without more context
 
 
Q