RACTestObject.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // RACTestObject.m
  3. // ReactiveCocoa
  4. //
  5. // Created by Josh Abernathy on 9/18/12.
  6. // Copyright (c) 2012 GitHub, Inc. All rights reserved.
  7. //
  8. #import "RACTestObject.h"
  9. @implementation RACTestObject
  10. - (void)dealloc {
  11. free(_charPointerValue);
  12. free((void *)_constCharPointerValue);
  13. }
  14. - (void)setNilValueForKey:(NSString *)key {
  15. if (!self.catchSetNilValueForKey) [super setNilValueForKey:key];
  16. }
  17. - (void)setCharPointerValue:(char *)charPointerValue {
  18. if (charPointerValue == _charPointerValue) return;
  19. free(_charPointerValue);
  20. _charPointerValue = strdup(charPointerValue);
  21. }
  22. - (void)setConstCharPointerValue:(const char *)constCharPointerValue {
  23. if (constCharPointerValue == _constCharPointerValue) return;
  24. free((void *)_constCharPointerValue);
  25. _constCharPointerValue = strdup(constCharPointerValue);
  26. }
  27. - (void)setObjectValue:(id)objectValue andIntegerValue:(NSInteger)integerValue {
  28. self.hasInvokedSetObjectValueAndIntegerValue = YES;
  29. self.objectValue = objectValue;
  30. self.integerValue = integerValue;
  31. }
  32. - (void)setObjectValue:(id)objectValue andSecondObjectValue:(id)secondObjectValue {
  33. self.hasInvokedSetObjectValueAndSecondObjectValue = YES;
  34. self.objectValue = objectValue;
  35. self.secondObjectValue = secondObjectValue;
  36. }
  37. - (void)setSlowObjectValue:(id)value {
  38. [NSThread sleepForTimeInterval:0.02];
  39. _slowObjectValue = value;
  40. }
  41. - (NSString *)combineObjectValue:(id)objectValue andIntegerValue:(NSInteger)integerValue {
  42. return [NSString stringWithFormat:@"%@: %ld", objectValue, (long)integerValue];
  43. }
  44. - (NSString *)combineObjectValue:(id)objectValue andSecondObjectValue:(id)secondObjectValue {
  45. return [NSString stringWithFormat:@"%@: %@", objectValue, secondObjectValue];
  46. }
  47. - (void)lifeIsGood:(id)sender {
  48. }
  49. + (void)lifeIsGood:(id)sender {
  50. }
  51. - (NSRange)returnRangeValueWithObjectValue:(id)objectValue andIntegerValue:(NSInteger)integerValue {
  52. return NSMakeRange((NSUInteger)[objectValue integerValue], (NSUInteger)integerValue);
  53. }
  54. - (RACTestObject *)dynamicObjectProperty {
  55. return [self dynamicObjectMethod];
  56. }
  57. - (RACTestObject *)dynamicObjectMethod {
  58. RACTestObject *testObject = [[RACTestObject alloc] init];
  59. testObject.integerValue = 42;
  60. return testObject;
  61. }
  62. - (void)write5ToIntPointer:(int *)intPointer {
  63. NSCParameterAssert(intPointer != NULL);
  64. *intPointer = 5;
  65. }
  66. - (NSInteger)doubleInteger:(NSInteger)integer {
  67. return integer * 2;
  68. }
  69. - (char *)doubleString:(char *)string {
  70. size_t doubledSize = strlen(string) * 2 + 1;
  71. char *doubledString = malloc(sizeof(char) * doubledSize);
  72. doubledString[0] = '\0';
  73. strlcat(doubledString, string, doubledSize);
  74. strlcat(doubledString, string, doubledSize);
  75. dispatch_async(dispatch_get_main_queue(), ^{
  76. free(doubledString);
  77. });
  78. return doubledString;
  79. }
  80. - (const char *)doubleConstString:(const char *)string {
  81. return [self doubleString:(char *)string];
  82. }
  83. - (RACTestStruct)doubleStruct:(RACTestStruct)testStruct {
  84. testStruct.integerField *= 2;
  85. testStruct.doubleField *= 2;
  86. return testStruct;
  87. }
  88. - (dispatch_block_t)wrapBlock:(dispatch_block_t)block {
  89. return ^{
  90. block();
  91. };
  92. }
  93. @end