Created
June 1, 2014 02:25
-
-
Save vikingosegundo/417bac2c3b5544be81c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface MyClass : NSObject | |
- (NSString *)actualPhotoPath:(NSDictionary *)input; | |
@end | |
@implementation MyClass | |
- (NSString *)actualPhotoPath:(NSDictionary *)input | |
{ | |
NSRange r1 = [[input objectForKey:@"pic"] rangeOfString:[input objectForKey:@"username"]]; | |
NSRange r2 = [[input objectForKey:@"pic"] rangeOfString:@".png"]; | |
if(r1.location != NSNotFound && r2.location != NSNotFound){ | |
NSRange rSub = NSMakeRange(r1.location + r1.length, r2.location - r1.location - r1.length); | |
NSString *sub = [[input objectForKey:@"pic"] substringWithRange:rSub]; | |
NSString *actual = [NSString stringWithFormat:@"%@%@.png",[input objectForKey:@"username"],sub]; | |
NSLog(@"%@",actual); | |
return actual; | |
} | |
// if the code reaches this block, one of the ranges didn't work. | |
// do what ever must be done in that case here | |
return nil; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSDictionary *dict = @{@"username": @"vikingosegundo", @"pic": @"vikingosegundo123.png"}; | |
MyClass *obj = [[MyClass alloc] init]; | |
NSString *file = [obj actualPhotoPath:dict]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment