酢ろぐ!

カレーが嫌いなスマートフォンアプリプログラマのブログ。

Xcode 4.2でNSFileManager createDirectoryAtPath:attributes:メソッドが非推奨となっている場合の対応

Xcode 4.2に変更して、iOS Deployment Targetを「4.3」に上げると、以下のメソッドでwarningが発生する様になりました。

[[NSFileManager defaultManager] createDirectoryAtPath:<hogeDirPath> attributes:nil];

このメソッドを使っていると、以下のようなwarningが表示されています。

'createDirectoryAtPath:attributes:' is deprecated

親ディレクトリの存在の有無を確認せずにディレクトリを作成することの出来る createDirectoryAtPath:withIntermediateDirectories:attributes:errorメソッドが追加されたようです。
特にその用途がない場合は、以下の様に書き換えるようにしました。

[[NSFileManager defaultManager]  createDirectoryAtPath:<hogeDirPath> 
       withIntermediateDirectories:NO 
                        attributes:nil error:nil];

これでwarningは発生しなくなったかと思います。