Skip to content

Commit

Permalink
Merge pull request #6 from florianbachmann/master
Browse files Browse the repository at this point in the history
added strong, because i needed it :-)
  • Loading branch information
carlj committed Aug 3, 2014
2 parents f23fc22 + b528e60 commit f2e1420
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CJAMacros.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "CJAMacros"
s.version = "2.0.3"
s.version = "2.0.4"
s.platform = :ios, "6.0"
s.summary = "Macro collection for daily usage"
s.homepage = "https://github.com/carlj/CJAMacros"
Expand Down
15 changes: 15 additions & 0 deletions CJAMacros/CJAMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ Add a Singelton implementation to the .m File
*/
#define CJAWeakSelf CJAWeak(self)

/**
Define a strong for an object with a given name.
*/
#define CJAStrongWithNameAndObject(_obj, _name) __strong typeof(_obj) strong##_name = _obj

/**
Define a strong for a given object.
*/
#define CJAStrong(_obj) CJAStrongWithNameAndObject(_obj, _obj)

/**
Define a strong self.
*/
#define CJAStrongSelf CJAStrong(self)

/**
Typicall isKindOfClass Check
*/
Expand Down
12 changes: 11 additions & 1 deletion Example/Classes/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,25 @@ - (void)performWeakDeclarations {
CJAWeakSelf;
NSAssert([weakself isEqual:self], @"Objects should be equal");

CJAStrongSelf;
NSAssert([strongself isEqual:self], @"Objects should be equal");

// Test weak strings.
NSString *text = @"Example";
CJAWeak(text);
NSAssert([weaktext isEqual:text], @"NSString objects should be equal");


CJAStrong(text);
NSAssert([strongtext isEqual:text], @"NSString objects should be equal");

// Test weak numbers
NSNumber *number = @(1);
CJAWeakWithNameAndObject(number, Number);
NSAssert([weakNumber isEqual:number], @"NSNumber objects should be equal");

CJAStrongWithNameAndObject(number, Number);
NSAssert([strongNumber isEqual:number], @"NSNumber objects should be equal");

}

- (void)perfomKindOfClassChecks {
Expand Down

0 comments on commit f2e1420

Please sign in to comment.