NSParameterAssert
Validates the specified parameter.
NSParameterAssert(condition)
Discussion
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 class NSAssertionHandler. When invoked, an assertion handler prints an error message that includes method and class names (or the function name). It then raises an NSInternalInconsistencyException exception.
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.
Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined. All assertion macros return void.
Availability
- Available in Mac OS X v10.0 and later.
分享到:
相关推荐
`NSAssert()`和`NSParameterAssert()`是Apple提供的两种强大的调试工具,它们可以帮助开发者在开发阶段快速定位并修复问题。下面我们将详细探讨这两个宏的使用方法和作用。 首先,`NSAssert()`是一个用于调试目的的...
良好的编程实践应该是尽量避免异常的发生,对可能出现错误的代码段进行充分的防御性编程,如使用`nil`检查、异常检测的API(如`NSParameterAssert`)等。 在压缩包文件"IgnoreException-master"中,可能包含了一个...
NSParameterAssert([curReach isKindOfClass:[Reachability class]]); [self updateInterfaceWithReachability:curReach]; } - (void)updateInterfaceWithReachability:(Reachability *)reachability { if ...
NSParameterAssert(asset); AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; assetImageGenerator.appliesPreferredTrackTransform = YES; ...
NSParameterAssert([currReach isKindOfClass:[Reachability class]]); NetworkStatus status = [currReach currentReachabilityStatus]; switch (status) { case NotReachable: // 无网络连接 // 处理网络...