Correct Structure to check for Errors using NSError

前端 未结 4 1874
囚心锁ツ
囚心锁ツ 2021-02-02 01:59

I\'m coding up various routines and I\'m trying my best to keep it neat and refactored.

Methods I\'m creating are starting to look similar to this code:

         


        
4条回答
  •  孤城傲影
    2021-02-02 02:36

    I think that none of the answers presented here are taking into account Apple's recommended practices.

    Basically you should never check for the NSError object to determine if there was a problem. You check if there was a problem by checking the value returned from the method that takes a pointer to a pointer to an NSError.

    From the Apple documentation:

    Important Success or failure is indicated by the return value of the method. Although Cocoa methods that indirectly return error objects in the Cocoa error domain are guaranteed to return such objects if the method indicates failure by directly returning nil or NO, you should always check that the return value is nil or NO before attempting to do anything with the NSError object.

提交回复
热议问题