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
#!/bin/bash | |
# https://gist.github.com/gavrix/5054182 original | |
source ~/.bash_profile | |
hash oclint &> /dev/null | |
if [ $? -eq 1 ]; then | |
echo >&2 "oclint not found, analyzing stopped" | |
exit 1 | |
fi |
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
class Dummy: NSObject { | |
@objc func barStyle() -> UIStatusBarStyle { | |
return .LightContent | |
} | |
func swizzle() { | |
guard let safariClass = NSClassFromString("SFSafariViewController") else { | |
print("can't swizzle, iOS 8") |
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
// This code does not compile without the following two changes | |
// | |
// 1. add ! to the type of expensiveThing (`String!`) | |
// 2. expensiveThing = nil // set expensiveThing to nil | |
// | |
// This doesn't really make sense to me. Why should I be forced to finish setup, if I'm going to fail? | |
// The swift book explains that this is required, but not the logic behind it: | |
// https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_339 | |
// Search for "Failable Initializers for Classes" | |
// |
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 | |
// work around the currently missing .componentsSeparatedByString method | |
extension String { | |
func split(on: Character) -> [String] { | |
var segments = [String]() | |
var current = "" |
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
// depends on https://github.com/coryalder/LevenshteinSwift | |
class SuggestionController { | |
// has a couple of notable vars: | |
// delegate, where the inputted text is loaded from | |
// rawCompletions, an array of possible suggestions (unfiltered) | |
// autocompletions, the filtered array of suggestions we're offer up to the user | |
func filterAutocompletions() { | |
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
// when specify id as the type, you can use NSObject methods. | |
// when you specify as a custom protocol, you cannot. | |
// UNLESS you say that your custom protocol includes <NSObject> | |
#import <Foundation/Foundation.h> | |
@protocol CustomProtocol // <NSObject> // uncommenting <NSObject> fixes the issue | |
@end |
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
// basic strings | |
var str: String = "Hello," | |
let helloWorld = str + " world" |
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
-(void)viewDidAppear:(BOOL)animated { | |
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:(CGRect){-50,-50,100,100}]; | |
// 0, 0 is center | |
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init]; |
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
// What's the best syntax for this: | |
// no trailing-closures | |
// explicit about what's happening, but those ()'s aren't needed... can we do better? | |
throwActions.filter({ $0.direction == dir }).map({ $0.action() }) | |
// all trailing closures | |
// weirdly looks like we're mapping the block, rather than the result of filtering throwActions using that block. |
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
extension UIImage { | |
func invertedImage() -> UIImage? { | |
let img = CoreImage.CIImage(CGImage: self.CGImage) | |
let filter = CIFilter(name: "CIColorInvert") | |
filter.setDefaults() | |
filter.setValue(img, forKey: "inputImage") |
NewerOlder