zoukankan      html  css  js  c++  java
  • what is NSParameterAssert?

    It is a simple way to test that a methods parameter is not nil or not 0. So basically, you use it to create a precondition, stating that some parameter must be set. If it is not set, the macro causes the application to abort and generates an error on that line. So:

    - (void)someMethod:(id)someObjectThatMustNotBeNil
    {
      // Make sure that someObjectThatMustNotBeNil is really not nil
      NSParameterAssert( someObjectThatMustNotBeNil );
      // Okay, now do things
    }

    Pre-conditions are a simple way to ensure that methods/API are being called correctly by the programmer. The idea is that if a programmer violates the precondition, the application terminates early--hopefully during debugging and basic testing.

    NSParameterAssert can be used to test that any expression evaluates to true, however, so you can use it like this as well:

    NSParameterAssert( index >=0);// ensure no negative index is supplied
  • 相关阅读:
    HDU 4285
    Codeforces 242C
    Codeforces 811C
    Codeforces 883H
    Codeforces 371D
    Codeforces 926E
    牛客算法周周练17 解题报告
    牛客算法周周练17D
    牛客算法周周练17C
    牛客算法周周练17A
  • 原文地址:https://www.cnblogs.com/mumue/p/3067981.html
Copyright © 2011-2022 走看看