Created
April 23, 2015 01:51
-
-
Save adamnemecek/143b3211514d5667d84d to your computer and use it in GitHub Desktop.
nsvalue.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
template<typename T> | |
inline | |
NSValue* NSValueFromStruct(T *object) | |
{ | |
return [NSValue value:object withObjCType:@encode(T)]; | |
} | |
template<typename T> | |
inline | |
T NSValueToStruct(NSValue *value) | |
{ | |
T s = {}; | |
[value getValue:&s]; | |
return s; | |
} | |
void f() | |
{ | |
NSRect r = {}; | |
NSMutableArray *a = [[NSMutableArray alloc] init]; | |
[a addObject:NSValueFromStruct<NSRect>(&r)]; | |
NSLog(@"%@", NSStringFromRect(r)); | |
NSLog(@"%@", a); | |
NSLog(@"%@", NSStringFromRect(NSValueToStruct<NSRect>([a objectAtIndex:0]))); | |
} | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
f(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment