Permalink
Browse files

Minor cleanup for 32/64 bit conversion warnings

  • Loading branch information...
1 parent dba0e21 commit 8f3abfa64f1243af1dc1a9d9c9e115937e388a46 @davedelong committed Mar 19, 2011
Showing with 87 additions and 13 deletions.
  1. +1 −0 CHLayout.h
  2. +20 −13 CHLayoutConstraint.m
  3. +13 −0 CHLayoutManager.xcodeproj/project.pbxproj
  4. +19 −0 NSNumber+CHLayout.h
  5. +34 −0 NSNumber+CHLayout.m
View
1 CHLayout.h
@@ -24,5 +24,6 @@
**/
#import "NSView+CHLayout.h"
+#import "NSNumber+CHLayout.h"
#import "CHLayoutManager.h"
#import "CHLayoutConstraint.h"
View
33 CHLayoutConstraint.m
@@ -25,6 +25,18 @@ of this software and associated documentation files (the "Software"), to deal
#import "CHLayout.h"
+CGFloat CHLayoutExtractCGFloat(id value) {
+ CGFloat extracted = 0;
+ if ([value respondsToSelector:@selector(CGFloatValue_ch)]) {
+ extracted = [value CGFloatValue_ch];
+ } else if (CGFLOAT_IS_DOUBLE && [value respondsToSelector:@selector(doubleValue)]) {
+ extracted = [value doubleValue];
+ } else if (!CGFLOAT_IS_DOUBLE && [value respondsToSelector:@selector(floatValue)]) {
+ extracted = [value floatValue];
+ }
+ return extracted;
+}
+
#pragma mark Value Transformers
@interface CHLayoutValueTransformer : NSValueTransformer
@@ -54,11 +66,9 @@ - (id) initWithOffset:(CGFloat)anOffset scale:(CGFloat)aScale {
}
- (id) transformedValue:(id)value {
- if ([value respondsToSelector:@selector(floatValue)] == NO) { return [NSNumber numberWithInt:0]; }
-
- CGFloat source = [value floatValue];
+ CGFloat source = CHLayoutExtractCGFloat(value);
CGFloat transformed = (source * scale) + offset;
- return [NSNumber numberWithFloat:transformed];
+ return [NSNumber numberWithCGFloat_ch:transformed];
}
@end
@@ -94,11 +104,9 @@ - (void) dealloc {
}
- (id) transformedValue:(id)value {
- if ([value respondsToSelector:@selector(floatValue)] == NO) { return [NSNumber numberWithInt:0]; }
-
- CGFloat source = [value floatValue];
+ CGFloat source = CHLayoutExtractCGFloat(value);
CGFloat transformed = transformer(source);
- return [NSNumber numberWithFloat:transformed];
+ return [NSNumber numberWithCGFloat_ch:transformed];
}
@end
@@ -138,8 +146,8 @@ + (id) constraintWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSS
}
- (id)initWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr valueTransformer:(NSValueTransformer *)transformer {
- double attributeRange = floorf(log10(attr));
- double sourceAttributeRange = floorf(log10(srcAttr));
+ double attributeRange = floor(log10(attr));
+ double sourceAttributeRange = floor(log10(srcAttr));
if (attributeRange != sourceAttributeRange) {
[super dealloc];
@@ -165,9 +173,8 @@ - (void) dealloc {
}
- (CGFloat) transformValue:(CGFloat)original {
- id transformed = [valueTransformer transformedValue:[NSNumber numberWithFloat:original]];
- if ([transformed respondsToSelector:@selector(floatValue)] == NO) { return 0; }
- return [transformed floatValue];
+ id transformed = [valueTransformer transformedValue:[NSNumber numberWithCGFloat_ch:original]];
+ return CHLayoutExtractCGFloat(transformed);
}
- (void) applyToTargetView:(NSView *)target {
View
13 CHLayoutManager.xcodeproj/project.pbxproj
@@ -10,6 +10,7 @@
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
256AC3DA0F4B6AC300CF3369 /* CHLayoutManagerAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* CHLayoutManagerAppDelegate.m */; };
551F7B8F121867DF00A573EE /* SinTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 551F7B8E121867DF00A573EE /* SinTransformer.m */; };
+ 553C2DB71335464700D93628 /* NSNumber+CHLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 553C2DB61335464700D93628 /* NSNumber+CHLayout.m */; };
558686A31215C7910014B300 /* CHLayoutManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 558686A21215C7910014B300 /* CHLayoutManager.m */; };
558686A61215CBD40014B300 /* CHLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 558686A51215CBD40014B300 /* CHLayoutConstraint.m */; };
558686C21215D0C40014B300 /* NSView+CHLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 558686C11215D0C40014B300 /* NSView+CHLayout.m */; };
@@ -32,6 +33,8 @@
550C4453121663CC00E0002B /* CHLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHLayout.h; sourceTree = "<group>"; };
551F7B8D121867DF00A573EE /* SinTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SinTransformer.h; sourceTree = "<group>"; };
551F7B8E121867DF00A573EE /* SinTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SinTransformer.m; sourceTree = "<group>"; };
+ 553C2DB51335464700D93628 /* NSNumber+CHLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNumber+CHLayout.h"; sourceTree = "<group>"; };
+ 553C2DB61335464700D93628 /* NSNumber+CHLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSNumber+CHLayout.m"; sourceTree = "<group>"; };
558686A11215C7910014B300 /* CHLayoutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHLayoutManager.h; sourceTree = "<group>"; };
558686A21215C7910014B300 /* CHLayoutManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHLayoutManager.m; sourceTree = "<group>"; };
558686A41215CBD40014B300 /* CHLayoutConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHLayoutConstraint.h; sourceTree = "<group>"; };
@@ -68,6 +71,8 @@
256AC3D90F4B6AC300CF3369 /* CHLayoutManagerAppDelegate.m */,
551F7B8D121867DF00A573EE /* SinTransformer.h */,
551F7B8E121867DF00A573EE /* SinTransformer.m */,
+ 553C2DB51335464700D93628 /* NSNumber+CHLayout.h */,
+ 553C2DB61335464700D93628 /* NSNumber+CHLayout.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -166,7 +171,14 @@
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "CHLayoutManager" */;
compatibilityVersion = "Xcode 3.1";
+ developmentRegion = English;
hasScannedForEncodings = 1;
+ knownRegions = (
+ English,
+ Japanese,
+ French,
+ German,
+ );
mainGroup = 29B97314FDCFA39411CA2CEA /* CHLayoutManager */;
projectDirPath = "";
projectRoot = "";
@@ -199,6 +211,7 @@
558686A61215CBD40014B300 /* CHLayoutConstraint.m in Sources */,
558686C21215D0C40014B300 /* NSView+CHLayout.m in Sources */,
551F7B8F121867DF00A573EE /* SinTransformer.m in Sources */,
+ 553C2DB71335464700D93628 /* NSNumber+CHLayout.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
19 NSNumber+CHLayout.h
@@ -0,0 +1,19 @@
+//
+// NSNumber+CHLayout.h
+// CHLayoutManager
+//
+// Created by Dave DeLong on 3/19/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface NSNumber (CHLayout)
+
++ (id)numberWithCGFloat_ch:(CGFloat)cgFloat;
+- (id)initWithCGFloat_ch:(CGFloat)cgFloat;
+
+- (CGFloat)CGFloatValue_ch;
+
+@end
View
34 NSNumber+CHLayout.m
@@ -0,0 +1,34 @@
+//
+// NSNumber+CHLayout.m
+// CHLayoutManager
+//
+// Created by Dave DeLong on 3/19/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSNumber+CHLayout.h"
+
+
+@implementation NSNumber (CHLayout)
+
++ (id)numberWithCGFloat_ch:(CGFloat)cgFloat {
+ return [[[self alloc] initWithCGFloat_ch:cgFloat] autorelease];
+}
+
+- (id)initWithCGFloat_ch:(CGFloat)cgFloat {
+#if CGFLOAT_IS_DOUBLE
+ return [self initWithDouble:cgFloat];
+#else
+ return [self initWithFloat:cgFloat];
+#endif
+}
+
+- (CGFloat)CGFloatValue_ch {
+#if CGFLOAT_IS_DOUBLE
+ return [self doubleValue];
+#else
+ return [self floatValue];
+#endif
+}
+
+@end

0 comments on commit 8f3abfa

Please sign in to comment.