ValetDefines.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // ValetDefines.h
  3. // Valet
  4. //
  5. // Created by Dan Federman on 2/11/15.
  6. // Copyright 2015 Square, Inc.
  7. //
  8. // Licensed under the Apache License, Version 2.0 (the "License");
  9. // you may not use this file except in compliance with the License.
  10. // You may obtain a copy of the License at
  11. //
  12. //    http://www.apache.org/licenses/LICENSE-2.0
  13. //
  14. // Unless required by applicable law or agreed to in writing, software
  15. // distributed under the License is distributed on an "AS IS" BASIS,
  16. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. // See the License for the specific language governing permissions and
  18. // limitations under the License.
  19. //
  20. /**
  21. Throws a caught exception and returns "result" if "condition" is false.
  22. Example:
  23. VALCheckCondition(isProperlyConfigured, nil, @"Foo was not properly configured.");
  24. */
  25. #define VALCheckCondition(condition, result, desc, ...) \
  26. do { \
  27. const BOOL conditionResult = !!(condition); \
  28. if (!conditionResult) { \
  29. @try { \
  30. [NSException raise:@"Valet API Misuse" format:(desc), ##__VA_ARGS__]; \
  31. } @catch (NSException *exception) { \
  32. NSLog(@"Valet API Misuse: %s %@", __PRETTY_FUNCTION__, exception.reason); \
  33. return result;\
  34. } \
  35. } \
  36. } while(0)
  37. /// Error returned from Security API when the application is not entitled to perform the requested action.
  38. #define errSecMissingEntitlement -34018