More Detailed Error From createFileAtPath?

前端 未结 2 956
失恋的感觉
失恋的感觉 2021-02-04 00:53

Is there anyway to get more detailed error data back from \"createFileAtPath\" I was kind of expecting an NSError? Currently I am using the BOOL return value.

su         


        
2条回答
  •  走了就别回头了
    2021-02-04 01:20

    You're not supposed to use that method; they forgot to put this in the main docs (!), but if you read the Apple header file you find this comment:

    /* These methods are provided here for compatibility. The corresponding methods on NSData which return NSErrors should be regarded as the primary method of creating a file from an NSData or retrieving the contents of a file as an NSData. */

    So, instead, Apple expects you to use this (which, from testing, appears to function exactly the same - except that it's located in a bizarre class where you'd never think to look for it (I want to create an empty file ... so I have to ... instantiate a nil NSData object? What?) it has an NSError object):

    https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/occ/instm/NSData/writeToFile:options:error:

提交回复
热议问题