following code is not working. no error message or anything.. it just istn working. (images are not shown where they are supposed to be)
imgdtl is a NSMutableDictionary
if ([NSString stringWithFormat:@"%@",[filePath pathExtension]] == @".jpg")
{
NSImage *myimage = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@" ,filePath]];
[imgdtl setObject: myimage forKey: @"image"];
[imgdtl setObject:[NSString stringWithFormat:@"%@" ,fileName] forKey: @"filename"];
}
else{
NSImage *myimage = [[NSImage alloc] initWithContentsOfFile:@"no_image.gif"];
[imgdtl setObject: myimage forKey: @"image"];
[imgdtl setObject:[NSString stringWithFormat:@"%@" ,fileName] forKey: @"filename"];
}
but this one is working:
NSImage *myimage = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@" ,filePath]];
[imgdtl setObject: myimage forKey: @"image"];
[imgdtl setObject:[NSString stringWithFormat:@"%@" ,fileName] forKey: @"filename"];
i would like to load the image only if the format is .jpg and would like it not to load if the file has any other extension. could somebody please tell me what i am doing wrong? thanks!
—EDIT—
thanks to all the comments, but the following code gives the same problem as the one above:
if ([[NSString stringWithFormat:@"%@",[filePath pathExtension]] isEqualToString @".jpg"])
There are hundreds of duplicates.
You want to compare the contents of a string, not the pointers.
== compares pointers. To compare contents use NSString’s
-isEqualToString:methodedit
On a side note, move your duplicate code out of your conditional blocks,
They are the same, so no need to put them there twice: