If statement does not work properly

前端 未结 3 556
不知归路
不知归路 2021-01-29 15:23

This is my code:

NSString * atime = [NSString stringWithFormat:@\"%@\",[theDataObject.minuteArray objectAtIndex:indexPath.row]];

NSLog(@\"value of atime is:%@\"         


        
相关标签:
3条回答
  • 2021-01-29 15:59

    isEqualToString: ->

    - (BOOL)isEqualToString:(NSString *)aString
    

    Returns a Boolean value that indicates whether a given string is equal to the receiver using a literal Unicode-based comparison.

    Discussion -> When this method compares two strings, if the individual Unicodes are the same, then the strings are equal

    For more you can access apple NSString Class Reference

    if([atime isEqualToString:@"0"])
    {
    }
    else
    {
    }
    
    0 讨论(0)
  • 2021-01-29 16:04

    Try the following:

    if ([atime isEqualToString : @" "]) {}
    
    0 讨论(0)
  • 2021-01-29 16:05
    if (atime==@"0")
    

    Compares the memory address of atime with the address of constant string @"0".

    if ([atime isEqualToString:@"0"]) 
    

    Compares the values that are stored in the two memory locations.

    From your requirement it is seen that you want to compare the value not the memory location. So go for 2nd one.

    0 讨论(0)
提交回复
热议问题