I inherited the following code:
- (id)initWithFileURL:(NSURL *)aURL {
if((self = [super initWithFileURL:aURL]) != nil) {
This init method is in a class which inherits from UIManagedDocument
When it hits the "if" line, I'm getting:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:]: nil string parameter'
So far, I've been unable to figure out why. I've tested this code in the legacy project I took it from, it works fine there. The method is getting called with aURL populated (aURL is not nil, seems ok) in both projects. What could be wrong with the new project I've copied this legacy code into, to be causing it to throw this error? Thanks.
Edit added:
Inserting NSLog immediately before the "if" line outputs the following value for aURL
file:///var/mobile/Applications/427BABD3-9D9D-41B7-8B99-1586E93FFADD/Documents/3FE3861A-CA4B-4859-B14B-5CC4A1C6E7B4.khp
Edit added, here is the code higher up the stack trace:
- (id)initWithFileURL:(NSURL *)aURL withFormType:(KHFormType)aFormType {
if((self = [self initWithFileURL:aURL]) != nil) {
self.formType = aFormType;
}
return self;
}
...
NSURL *uniqueFileURL = [[self class] uniqueFilenameInDirectory:documentURL withFileExtension:DOCUMENT_EXT];
// KHDocument *aDocument = [[KHDocument alloc] initWithFileURL:uniqueFileURL withFormType:inputPaceForm];
NSLog(@"%d", [KHProfileInfoController getFormType:@"inputPaceForm"]);
KHDocument *aDocument = [[KHDocument alloc] initWithFileURL:uniqueFileURL withFormType:[KHProfileInfoController getFormType:@"inputPaceForm"]];
...
+ (NSURL *)uniqueFilenameInDirectory:(NSURL *)dirURL withFileExtension:(NSString *)fileExtension {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *existingFiles = [fileManager contentsOfDirectoryAtPath:[dirURL path] error:nil];
NSString *uniqueFilename;
do {
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef newUniqueIdString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
uniqueFilename = [[[dirURL path] stringByAppendingPathComponent:(__bridge NSString *)newUniqueIdString] stringByAppendingPathExtension:fileExtension];
CFRelease(newUniqueId);
CFRelease(newUniqueIdString);
} while ([existingFiles containsObject:uniqueFilename]);
return [NSURL fileURLWithPath:uniqueFilename];
}