Created
March 24, 2012 00:23
-
-
Save iamleeg/2176672 to your computer and use it in GitHub Desktop.
Using operator overloading with Objective-C. Erm, ++.
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
#include "objc_id.hpp" | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString *s1 = @"hello"; | |
NSString *s2 = [@"hell" stringByAppendingString: @"o"]; | |
if ((objc_id(s1) == objc_id(s2))) { | |
NSLog(@"win"); | |
} | |
else { | |
NSLog(@"fail"); | |
} | |
} | |
return 0; | |
} |
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
#include <objc/objc.h> | |
#import <Foundation/Foundation.h> | |
#ifndef __objc_H_ | |
#define __objc_H_ | |
class objc_id { | |
private: | |
id<NSObject> object; | |
public: | |
objc_id(id<NSObject> theObject) { | |
[theObject retain]; | |
object = theObject; | |
}; | |
bool operator==(const objc_id& other) { | |
return [object isEqual: other.object]; | |
}; | |
~objc_id() { | |
[object release]; | |
}; | |
}; | |
#endif //__objc_H_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment