Permalink
Browse files

About Retain - very simple intro to concept of retain release

and then a pointer to more reading
  • Loading branch information...
1 parent 31b83c9 commit 20bd02858d439f77bacbfa70f55c8eb357f0a003 Curtis Schofield committed Nov 10, 2011
Showing with 64 additions and 2 deletions.
  1. +59 −0 AboutRetain.m
  2. +1 −2 Kiwi/KWMatcher.h
  3. +4 −0 ObjectiveCKoans.xcodeproj/project.pbxproj
View
@@ -0,0 +1,59 @@
+//
+// AboutAssertions.m
+// ObjectiveCKoans
+//
+// Created by Curtis Schofield
+// Copyright 2011 BlazingCloud, Curtis J Schofield
+//
+
+#import "Kiwi.h"
+
+SPEC_BEGIN(AboutRetain)
+
+describe(@"Retain Assertions", ^{
+
+ context(@"NSMutableString Retain", ^{
+ __block NSMutableString *aString = NULL;
+
+ beforeEach(^{
+ aString = [[NSMutableString alloc] init];
+ });
+
+ it(@"starts with a retainCount value", ^{
+ int actual_count = [aString retainCount];
+ int expected_count = -1; // change this to the correct value
+ [[theValue(actual_count) should] equal:theValue(expected_count)];
+ });
+
+ it(@"increments retainCount value according to the selector retain", ^{
+ [aString retain];
+ int actual_count = [aString retainCount];
+ int expected_count = -2; // change this to the correct value
+ [[theValue(actual_count) should] equal:theValue(expected_count)];
+ });
+
+ it(@"decriments retainCount on selector release", ^{
+
+ [aString retain];
+ [aString release];
+ int actual_count = [aString retainCount];
+ int expected_count = -1; // change this to the correct value
+ [[theValue(actual_count) should] equal:theValue(expected_count)];
+
+
+ [aString release];
+ actual_count = [aString retainCount];
+ expected_count = -1; // change this to the correct value
+ [[theValue(actual_count) should] equal:theValue(expected_count)];
+
+ //
+ // Did you not get what you expected? Check this resource out.
+ //
+ // http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html
+ });
+
+ });
+
+});
+
+SPEC_END
View
@@ -8,8 +8,7 @@
#import "KWMatching.h"
@interface KWMatcher : NSObject<KWMatching> {
-@protected
- id subject;
+@protected id subject;
}
#pragma mark -
@@ -77,6 +77,7 @@
D15C53E812C3FB6300929E2A /* AboutValueAssertions.m in Sources */ = {isa = PBXBuildFile; fileRef = D15C53E712C3FB6300929E2A /* AboutValueAssertions.m */; };
D174002512C43FE500775C72 /* AboutNil.m in Sources */ = {isa = PBXBuildFile; fileRef = D174002412C43FE500775C72 /* AboutNil.m */; };
D17C5AEB12CD6C8300E961B8 /* AboutNSArray.m in Sources */ = {isa = PBXBuildFile; fileRef = D17C5AEA12CD6C8300E961B8 /* AboutNSArray.m */; };
+ D5EA8185146B5FFF00C2F616 /* AboutRetain.m in Sources */ = {isa = PBXBuildFile; fileRef = D5EA8184146B5FFF00C2F616 /* AboutRetain.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -238,6 +239,7 @@
D15C53E712C3FB6300929E2A /* AboutValueAssertions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutValueAssertions.m; sourceTree = "<group>"; };
D174002412C43FE500775C72 /* AboutNil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutNil.m; sourceTree = "<group>"; };
D17C5AEA12CD6C8300E961B8 /* AboutNSArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutNSArray.m; sourceTree = "<group>"; };
+ D5EA8184146B5FFF00C2F616 /* AboutRetain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutRetain.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -283,6 +285,7 @@
D15C531112C3F8C700929E2A /* Tests */ = {
isa = PBXGroup;
children = (
+ D5EA8184146B5FFF00C2F616 /* AboutRetain.m */,
D15C531C12C3F9A000929E2A /* Kiwi */,
D15C53E712C3FB6300929E2A /* AboutValueAssertions.m */,
D174002412C43FE500775C72 /* AboutNil.m */,
@@ -598,6 +601,7 @@
26ECC57E146634E200B83428 /* NSObject+KiwiStubAdditions.m in Sources */,
26ECC57F146634E200B83428 /* NSObject+KiwiVerifierAdditions.m in Sources */,
26ECC580146634E200B83428 /* NSValue+KiwiAdditions.m in Sources */,
+ D5EA8185146B5FFF00C2F616 /* AboutRetain.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 20bd028

Please sign in to comment.