NSValue+KiwiAdditions.m 491 B

1234567891011121314151617181920212223
  1. //
  2. // Licensed under the terms in License.txt
  3. //
  4. // Copyright 2010 Allen Ding. All rights reserved.
  5. //
  6. #import "NSValue+KiwiAdditions.h"
  7. #import "KWObjCUtilities.h"
  8. @implementation NSValue(KiwiAdditions)
  9. #pragma mark - Accessing Data
  10. - (NSData *)dataValue {
  11. NSUInteger length = KWObjCTypeLength([self objCType]);
  12. void *buffer = malloc(length);
  13. [self getValue:buffer];
  14. NSData *data = [NSData dataWithBytes:buffer length:length];
  15. free(buffer);
  16. return data;
  17. }
  18. @end