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 A { | |
func hoge() -> String? { | |
return "a" | |
} | |
} | |
class B : A { | |
override func hoge() -> String { | |
return "b" | |
} |
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
data class User(val name: String, val id: Int) | |
fun getUser(): User { | |
return User("Alex", 1) | |
} | |
fun main(args: Array<String>) { | |
val user = getUser() | |
println("name = ${user.name}, id = ${user.id}") |
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
// シャドーイング | |
let value: Optional<Int> = 10 | |
// 同名の変数の定義で元の変数へのアクセスを制限する機能 | |
// この例ではOptional Binding | |
if let value = value { | |
print(1 + 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
//構造体かクラスかでletで固められる影響範囲が異なる感じ | |
//値型 | |
struct Value { | |
var name: String = "" | |
} | |
//参照型 | |
class Object { | |
var name: 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
//構造体かクラスかでletで固められる影響範囲が異なる感じ | |
//値型 | |
struct Value { | |
var name: String = "" | |
} | |
//参照型 | |
class Object { | |
var name: 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
func unreachableDefer() { | |
print(#function + " start") | |
if true { return } | |
// It will not execute because unreachable | |
defer { print("defer-1") } | |
print(#function + " 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
enum Color : Int { | |
case Red, Green, Blue | |
case Dummy | |
} | |
extension Color: ForwardIndexType { | |
func successor() -> Color { | |
return Color(rawValue: self.rawValue + 1) ?? Color.Dummy | |
} | |
} |
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
enum FizzBuzzResult { | |
case FIZZ | |
case BUZZ | |
case FIZZBUZZ | |
case OTHERS(Int) | |
func toString() -> String { | |
switch self { | |
case .FIZZ: return "Fizz" | |
case .BUZZ: return "Buzz" |
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
1> "100".toInt() | |
$R0: Int? = 100 | |
2> var a = 250 | |
a: Int = 250 | |
3> func sum(val1:Int, val2:Int)->Int{ | |
4. return val1 + val2 | |
5. } | |
6> | |
7> sum(10, 20) | |
$R1: Int = 30 |
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
/** | |
* エンコードから除外したいプロパティを記載する | |
*/ | |
+ (NSDictionary *)encodingBehaviorsByPropertyKey { | |
NSDictionary *excludeProperties = @{ | |
NSStringFromSelector(@selector(keyChainStore)): @(MTLModelEncodingBehaviorExcluded) | |
}; | |
NSDictionary *encodingBehaviors = [[super encodingBehaviorsByPropertyKey] mtl_dictionaryByAddingEntriesFromDictionary:excludeProperties]; | |
return encodingBehaviors; | |
} |