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
PROMOTION DEMOTION | |
(init?) (init) | |
[~~~~~~~~~~~AnyRandomAccessCollection~~~~~~~~~~~] | |
^ ^ | | | |
| | | | | |
| | v | | |
| [~~AnyBidirectionalCollection~~] | | |
| ^ | | | |
| | | | | |
| | v v |
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
// | |
// ExampleCode.swift | |
// | |
import UIKit | |
// MARK: - Protocol | |
protocol SearchQueryProviderProtocol : class { // 'class' means only class types can implement it | |
func searchQueryData() -> String |
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
import UIKit | |
// Running on Xcode 7.0 beta (7A121l) | |
// All running in a playground | |
// Open console (View -> Debug Area -> Show Debug Area) | |
// Define a non-generic free fn taking 1 arg | |
func notGeneric(x: String) { | |
print("notGeneric called") | |
} |
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
import UIKit | |
/// A very simple example view that can accept keyboard input and add or delete text from an enclosed label. | |
class CustomTextInputView : UIControl, UIKeyInput { | |
var label : UILabel? | |
override func canBecomeFirstResponder() -> Bool { | |
return true | |
} |
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
// Released under the terms of the MIT license. | |
struct PrefixedPostfixedSequence<T : SequenceType, U where U == T.Generator.Element> : SequenceType { | |
private let sequence : T | |
private let initial : U? | |
private let final : U? | |
init(_ sequence: T, initial: U? = nil, final: U? = nil) { | |
self.sequence = sequence | |
self.initial = initial |
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
import Foundation | |
// Build this as an OS X command line project, then run it. It should never terminate. | |
enum Value<T> { | |
case Nil | |
case Cons(T, LinkedList<T>) | |
} | |
final class LinkedList<T> { |
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
// Set up mentions plug-in | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
HKWMentionsChooserPositionMode mode = HKWMentionsChooserPositionModeEnclosedTop; | |
NSCharacterSet *controlCharacters = [NSCharacterSet characterSetWithCharactersInString:@"@+"]; | |
HKWMentionsPlugin *mentionsPlugin = [HKWMentionsPlugin mentionsPluginWithChooserMode:mode | |
controlCharacters:controlCharacters | |
searchLength:3]; | |
self.plugin = mentionsPlugin; | |
mentionsPlugin.delegate = [MentionsManager sharedInstance]; |
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
// Text transformer (palindrome) | |
[self.textView transformSelectedTextWithTransformer:^NSAttributedString *(NSAttributedString *input) { | |
NSString *rawInput = [input string]; | |
NSMutableString *buffer = [NSMutableString string]; | |
unichar stackC; | |
for (NSInteger i=[rawInput length] - 1; i>=0; i--) { | |
stackC = [rawInput characterAtIndex:i]; | |
[buffer appendString:[NSString stringWithCharacters:&stackC length:1]]; | |
} | |
NSDictionary *attrs = [input attributesAtIndex:0 effectiveRange:NULL]; |
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
protocol InitProtocol { init() } | |
struct SomeStruct<T: InitProtocol> { | |
var x: T? = nil | |
mutating func instantiate() { | |
if x == nil { | |
x = T() | |
} | |
} | |
} |
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
// Playground - noun: a place where people can play | |
import Cocoa | |
enum Wildcard : NilLiteralConvertible { | |
case Single | |
case FromBeginning | |
case ToEnd | |
case Range(Int) | |
case Literal(Int) |