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
| extension Card { | |
| init(_ notation: String) { | |
| self.suit = Suit(rawValue: String(notation.prefix(1)))! | |
| self.rank = Rank(rawValue: String(notation.suffix(notation.characters.count - 1)))! | |
| } | |
| } | |
| card = Card("♥1") |
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
| // | |
| // SynchronizeScrollMediatorTest.swift | |
| // CollectionViewInTableViewTests | |
| // | |
| // Created by tanaka.kenji on 2018/02/16. | |
| // Copyright © 2018年 tanaka.kenji. All rights reserved. | |
| // | |
| import XCTest | |
| @testable import Hoge |
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 UIKit | |
| class SynchronizeScrollMediator: NSObject { | |
| // MARK: - Base | |
| private(set) weak var synchronizer: UIScrollView! | |
| private(set) weak var synchronizee: UIScrollView! | |
| private let synchronizeKeyPath = "contentOffset" | |
| init(synchronizer: UIScrollView, synchronizee: UIScrollView) { |
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
| #!/bin/bash | |
| set -eu | |
| while getopts p: OPT | |
| do | |
| case $OPT in | |
| "p" ) | |
| FILE_PATH=$OPTARG;; | |
| esac |
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
| #!/bin/sh | |
| set -xe | |
| HTTP_RESPONSE=$(curl -X POST --silent <url>) | |
| # { "hoge": "fuga" } | |
| VALUE=$(echo $HTTP_RESPONSE | jq '.hoge') | |
| # "fuga" が出力される |
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
| URL="http://stackoverflow.com/" | |
| # store the whole response with the status at the and | |
| HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST $URL) | |
| # extract the body | |
| HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g') | |
| # extract the status | |
| HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') |
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
| private func calculateImageHeight(fromImageSize imageSize: CGSize, imageViewWidth: CGFloat) -> CGFloat { | |
| let aspectRatio = imageSize.width / imageViewWidth | |
| let imageHeight = imageSize.height / aspectRatio | |
| return imageHeight | |
| } |
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
| enum SomeError: Error, Equatable { | |
| case a | |
| case b | |
| // Equatableプロトコル準拠。caseを判別するためにhashValueを比較する | |
| static func ==(lhs: MockError, rhs: MockError) -> Bool { | |
| return lhs.hashValue == rhs.hashValue | |
| } | |
| } |
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 documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String | |
| // ファイル内に書き込む情報 | |
| let fileObject = "\(userInfo)" | |
| // ファイル名 | |
| let fileName = "file.txt" | |
| let filePath = documentPath + "/" + fileName | |
| do { | |
| try fileObject.write(toFile: filePath, atomically: true, encoding: String.Encoding.utf8) | |
| } catch { | |
| () |
NewerOlder