iOS 中 NSParameterAssert 是幹啥的之官方解釋翻譯篇

來源:互聯網
上載者:User


<喎?http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHAgY2xhc3M9"p1">討論 Discussion

斷言評估一個條件,如果條件為 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.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.