Last active
May 25, 2020 16:03
-
-
Save Adobe-Android/e0ac8d85d5eb277c50d56545d6165c48 to your computer and use it in GitHub Desktop.
My Objective-C collection (using GNUstep)
This file contains hidden or 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
// ARC environment | |
#import <stdio.h> | |
int main( int argc, const char *argv[] ) { | |
@autoreleasepool { | |
// Code benefitting from a local autorelease pool. | |
NSLog(@"Hello, World!"); | |
} | |
} |
This file contains hidden or 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
// 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; | |
} | |
} |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
// 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