Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
---- example.h ----
#import <Foundation/Foundation.h>
#ifndef __has_feature // Optional.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#if __has_feature(attribute_ns_returns_not_retained)
#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
extern NSString *someFunction1(void) NS_RETURNS_NOT_RETAINED;
extern NSString *someFunction2(void) NS_RETURNS_NOT_RETAINED;
---- example.m ----
#import "example.h"
NSString *someFunction1()
return @"someFunction1";
NSString *someFunction2()
return @"someFunction2";
---- compilation ----
$ clang -framework Foundation -Xclang -ast-dump example.m | grep someFunction
|-FunctionDecl 0x10450ca90 <./example.h:15:1, /System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:137:72> someFunction1 'NSString *(void)' extern
|-FunctionDecl 0x10450cc00 <./example.h:16:1, /System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:137:72> someFunction2 'NSString *(void)' extern
|-FunctionDecl 0x10450cd30 <example.m:3:1, line:6:1> someFunction1 'NSString *(void)'
| | `-StringLiteral 0x10450ce18 <col:11> 'char [14]' lvalue "someFunction1"
`-FunctionDecl 0x10450cee0 <example.m:8:1, line:11:1> someFunction2 'NSString *(void)'
| `-StringLiteral 0x10450cfc8 <col:11> 'char [14]' lvalue "someFunction2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment