Skip to content

Instantly share code, notes, and snippets.

@CodaFi
Last active July 30, 2016 07:45
Show Gist options
  • Select an option

  • Save CodaFi/8b81dfd853c197a910bc to your computer and use it in GitHub Desktop.

Select an option

Save CodaFi/8b81dfd853c197a910bc to your computer and use it in GitHub Desktop.
Faking namespaces with the new objc_runtime_name. Interestingly, this won't stop the compiler from complaining if you declare two classes of the same name but different namespace, but the runtime representation of the two classes would be different if put into two different frameworks. https://twitter.com/bavarious/status/489461621308522496
// Created by Robert Widmann on 7/16/14.
// Copyright (c) 2014 CodaFi. All rights reserved.
//
#define stringify(x) #x
#define namespaced_interface(space, klass) class NSObject; \
__attribute__((objc_runtime_name(stringify(space.klass)))) \
@interface klass
#define namespaced_protocol(space, proto) class NSObject; \
__attribute__((objc_runtime_name(stringify(space.proto)))) \
@protocol proto
// Produces a runtime class of Asterism_Object instead of "Object"
@namespaced_interface(Asterism, Object) : NSObject
@end
// Produces a runtime protocol of Asterism_Coder instead of "Coder"
@namespaced_protocol(Asterism, Coder) <NSObject>
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment