button.imageView?.contentMode = .scaleAspectFit
button.contentHorizontalAlignment = .fill
button.contentVerticalAlignment = .fill
コードを書くと実行時にAspect Fitになる。 Interface Builder上では正しく表示されない。
IBDesignableで指定できるボタンを作ると便利かも?
public struct CircularBuffer<Element> { | |
var beginIndex: Int | |
var endIndex: Int? | |
var buffer: [Element?] | |
var capacity: Int { | |
return buffer.count | |
} |
public class Publisher<Subscriber> { | |
private class Disposer { | |
private let disposing: () -> Void | |
fileprivate init(disposing: @escaping () -> Void) { | |
self.disposing = disposing | |
} | |
deinit { |
import Foundation | |
public struct MIMEType: RawRepresentable, CustomStringConvertible { | |
public var rawValue: String | |
public var description: String { rawValue } | |
public init?(rawValue: String) { | |
self.rawValue = rawValue | |
} |
#!/bin/bash | |
# 要pandoc。mac環境に依存している。 | |
# `pbpaste`: クリップボードの内容をペースト | |
# `pbcopy`: クリップボードにコピー | |
pandoc --from=markdown --to=textile <(pbpaste) | pbcopy | |
# githubのmarkdownの場合 | |
# pandoc --from=markdown_github --to=textile <(pbpaste) | pbcopy |
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 |
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 { |
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 |
// `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) | |
} | |
} |