Wednesday, May 1, 2013

NSURL URLByDeletingPathExtension example ios


Returns a new URL made by deleting the path extension, if any, from the original URL.
- (NSURL *)URLByDeletingPathExtension
Return Value of [NSURL URLByDeletingPathExtension]
A new URL with the path extension of the original URL removed.
Discussion of [NSURL URLByDeletingPathExtension]
If the original URL represents the root path, the returned URL is identical. If the URL has multiple path extensions, only the last one is removed.
Example of [NSURL URLByDeletingPathExtension]
NSString *path;
NSURL *filepath;
fileurl = [sheet URL];
fileurl = [fileurl URLByDeletingPathExtension];
fileurl = [fileurl URLByAppendingPathExtension:@"yyy"];
path = [fileurl path];
Example of [NSURL URLByDeletingPathExtension]
           NSUInteger count = 0;
            NSString *filePath = nil;
            do {
                NSString *extension = ( NSString *)UTTypeCopyPreferredTagWithClass(( CFStringRef)AVFileTypeQuickTimeMovie, kUTTagClassFilenameExtension);
                NSString *fileNameNoExtension = [[asset.defaultRepresentation.url URLByDeletingPathExtension] lastPathComponent];
                NSString *fileName = [NSString stringWithFormat:@"%@-%@-%u",fileNameNoExtension , AVAssetExportPresetLowQuality, count];
                filePath = NSTemporaryDirectory();
                filePath = [filePath stringByAppendingPathComponent:fileName];
                filePath = [filePath stringByAppendingPathExtension:extension];

            } while ([[NSFileManager defaultManager] fileExistsAtPath:filePath]);

            NSURL *outputURL = [NSURL fileURLWithPath:filePath];