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
| class User { | |
| typealias MyInt = Int | |
| } | |
| extension User.MyInt { | |
| func say() { | |
| print("MyInt") | |
| } | |
| } | |
| 1.say() // MyInt |
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 P { | |
| func say() | |
| } | |
| class A : P {} | |
| class B : A {} | |
| extension P { | |
| func say() { print("P") } | |
| } |
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
| # app/models/posts/action.rb | |
| class Action | |
| include ActiveModel::Model | |
| attr_reader :post_id, :name | |
| def save | |
| return false if invalid? | |
| @post = Post.find(post_id) |
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
| class Foo { | |
| let number: Int? = nil | |
| } | |
| let m = Mirror(reflecting: Foo()) | |
| let defNumber = m.children.filter { $0.label == "number" }[0] | |
| defNumber.value == nil | |
| // Playground execution failed: MyPlayground.playground:1:17: error: value of type 'Any' (aka 'protocol<>') can never be nil, comparison isn't allowed | |
| // defNumber.value == nil | |
| //~~~~~~~~~~~~~~~ ^ |
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
| // ==UserScript== | |
| // @name WIP Pull Request Unhighlignter | |
| // @author sinsoku | |
| // @version 0.4 | |
| // @match https://github.com/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; |
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
| struct A<T>: Equatable { | |
| let name: String | |
| // 2. 最悪、Tに比較メソッドを実装する | |
| // func == <T>(lhs: A<T>, rhs: A<T>) -> Bool { | |
| // return T.compare(lhs, rhs) | |
| // } | |
| } | |
| func == <T>(lhs: A<T>, rhs: A<T>) -> Bool { | |
| return false |
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
| struct S<T> { | |
| let name: String | |
| } | |
| func m<T>(_ v: S<T>) { | |
| print(1) | |
| } | |
| class C {} | |
| func m<T: C>(_ v: S<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
| protocol P { | |
| static func eq<T>(_ x: A<T>, _ y: A<T>) -> Bool | |
| static func lt<T>(_ x: A<T>, _ y: A<T>) -> Bool | |
| } | |
| struct A<T: P>: Comparable {} | |
| func == <T>(x: A<T>, y: A<T>) -> Bool { | |
| return T.eq(x, y) | |
| } |
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
| struct GridPoint { | |
| var x: Int | |
| var y: Int | |
| } | |
| func ==(lhs: GridPoint, rhs: GridPoint) -> Bool { | |
| return lhs.x == rhs.x && lhs.y == rhs.y | |
| } | |
| extension GridPoint: Hashable { |
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
| struct Container<T> { | |
| var obj: T | |
| } | |
| func factory<T>(objects: T...) -> Array<Container<T>> { | |
| return objects.map { Container<T>(obj: $0) } | |
| } | |
| let c = factory("a", "b") | |
| print(c.dynamicType) |