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
import Foundation | |
class TestDataHelper { | |
// 使い方 | |
// let agreement: Agreement = TestDataHelper.testData(forResource: "Some", ofType: "json") | |
static func testData<T: Decodable>(forResource resource: String, ofType type: String) -> T { | |
let url = Bundle(for: TestDataHelper.self).url(forResource: resource, withExtension: type)! | |
let data = try! Data(contentsOf: url) | |
let decoder = JSONDecoder() |
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
// TODO: async/await実装したい | |
// TODO: ストリームの中でthread指定したい | |
protocol Awaitable { | |
associatedtype Value | |
// なんかDispatchQueueを返すメソッド...? | |
} | |
typealias CompletionHandler<T> = ((T) -> Awaitable<T>) |
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
// FizzBuzzTests.swift | |
import XCTest | |
@testable import FizzBuzz | |
class FizzBuzzTests: XCTestCase { | |
func test数字を渡すとnumberを返す() { | |
XCTContext.runActivity(named: "2を渡した場合") { _ in | |
let fizzBuzz = FizzBuzz(2) | |
XCTContext.runActivity(named: "number(2)を返す") { _ in |
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
do { | |
let realm = try Realm() | |
let favoriteListObjects = realm.objects(FavoriteListObject.self).filter("id like '\(id)'") | |
guard let favoriteListObject = favoriteListObjects.first else { | |
completion(.failure(FavoriteListDataStoreError.deleteError)) | |
return | |
} | |
try realm.write() { |
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 context(named: String, block: (XCTActivity) throws -> (XCTWaiter.Result)) rethrows { | |
_ = try XCTContext.runActivity(named: named, block: block) | |
} | |
class FavoriteListDataStoreTests: XCTestCase { | |
func testSaveFavoriteList() { | |
context(named: "") { activity -> XCTWaiter.Result in | |
return .completed | |
} | |
} |
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
// 参考・関連 | |
// https://qiita.com/omochimetaru/items/2aa00c7cb0eef4e57999 | |
// https://qiita.com/omochimetaru/items/c95e0d36ae7f1b1a9052 | |
// https://stackoverflow.com/questions/24938503/nsobject-is-hashable-but-a-protocol-that-adopts-nsobject-is-not | |
// https://developer.apple.com/documentation/swift/1538988 | |
import Foundation | |
class Hoge {} |
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
//emlist{ | |
func testCardEqual() { | |
XCTAssertEqual( | |
Card(rank: .jack, suit: .club), | |
Card(rank: .jack, suit: .club) | |
) | |
XCTAssertNotEqual( | |
Card(rank: .queen, suit: .diamond), | |
Card(rank: .jack, suit: .club) | |
) |
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 single = Single<Void>.create { singleEvent in | |
let req = Alamofire.request("https://www.google.co.jp/") | |
req.response { response in | |
print("通信完了") | |
} | |
return Disposables.create(with: { | |
print("通信キャンセル") // <- こっちが出た | |
req.cancel() | |
}) |
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 number() -> Int { | |
var x: Int | |
x = 1 | |
return x | |
} | |
func number() -> Int { | |
return 1 | |
} |
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 number() -> Int { | |
let x: Int | |
x = 1 | |
return x | |
} | |
func number() -> Int { | |
return 1 | |
} |