Skip to content

Instantly share code, notes, and snippets.

@bnham
Created August 1, 2017 16:15
Show Gist options
  • Save bnham/f9a0cf6c1cf232a1fbb1ea8bc8be7c9f to your computer and use it in GitHub Desktop.
Save bnham/f9a0cf6c1cf232a1fbb1ea8bc8be7c9f to your computer and use it in GitHub Desktop.
test2
#import <Foundation/Foundation.h>
class ObjectWrapper {
public:
ObjectWrapper(id obj);
id get();
void set(id obj);
private:
id obj_;
};
@interface Foo : NSObject
+ (ObjectWrapper)foo;
@end
#import "foo.h"
ObjectWrapper::ObjectWrapper(id obj)
: obj_(obj) {
}
id ObjectWrapper::get() {
return obj_;
}
void ObjectWrapper::set(id obj) {
obj_ = obj;
}
@implementation Foo
+ (ObjectWrapper)foo {
const char *status = (self == [Foo class]) ? "CORRECT" : "INCORRECT";
NSLog(@"%s: receiver is %s", __func__, status);
return ObjectWrapper{[[NSObject alloc] init]};
}
@end
all: test2-arc-caller test2-mrr-caller
.PHONY: all
CXXFLAGS = -gdwarf -std=c++11
LDLIBS = -framework Foundation
test2-arc-caller: test2.mm foo.h foo.mm
$(CXX) $(CXXFLAGS) -fobjc-arc -o test2-arc.o -c test2.mm
$(CXX) $(CXXFLAGS) -fobjc-arc -o foo-arc.o -c foo.mm
$(CXX) $(LDFLAGS) $(LDLIBS) -o $@ test2-arc.o foo-arc.o
test2-mrr-caller: test2.mm foo.h foo.mm
$(CXX) $(CXXFLAGS) -fno-objc-arc -o test2-mrr.o -c test2.mm
$(CXX) $(CXXFLAGS) -fobjc-arc -o foo-arc.o -c foo.mm
$(CXX) $(LDFLAGS) $(LDLIBS) -o $@ test2-mrr.o foo-arc.o
clean:
rm -rf test2-* *.o
.PHONY: clean
#import <Foundation/Foundation.h>
#import "foo.h"
int main() {
@autoreleasepool {
[Foo foo];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment