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

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

梁溪網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)2013年開創(chuàng)至今到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。

NSAssert:

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

#define NSAssert(condition, desc)

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

 下面介紹NSParameterAssert

   斷言評估一個條件,如果條件為 false ,調(diào)用當(dāng)前線程的斷點(diǎn)句柄。每一個線程有它自已的斷點(diǎn)句柄,它是一個 NSAsserttionHandler 類的對象。當(dāng)被調(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.

這個宏用于確認(rèn)一個 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 斷言就被禁止了。所有的斷點(diǎn)宏都返回 void。

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

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

網(wǎng)頁標(biāo)題:IOS使用NSAssert()和NSParameterAssert調(diào)試程序
網(wǎng)頁網(wǎng)址:http://bm7419.com/article22/gegpcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)網(wǎng)站導(dǎo)航、網(wǎng)站制作網(wǎng)站收錄、建站公司商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計