是什么导致了这个逻辑错误?

时间:2016-03-13 00:53:28

标签: objective-c parse-platform firebase

这是我的代码,这里是输出...我不明白为什么我在日志上面的if语句允许这种情况发生...这个嵌套在for循环中的if语句不应该允许输出全名与描述相同......

    Firebase *firebase = [[Firebase alloc] initWithUrl:[NSString stringWithFormat:@"%@/Recent", FIREBASE]];
    FQuery *query = [[firebase queryOrderedByChild:@"groupId"] queryEqualToValue:groupId];

[query observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
    //Is group

    if ([snapshot.value[@"type"]  isEqual: @"group"]){
        self.title = snapshot.value[@"description"];
    }
    //Is individual
    else{

        NSString *senderId = snapshot.value[@"userId"];
        PFQuery *query = [PFQuery queryWithClassName:PF_USER_CLASS_NAME];
        [query whereKey:@"objectId" equalTo:senderId];
        query.limit = 1;
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
                // Do something with the found objects
                for (PFObject *object in objects) {
                    NSString *userName = [[PFUser currentUser]fullname];
                    if (object[@"fullname"] != userName){
                        self.title = object[@"fullname"];
                        NSLog(@"You're talking to: %@", object[@"fullname"]);
                        NSLog(@"Logged in user: %@", userName);
                    }
                }
            } else {
                // Log details of the failure
                NSLog(@"Error: %@ %@", error, [error userInfo]);
            }
        }];
    }



}];

还有日志

2016-03-12 18:48:09.844 Gibr[34128:1436940] You're talking to: Testerten
2016-03-12 18:48:09.844 Gibr[34128:1436940] Logged in user: Travis Tubbs
2016-03-12 18:48:09.845 Gibr[34128:1436940] You're talking to: Travis Tubbs
2016-03-12 18:48:09.845 Gibr[34128:1436940] Logged in user: Travis Tubbs

1 个答案:

答案 0 :(得分:3)

您使用 var myarray = [ [178, 559, 906, 1252], [381, 537, 937, 1115], [346, 529, 913, 1069] ]; var resultArray = []; var maxlen = Math.max.apply(null, myarray.map(function(i) { return i.length; })); var l = 0; while (l < maxlen) { var s = 0; var a = []; for (i = 0; i < myarray.length; i++) { a.push(myarray[i].shift()); } resultArray.push(a); l++; s++; } console.log(resultArray); 来比较两个字符串的问题。但这不是它的用途;它用于比较对象。两个字符串变量不是同一个对象;它们是两个不同的对象,两个不同的变量。

如果您想知道两个字符串变量是否具有与字符串相同的值 ,请使用!=

isEqualToString: