NSAssert()只是一個宏,用於開發階段調試程序中的Bug,經過爲NSAssert()傳遞條件表達式來判定是否屬於Bug,知足條件返回真值,程序繼續運行,若是返回假值,則拋出異常,並切能夠自定義異常描述。NSAssert()是這樣定義的:ide
#define NSAssert(condition, desc)函數
condition是條件表達式,值爲YES或NO;desc爲異常描述,一般爲NSString。當conditon爲YES時程序繼續運行,爲NO時,則拋出帶有desc描述的異常信息。NSAssert()能夠出如今程序的任何一個位置。lua
NSParameterAssert線程
斷言評估一個條件,若是條件爲 false ,調用當前線程的斷點句柄。每個線程有它自已的斷點句柄,它是一個 NSAsserttionHandler 類的對象。當被調用時,斷言句柄打印一個錯誤信息,該條信息中包含了方法名、類名或函數名。而後,它就拋出一個 NSInternalInconsistencyException 異常。
Assertions evaluate a condition and, if the condition evaluates to false, call the assertion handler for the current thread, passing it a format string and a variable number of arguments. Each thread has its own assertion handler, which is an object of classNSAssertionHandler. When invoked, an assertion handler prints an error message that includes method and class names (or the function name). It then raises anNSInternalInconsistencyException exception.調試
這個宏用於確認一個 Objective-C 的方法的有效性。簡單提供參數做爲條件就行。該宏評估這個參數,若是爲 false ,它就打印一個錯誤日誌信息,該信息包含了參數而且拋出一個異常。
This macro validates a parameter for an Objective-C method. Simply provide the parameter as the condition argument. The macro evaluates the parameter and, if it is false, it logs an error message that includes the parameter and then raises an exception.日誌
若是定義了預處理宏 NS_BLOCK_ASSERTIONS 斷言就被禁止了。全部的斷點宏都返回 void。
Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined. All assertion macros return void.orm