国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

IOS 使用NSAssert()和NSParameterAssert調(diào)試程序

2020-07-26 02:47:37
字體:
供稿:網(wǎng)友

IOS 使用NSAssert()和NSParameterAssert調(diào)試程序

NSAssert:

  NSAssert()只是一個宏,用于開發(fā)階段調(diào)試程序中的Bug,通過為NSAssert()傳遞條件表達式來斷定是否屬于Bug,滿足條件返回真值,程序繼續(xù)運行,如果返回假值,則拋出異常,并切可以自定義異常描述。NSAssert()是這樣定義的:

#define NSAssert(condition, desc)

condition是條件表達式,值為YES或NO;desc為異常描述,通常為NSString。當conditon為YES時程序繼續(xù)運行,為NO時,則拋出帶有desc描述的異常信息。NSAssert()可以出現(xiàn)在程序的任何一個位置。

 下面介紹NSParameterAssert

   斷言評估一個條件,如果條件為 false ,調(diào)用當前線程的斷點句柄。每一個線程有它自已的斷點句柄,它是一個 NSAsserttionHandler 類的對象。當被調(diào)用時,斷言句柄打印一個錯誤信息,該條信息中包含了方法名、類名或函數(shù)名。然后,它就拋出一個 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 的方法的有效性。簡單提供參數(shù)作為條件就行。該宏評估這個參數(shù),如果為 false ,它就打印一個錯誤日志信息,該信息包含了參數(shù)并且拋出一個異常。

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.

  如果定義了預(yù)處理宏 NS_BLOCK_ASSERTIONS 斷言就被禁止了。所有的斷點宏都返回 void。

Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined. All assertion macros return void.

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 扶沟县| 时尚| 石家庄市| 东乌珠穆沁旗| 乐业县| 临夏市| 绩溪县| 峨眉山市| 林州市| 如皋市| 大关县| 江北区| 东乌珠穆沁旗| 托里县| 汝州市| 澄城县| 巩义市| 涟源市| 泸州市| 东乌| 镇巴县| 巢湖市| 西充县| 天镇县| 江永县| 长乐市| 花垣县| 民乐县| 庆云县| 仙桃市| 黄平县| 渭源县| 视频| 兴业县| 安顺市| 绥江县| 麦盖提县| 鄂尔多斯市| 辽源市| 乌兰察布市| 兴和县|