Skip to content

Commit

Permalink
added CGFloat compare marco, also removed the custom NSLog Macros, us…
Browse files Browse the repository at this point in the history
…e instead CJALog
  • Loading branch information
carlj committed Aug 12, 2014
1 parent f2e1420 commit cc06e1a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 87 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.4"
s.version = "2.0.5"
s.platform = :ios, "6.0"
s.summary = "Macro collection for daily usage"
s.homepage = "https://github.com/carlj/CJAMacros"
Expand Down
29 changes: 20 additions & 9 deletions CJAMacros/CJAMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
#import <Foundation/Foundation.h>
#include <Availability.h>

///---------------------------
/// @name Logs
///---------------------------

/**
Shortcuts for NSLogs(...). Also includes the current __FUNCTION__
*/
#define kNSLogFunctionWithObject(_object) NSLog(@"%s %@", __FUNCTION__, [_object description]);
#define kNSLogFunction kNSLogFunctionWithObject(@"")

///---------------------------
/// @name Localization
Expand Down Expand Up @@ -230,6 +221,11 @@ _lambda \
*/
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(_gVersion) ( floor(NSFoundationVersionNumber) <= _gVersion )


///---------------------------
/// @name Singleton Macros
///---------------------------

/**
Add a Singelton implementation to the .m File
*/
Expand All @@ -250,6 +246,10 @@ Add a Singelton implementation to the .m File
*/
#define CJAMacrosSingletonInterface + (instancetype)sharedInstance;

///---------------------------
/// @name Block Vars
///---------------------------

/**
Define a weak for an object with a given name.
*/
Expand Down Expand Up @@ -285,3 +285,14 @@ Add a Singelton implementation to the .m File
*/
#define CJAIsKindOfClass(_object, _class) [_object isKindOfClass: [_class class]]


///---------------------------
/// @name Float compare
///---------------------------

/**
Compare two float objects
*/
#define CJAFloatEqual(_first, _second) (fabsf( _first - _second ) < FLT_EPSILON)


149 changes: 72 additions & 77 deletions Example/Classes/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
//

DEFINE_KEY(kTestKey)

DECLARE_KEY(kTestKey)

DEFINE_KEY_WITH_VALUE(kNewTestKey, @"CustomValue")
DEFINE_KEY_WITH_VALUE(kNewTestKey, CustomValue)

#import "DemoViewController.h"

Expand All @@ -24,117 +23,107 @@ @implementation DemoViewController


- (void)viewDidLoad {
[super viewDidLoad];

[self performLogMacros];
[self performLocalizationMacro];
[self performMainThreadMacro];
[self performRuntimeChecks];
[self performDeviceChecks];
[self performKeyDeclaration];
[self performWeakDeclarations];
[self perfomKindOfClassChecks];
}

- (void)performLogMacros {

//Should output the current function fingerprint
kNSLogFunction

//Should output the current function fingerprint + and the given object description
kNSLogFunctionWithObject(@"My test log");
kNSLogFunctionWithObject(self);
[super viewDidLoad];

[self performLocalizationMacro];
[self performMainThreadMacro];
[self performRuntimeChecks];
[self performDeviceChecks];
[self performKeyDeclaration];
[self performWeakDeclarations];
[self perfomKindOfClassChecks];
[self perfomFloatChecks];
}

- (void)performLocalizationMacro {

//Localization Shortcut
NSString *localString = CJALocalize(@"MyTestLocalizationStrinKey");
kNSLogFunctionWithObject(localString);
//Localization Shortcut
NSString *localString = CJALocalize(@"MyTestLocalizationStrinKey");
NSLog(@"%s %@", __FUNCTION__, localString);
}

- (void)performNotificationMacros {

//Notification Shortcuts
static NSString *testNotificationName = @"TestNotificationName";

addObserver(testNotificationName, self, testNotification:, nil);

notify(testNotificationName, nil, nil);

removeObserver(self);
//Notification Shortcuts
static NSString *testNotificationName = @"TestNotificationName";
addObserver(testNotificationName, self, testNotification:, nil);
notify(testNotificationName, nil, nil);
removeObserver(self);
}

- (void)testNotification:(NSNotification *)notification {
kNSLogFunctionWithObject(notification.name);
NSLog(@"%s %@", __FUNCTION__, notification.name);
}


- (void)performMainThreadMacro {

//Main thread shortcuts
onMainThread(
kNSLogFunctionWithObject(@"This should be on the Main Thread");
notify(@"NotificationOnMainThread", nil, nil);
);

//Main thread shortcuts
onMainThread(
NSLog(@"This should be on the Main Thread");
notify(@"NotificationOnMainThread", nil, nil);
);
}

- (void)performRuntimeChecks {

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( _iOS_7_0) ) {
kNSLogFunctionWithObject(@"Why are on iOS 7")
}

//you can always use the normal NSFoundationVersionNumber's
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( NSFoundationVersionNumber_iOS_7_0)) {
kNSLogFunctionWithObject(@"same runtime check as above")
}

if (SYSTEM_VERSION_LESS_THAN( _iOS_7_0) ) {
kNSLogFunctionWithObject(@"Why are on iOS 6, 5, 4, 3 or 2");
}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( _iOS_7_0) ) {
NSLog(@"Why are on iOS 7");
}
//you can always use the normal NSFoundationVersionNumber's
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( NSFoundationVersionNumber_iOS_7_0)) {
NSLog(@"same runtime check as above");
}
if (SYSTEM_VERSION_LESS_THAN( _iOS_7_0) ) {
NSLog(@"Why are on iOS 6, 5, 4, 3 or 2");
}
}

- (void)performDeviceChecks {

if (DEVICE_IS_IPAD) {
kNSLogFunctionWithObject(@"The current device is an iPad");
}

if (DEVICE_IS_IPHONE) {
kNSLogFunctionWithObject(@"The current device is an iPhone (incl. iPhone 5 and iPod Touch's)");
}

if (DEVICE_IS_IPHONE_5) {
kNSLogFunctionWithObject(@"The current device is an iPhone 5 or iPod Touch 5 Gen.");
}
if (DEVICE_IS_IPAD) {
NSLog(@"The current device is an iPad");
}
if (DEVICE_IS_IPHONE) {
NSLog(@"The current device is an iPhone (incl. iPhone 5 and iPod Touch's)");
}
if (DEVICE_IS_IPHONE_5) {
NSLog(@"The current device is an iPhone 5 or iPod Touch 5 Gen.");
}
}

- (void)performKeyDeclaration {


kNSLogFunctionWithObject(kTestKey);
kNSLogFunctionWithObject(kNewTestKey);
NSLog(kTestKey);
NSLog(kNewTestKey);
}

- (void)performWeakDeclarations {
// Test self weak.
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);
Expand All @@ -146,9 +135,15 @@ - (void)performWeakDeclarations {
}

- (void)perfomKindOfClassChecks {

NSAssert(CJAIsKindOfClass(self, UIViewController), @"self isnt Kind of UIViewController Subclass ");
NSAssert(!CJAIsKindOfClass(self, UIView), @"self shouldnt be a UIView Subclass ");
}

- (void)perfomFloatChecks {

NSAssert(CJAFloatEqual(1.0f, 1.0f), @"floats should be equal");
NSAssert(!CJAFloatEqual(1.0001f, 1.0f), @"floats shouldnt be equal");
}

@end

0 comments on commit cc06e1a

Please sign in to comment.