let cookie = HTTPCookie(properties: [
.name: "name1",
.value: "value1",
.path: "/",
.originURL: URL(string: "https://hoge.com")! // StringでもOK
])!
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
// `public convenience init?(contentsOf url: URL)` | |
// というメソッドがあるが、Objective-Cからは見えず、Swiftからは引数型で区別できる。 | |
// もっと良い名前があれば変更する。 | |
extension NSMutableArray { | |
public convenience init<S : Sequence>(contentsOf newElements: S) { | |
self.init() | |
newElements.forEach(self.add) | |
} | |
} |
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
public protocol BundleSearchable { | |
static func searchBundle() -> Bundle? | |
} | |
extension BundleSearchable { | |
public static func searchBundle() -> Bundle? { | |
if let anyClass = self as? AnyClass { | |
return Bundle(for: anyClass) | |
} else { | |
return nil |
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
public struct Storyboard { | |
public init(_ name: String, bundle: Bundle? = nil) { | |
self.name = name | |
self.bundle = bundle | |
} | |
public var name: String | |
public var bundle: Bundle? | |
public func instantiate<VCType>(_ vcType: VCType.Type = VCType.self, identifier: String? = nil) -> VCType? { | |
if let identifier = identifier { |
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 array: [Int] = [1, 2, 3, 4] | |
for (first, second) in zip(array.dropLast(), array.dropFirst()) { | |
print(first, second) | |
} | |
extension Array { | |
func eachConsecutive(_ number: Int, body: (ArraySlice<Element>) -> Void) { | |
var lower = 0 |
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
#!/bin/bash | |
# 要pandoc。mac環境に依存している。 | |
# `pbpaste`: クリップボードの内容をペースト | |
# `pbcopy`: クリップボードにコピー | |
pandoc --from=markdown --to=textile <(pbpaste) | pbcopy | |
# githubのmarkdownの場合 | |
# pandoc --from=markdown_github --to=textile <(pbpaste) | pbcopy |
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 | |
public struct MIMEType: RawRepresentable, CustomStringConvertible { | |
public var rawValue: String | |
public var description: String { rawValue } | |
public init?(rawValue: String) { | |
self.rawValue = rawValue | |
} |
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
public class Publisher<Subscriber> { | |
private class Disposer { | |
private let disposing: () -> Void | |
fileprivate init(disposing: @escaping () -> Void) { | |
self.disposing = disposing | |
} | |
deinit { |
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
public struct CircularBuffer<Element> { | |
var beginIndex: Int | |
var endIndex: Int? | |
var buffer: [Element?] | |
var capacity: Int { | |
return buffer.count | |
} |
OlderNewer