[NSString lastPathComponent]
Returns the last path component of the receiver.
- (NSString *)lastPathComponent
Return Value
The last path component of the receiver.
Discussion of [NSString lastPathComponent]
Path components are alphanumeric strings delineated by the path separator (slash “/”) or the beginning or end of the path string. Multiple path separators at the end of the string are stripped.
Example of [NSString lastPathComponent]
NSString *filename = [filePath lastPathComponent];
[encryptedData writeToFile:[[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"]
stringByAppendingPathComponent:[filename stringByAppendingString:@".kry"] atomically:YES];
Example of [NSString lastPathComponent]
NSURL *url = [NSURL urlWithString:@"http://www.google.com/a.pdf"];
NSString *filename = [url lastPathComponent];
NSString* theFileName = [[string lastPathComponent] stringByDeletingPathExtension]
Example of [NSString lastPathComponent]
NSString *fullPath = // Get the path to your image
NSString *pathWithNoFileName = [fullPath stringByDeletingLastPathComponent];
NSString *myPath = [[pathWithNoFileName lastPathComponent] stringByAppendingPathComponent:[fullPath lastPathComponent]];