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
/// CodingKeyのマッピングを動的に切り替える | |
protocol CodingKeyMapper { | |
static var mapper: [String: S<Self>.CodingKeys] { get } | |
} | |
extension CodingKeyMapper { | |
static var mapper: [String: S<Self>.CodingKeys] { return [:] } | |
static func key(_ stringValue: String) -> S<Self>.CodingKeys? { | |
return mapper[stringValue] | |
} |
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
// | |
// HashablePerformanceTests.swift | |
// HashableExampleTests | |
// | |
// Created by takasek on 2017/06/18. | |
// Copyright © 2017年 takasek. All rights reserved. | |
// | |
import XCTest |
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 | |
//===----------------------------------------------------------------------===// | |
// CSV Decoder | |
//===----------------------------------------------------------------------===// | |
/// `CSVDecoder` facilitates the decoding of CSV into semantic `Decodable` types. | |
/// structでなくclassなのは、JSONDecoderやPlistDecoderの場合にはoptionを適宜切り替えつつdecodeしていけるようにだと思う | |
/// 実際の Decoder プロトコルへの適合は、fileprivateな _CSVRowDecoder 型を通して行う。 | |
open class CSVDecoder { |
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 | |
struct S1: Codable { | |
let dateFromTimeInterval: Date | |
} | |
struct S2: Codable { | |
let dateFromISO8601: Date | |
} |
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 | |
struct User: Codable { | |
struct Address: Codable { | |
let street: String | |
let city: String | |
let state: String | |
} | |
let name: String | |
let address: Address |
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 | |
struct User: Codable { | |
struct Address: Codable { | |
let street: String | |
let city: String | |
let state: String | |
private enum AddressCodingKeys: CodingKey { | |
case street |
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 Hoge: Equatable, Hashable { | |
let a: Int | |
let b: Int | |
static func == (lhs: Hoge, rhs: Hoge) -> Bool { | |
return lhs.a == rhs.a | |
&& lhs.b == rhs.b | |
} | |
var hashValue: Int { | |
return a | |
} |
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 Propotion {} | |
final class 🐕: Propotion {} | |
final class 🐶: Propotion {} | |
// 👆class継承使ってるけど、 | |
// Swift3.1.1以降は👇でもよさそう? | |
//protocol Propotion {} | |
//struct 🐕: Propotion {} | |
//struct 🐶: Propotion {} |
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
let num = 1 as NSNumber | |
num === num | |
//true | |
(num as Int as NSNumber) === (num as Int as NSNumber) | |
//false | |
(num as UInt as NSNumber) === (num as UInt as NSNumber) | |
//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
import Foundation | |
do { | |
let value = 1 | |
let a = value as AnyObject | |
let b = value as AnyObject | |
a === b //false | |
//値型は、as AnyObjectのタイミングでclassインスタンスにboxingされる | |
//as AnyObjectのタイミングが異なれば、別のclassインスタンスとしてboxingされる |