Skip to content

Instantly share code, notes, and snippets.

@Adobe-Android
Last active May 25, 2020 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adobe-Android/e0ac8d85d5eb277c50d56545d6165c48 to your computer and use it in GitHub Desktop.
Save Adobe-Android/e0ac8d85d5eb277c50d56545d6165c48 to your computer and use it in GitHub Desktop.
My Objective-C collection (using GNUstep)
// ARC environment
#import <stdio.h>
int main( int argc, const char *argv[] ) {
@autoreleasepool {
// Code benefitting from a local autorelease pool.
NSLog(@"Hello, World!");
}
}
// A way to test that Automatic Reference Counting (ARC) is working as expected in Objective-C
#import <stdio.h>
int main( int argc, const char *argv[] ) {
if (__has_feature(objc_arc)) {
printf("ARC is working.");
return 0;
} else {
printf("ARC is not working.");
return -1;
}
}
#!/bin/bash
# ======================================================================
# COMPILE USING THE FOLLOWING COMMAND LINE
# ======================================================================
# Set compiler
if [ -x "$(command -v ${CC})" ]; then
echo "Using CC from environment variable: ${CC}"
else
if [ -x "$(command -v clang-9)" ]; then
CC=clang-9
elif [ -x "$(command -v clang-8)" ]; then
CC=clang-8
elif [ -x "$(command -v clang-6.0)" ]; then
CC=clang-6.0
elif [ -x "$(command -v clang)" ]; then
CC=clang
else
echo 'Error: clang seems not to be in PATH. Please check your $PATH.' >&2
exit 1
fi
fi
# Using COMMAND LINE
echo "Compiling and running $1."
# With ARC
${CC} `gnustep-config --objc-flags` `gnustep-config --objc-libs` -fobjc-arc -lobjc -lgnustep-base $1.m -o $1
# Without ARC
# ${CC} `gnustep-config --objc-flags` `gnustep-config --objc-libs` -lobjc -lgnustep-base $1.m -o $1
./$1
// Non-ARC environment
#import <stdio.h>
int main( int argc, const char *argv[] ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Code benefitting from a local autorelease pool.
NSLog(@"Hello, World!");
[pool release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment