Skip to content

Instantly share code, notes, and snippets.

@Kametrixom
Kametrixom / emoji.swift
Created August 3, 2015 20:46
Gets all Emoji Unicode code points from the latest Unicode source and prints them out (as Emoji). Also: Prints out all country flag emojis from "AA" to "ZZ"
import Foundation
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely()
func getAllEmojis(completion: String? -> ()) {
let url = NSURL(string: "http://www.unicode.org/Public/UCD/latest/ucd/EmojiSources.txt")!
NSURLSession.sharedSession().dataTaskWithURL(url) { data, response, error in
guard let data = data where error == nil else {
completion(nil)
protocol ContextError : ErrorType {
mutating func addContext<T>(type: T.Type)
}
protocol Contextualizable {}
extension Contextualizable {
func addContext(var error: ContextError) -> ContextError {
error.addContext(self.dynamicType)
return error
}
// Make this code compile without changing these lines
func raw<T: RawRepresentable>(t: T) -> T.RawValue {
return t.rawValue
}
let array : [E] = [.A(true), .B(1), .C("C")]
array.map(raw)
// Do you like confusion? I like confusion. Make this compile. Some people may find it easier than others
_={${$1($0($2.0))($2.1)[{{({"\($0)"},0)}},{0}]()}}()({$0})(0)
// This one is quite tricky
let returnN = getReturnN()
func availableToIntCollection<C: CollectionType where C.Generator.Element == Int>(c: C) {}
availableToIntCollection([1, 2, 3].lazy.map(returnN))
var a : Int { returnN (n: 3) }
// I really like this one
func doIt(inout s: D) {
if case self = isUniquelyReferenced(&s),
self.`self` = true where self {
self.`self` = { [unowned x = [self, 7] as Self] n in
print(x + n)
} as () -> ()
}
}