This file contains 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
// The difference between declaring a method in a class, a function | |
// outside of a class, and an init method. | |
func foo(#a: String, #b:String) -> String { | |
return a + " " + b | |
} | |
foo(a:"Hello", b:"dude") | |
func foo1(a: String, b: String) -> String { |
This file contains 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
protocol ExampleProtocol { | |
var simpleDescription: String { get } | |
mutating func adjust() | |
} | |
class SimpleClass: ExampleProtocol { | |
var simpleDescription: String = "A very simple class." | |
var anotherProperty: Int = 69105 | |
func adjust() { | |
simpleDescription += " Now 100% adjusted." |
This file contains 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
// Objective-C | |
@implementation NSManagedObject (Helpers) | |
+ (instancetype)createEntity | |
{ | |
id newObject = [NSEntityDescription | |
insertNewObjectForEntityForName:[[self class] description] | |
inManagedObjectContext:[[SACoreDataStack defaultStack] | |
managedObjectContext]]; | |
return newObject; | |
} |
This file contains 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
var nsDict: [NSObject : AnyObject] = ["test" : 4] | |
if let value = nsDict["test"] as? Int { | |
println("It is an Int") | |
} | |
// ERROR: 'Int' is not a subtype of '(NSObject, AnyObject)' | |
if let value = nsDict["test"].1 as? Int { | |
println("It is an Int") | |
} |
This file contains 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
// Objective-C | |
BOOL (^completion) (NSError *, NSDictionary *) = ^BOOL(NSError *error, NSDictionary *data) { | |
// code here | |
return YES; | |
} | |
// Swift | |
let completion: (NSError, [String : AnyObject]) -> Bool = { error, data in | |
// code here | |
return true |
This file contains 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
dispatch_async(dispatch_get_main_queue()) { | |
self.object?.doSomething() | |
return // This is needed for it to compile | |
} |
This file contains 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
// Error Handling // | |
enum Either<T> { | |
case Success(T) | |
case Failure(ErrorType) | |
func getValue() throws -> T { | |
switch self { | |
case .Success(let value): |
This file contains 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
var outletRegex = /<outlet property=\"(.*)\" destination=\"(.*)\" id=\".*\"\/>/g; | |
var xcodeIDRegex = /id=\"(.*)\".*userLabel=\"(.*)\"/g; | |
var customClass = /id=\"(.*)\".*customClass=\"(.*)\"/g; | |
var allDiffs = [].slice.call(document.getElementsByClassName("sidebyside")); | |
for (i = 0; i < allDiffs.length; i++) { | |
if (allDiffs[i].getElementsByClassName("filename-row")[0].textContent.includes(".xib")) { | |
var xibString = allDiffs[i].innerText; | |
var matches, output = []; | |
while (matches = outletRegex.exec(xibString)) { |
This file contains 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
protocol SafeMutation { | |
mutating func safeMutate(_ work: () throws -> ()) rethrows | |
} | |
extension SafeMutation { | |
mutating func safeMutate(_ work: () throws -> ()) rethrows { | |
let old = self | |
do { | |
try work() | |
} catch { |
This file contains 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
#import <Foundation/Foundation.h> | |
/** | |
These methods will not be called on the main thread. So, | |
if you will be doing anything with UIKit, ensure you dispatch back | |
to the main thread. | |
*/ | |
@protocol KSScrollPerformanceDetectorDelegate<NSObject> | |
@optional | |
- (void)framesDropped:(NSInteger)framesDroppedCount cumulativeFramesDropped:(NSInteger)cumulativeFramesDropped cumulativeFrameDropEvents:(NSInteger)cumulativeFrameDropEvents; |
OlderNewer