Skip to content

Instantly share code, notes, and snippets.

View samdmarshall's full-sized avatar
💭
I will be slow to respond.

Samantha Demi samdmarshall

💭
I will be slow to respond.
View GitHub Profile
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
uint32_t check_image(const struct mach_header *mh) {
struct mach_header *imageHeader;
uint32_t index;
for (index = 0; index < _dyld_image_count(); index++) {
imageHeader = (struct mach_header *)_dyld_get_image_header(index);
if ((int)memcmp(imageHeader, mh, sizeof(struct mach_header)) == 0) {
@samdmarshall
samdmarshall / 1. goto vs early return.c
Last active June 29, 2016 19:12
basic example of a goto versus an early return statement in C
#include <stdio.h>
int add_goto(int a, int b)
{
int c;
if (a == 0) {
c = b;
goto return_statement;
}
include "root.xcconfig"
include "codesign.xcconfig"
setting PODS_ROOT {
for * {
${SRCROOT}/Pods
}
}
# these are some places you can put comments
include "root.xcconfig" # like here
include "codesign.xcconfig"
# or here
setting PODS_ROOT {
for * {
${SRCROOT}/Pods
}
}
setting PODS_ROOT
for * {
${SRCROOT}/Pods
}
setting HEADER_SEARCH_PATHS
for * {
$(inherited),
"${PODS_ROOT}/Headers/Public",
"${PODS_ROOT}/Headers/Public/AFNetworking",
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSMapTable *table = [NSMapTable mapTableWithKeyOptions:(NSPointerFunctionsIntegerPersonality | NSPointerFunctionsOpaqueMemory) valueOptions:NSPointerFunctionsObjectPersonality];
NSMapInsert(table, (void *)1, (__bridge void *)@"hello");
NSMapInsert(table, (void *)2, (__bridge void *)@"world");
NSMapEnumerator mapEnum = NSEnumerateMapTable(table);
for (NSUInteger pair = 0; pair < NSCountMapTable(table); pair++) {
Samantha@Pegasus:~/Desktop $ cat crash.m
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSMapTable *table = [NSMapTable mapTableWithKeyOptions:(NSPointerFunctionsIntegerPersonality | NSPointerFunctionsOpaqueMemory) valueOptions:NSPointerFunctionsObjectPersonality];
NSMapInsert(table, (void *)1, (__bridge void *)@"hello");
NSMapInsert(table, (void *)2, (__bridge void *)@"world");
NSLog(@"%@",[[table keyEnumerator] allObjects]);
@samdmarshall
samdmarshall / MyDelegateProxy.h
Created April 4, 2016 15:06
NSProxy to register multiple delegates
#import <Foundation/Foundation.h>
#import "MyDelegate.h"
@interface MyDelegateProxy : NSProxy
@property (nonatomic, weak, readonly) id<MyDelegate> primary;
@property (nonatomic, readonly) NSHashTable *secondary;
- (instancetype)init;
AppleFileSystemDriver-21
AppleRAID-5
AvailabilityVersions-20
BootCache-114
CPAN-57
CPANInternal-162
Chess-318
CommonCrypto-60074
DiskArbitration-277
Heimdal-452.1.1

Xcode loads xcspec files (ascii plists) that specify everything (tools, buildphases, compilers, rules, etc) based on a set of conditions.

To evaluate these conditions you have to load these files and simulate the build process and construct your own "environment"

The target's build settings will help to resolve most of the environment variables by taking the basics from the particular platform you are using for the target (resolved from the SDKROOT value xcrun --show-sdk-platform-path --sdk)

when you load the spec of the compiler there is a key on it called "Options" which is an array of dictionaries that have