xcode - iOS Swift 1.2 - Primitive Type Comparison Failure -


i have function gets , parses data firebase. have validation "parseusermodel) returns "bool" type if model meets requirements pass. set value validuser of bool type. model i'm pulling passes , returns boolean of true.

here's issue happens.

if(validuser) { ... code ... } fails though validuser "true".

i've played around actual return type , i've tried these things:

  1. validuser.boolvalue , setting inside if(validuser.boolvalue)
    • this fails
  2. setting if(validuser) { ... code ... }
    • this fails
  3. setting if(validuser == true) {..code..}
    • this fails
  4. setting if(validuser.boolvalue == true) {code}
    • this fails

i'm out of ideas why failing. i'm comparing primitive type (i'm assuming) primitive type.

my questions

  1. is 'true' keyword in swift not bool object type?
  2. why failing when i'm explicitly asking boolvalue?
  3. is swift bug should know about?
  4. is if statement not doing think should doing?

retrieve data function

public static func retrieveuserdata(user:usermodel, completion:(success:bool)->void){     if(user.username != nil){         let fbref = firebase(url: globalvariables().fb_base_url+"users/\(user.username)")         fbref.observesingleeventoftype(feventtype.value, withblock: { (snapshot) -> void in             if(snapshot.value != nil){                 let validuser:bool = usermodel.sharedinstance.parseuserdata(json(snapshot.value))                 println(validuser)                 println(validuser.boolvalue)                 if(validuser.boolvalue){                     completion(success: true)                 } else {                     completion(success: false)                 }             }         })     } } 

parse model , validate

public func parseuserdata(data:json) -> bool {     var uname:string!     var ufullname:string!      if let username = data["username"].string {         usermodel.sharedinstance.username = username     }      if let fullname = data["fullname"].string {         usermodel.sharedinstance.fullname = fullname     } else {         return false     }      if let biography = data["biography"].string {         usermodel.sharedinstance.biography = biography     }      if let email = data["email"].string {         usermodel.sharedinstance.email = email     }      if let plistid = data["playlistcollectionid"].string {         usermodel.sharedinstance.playlistcollectionid = plistid     } else {         //generate playlistcollectionid because user doesn't have 1         usermodel.sharedinstance.playlistcollectionid = nsuuid().uuidstring     }     if(usermodel.validateuserobject(usermodel.sharedinstance)) {         return true     } else {         return false     } } 

println() log xcode true true

the above 2 true coming retrieval code println(validuser) , println(validuser.boolvalue)

the bool type in swift conforms booleantype, has member:

var boolvalue: bool { }

the value stored in validuser bool, because otherwise wouldn't able put in variable of bool type.

the situation here there bug in code. go on again , make sure it's entering else block instead of if block.

as side note, swift formatting convention if statements looks this:

if condition {     ... } else {     ... } 

as opposed if(condition){...


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -