Search code examples
iphoneobjective-ciosipadnsfilemanager

Calling -createDirectoryAtURL: causes crash


I'm really confused right now. This is my piece of code:

NSFileManager *manager = [NSFileManager defaultManager];

NSURL *backup = [self applicationDocumentsDirectory];
backup = [backup URLByAppendingPathComponent:@"Old_Data_File"];

[manager createDirectoryAtURL:backup withIntermediateDirectories:YES attributes:nil error:nil];

When this code is executed, it crashes at the last line with the message

-[NSFileManager createDirectoryAtURL:withIntermediateDirectories:attributes:error:]: unrecognized selector sent to instance 0x5e59220

How could this be an unrecognized selector?

EDIT:

manager is not nil and printing backup to the console results in

{type = 15, string = file://localhost/Users/fabian/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/D37C5B93-A778-4555-8953-814F823B1116/Documents/Old_Data_File, encoding = 134217984, base = (null)}

Until the Old_Data_File the path exists, the last component should be created by the file manager...


Solution

  • oh... are you targeting iOS 5.0 and newer? this API does not exist on iOS 4.3.