Skip to content

Instantly share code, notes, and snippets.

@loganwright
loganwright / Obj-C-Runtime Property Names Of Class
Last active August 29, 2015 14:01
Property Names / Attributes of Class
#import <objc/runtime.h>
- (NSArray *) getPropertyNamesForClass:(Class)class {
NSMutableArray * propertyNames = [NSMutableArray array];
// Fetch Properties
unsigned count;
objc_property_t *properties = class_copyPropertyList(class, &count);
// Parse Out Properties
@loganwright
loganwright / Obj-C-Runtime Attributes For Property
Last active August 29, 2015 14:01
Get All Attributes of A Property
#import <objc/runtime.h>
- (NSArray *) attributesForProperty:(objc_property_t)property {
// Get attributes as char
const char * attributes = property_getAttributes(property);
// Make NSString
NSString * attributeString = [NSString stringWithUTF8String:attributes];
// Array of Attributes
NSArray * attributesArray = [attributeString componentsSeparatedByString:@","];
//
// NSNonConcurrentOperation.h
// ConcurrencyPractice
//
// Created by Logan Wright on 5/23/14.
// Copyright (c) 2014 Logan Wright. All rights reserved.
//
#import <Foundation/Foundation.h>
@loganwright
loganwright / 0_reuse_code.js
Created May 23, 2014 23:31
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@loganwright
loganwright / StructWithObjects
Created May 24, 2014 03:38
C-Type Struct With Objective-C Objects
typedef void (^CompletionBlock)(void);
typedef struct {
SEL selector;
__unsafe_unretained id object;
__unsafe_unretained NSArray * arguments;
__unsafe_unretained CompletionBlock completionBlock;
} ExecutableOperationStruct ;
import Cocoa
/* To declare a variable in Swift, simply assign something to it, like below: */
var str = "Hello, playground"
/* As you can see, there is no explicit type declared. This is because type inference will notice that the variable 'str' is being assigned a string and the compiler will infer that str is of type 'String' */
/* You can declare a Type explicitly using a 'Type Annotation' like this */
import Cocoa
// LET vs. VAR
/* Up to this point, we have declared all of our names using the keyword `var`. Swift however makes use of another type of variable declaration with the keyword 'let'. At its most basic, `let` indicates that something is constant and `var` indicates that something is variable. */
/* In the following code, we will create a new constant named `someConstant` that will be an unchanging value */
let someConstant = "I am forever constant"
import Cocoa
/*
Basic Function - Let's jump right into it and create an extremely basic function named 'sayHello' that takes no arguments and has no return.*/
func sayHello() {
println("Hello!")
}
import Cocoa
/*
Up to this point, we've built fairly simple functions that take one or no arguments and return one or no values.
Let's first make a basic function that takes two arguments and returns their sum */
func sum(a: Int, b: Int) -> Int {
return a + b
// Playground - noun: a place where people can play
import Cocoa
/* Classes and Structures
Traditionally, we've referred to instances of a class as "objects" however, because Swift classes and structures are so much alike, it's preferable to use the more general term -- 'Instance'
Even though these two Types have a lot of similarity, they are handled by the system very differently. ***Structures are values which are always copied when they are passed around, whereas Classes use reference counting.*** This means more than one variable can reference a specific class instance, but you will never have multiple references to the same specific instance of a Struct