0
我試圖讓註冊與解析,我的代碼看起來是這樣的:檢查所提供的字段是零,解析,斯威夫特
@IBAction func signUpTapped(sender: AnyObject) {
let user = PFUser()
// User details..
// Profile picture..
user.username = username.text
user.password = password.text
user.email = email.text
let imageData = UIImagePNGRepresentation(dp.image!)
let imageFile = PFFile(name: "file", data: imageData!)
user["profile_picture"] = imageFile
let fullName = fullname.text
var myStringArr = fullName!.componentsSeparatedByString(" ")
user["first_name"] = myStringArr[0]
user["last_name"] = myStringArr[1]
user.signUpInBackgroundWithBlock({ (succes, error) -> Void in
if error != nil {
print("error")
} else {
print("signedUp")
}
})
}
我要顯示一個警告,如果username, password, email or fullname
是零。 我怎樣才能使一個檢查有效地一行代碼就行,而不是單獨檢查他們..
我想這太:
if user.username == nil | user.email == nil | user.password == nil | user["first_name"] == nil | user["last_name"] == nil {
} else {
}
,但是這也給了我一個錯誤:Expression was too complex to be solved.
感謝您的時間。
使用'| |'不''|' – dan
fyi,單個|是一個按位或或見https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html –