(w, h)
| Orientation | Full Screen | Split View 2/3 | Split View 1/2 | Split View 1/3 |
|---|---|---|---|---|
| Portrait | R, R | C, R | - | C, R |
| import UIKit | |
| public protocol NibNameableView: class { | |
| static var nibName: String { get } | |
| } | |
| extension NibNameableView where Self: UIView { | |
| public static var nibName: String { | |
| return String(describing: self) | |
| } |
| import UIKit | |
| public class ScrollableStackView: UIView { | |
| // MARK: Properties | |
| private var didSetupConstraints = false | |
| private lazy var scrollView: UIScrollView = { | |
| let scrollView = UIScrollView(frame: .zero) |
| 1. Install oh my zsh | |
| http://ohmyz.sh/ | |
| $ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
| 1. Install powerline fonts | |
| https://github.com/powerline/fonts | |
| 1. download agnoster theme | |
| https://github.com/mbadolato/iTerm2-Color-Schemes/zipball/master |
| // Swift 3 | |
| extension DateFormatter { | |
| public static var iso8601: DateFormatter { | |
| return DateFormatter.iso8601DateFormatter | |
| } | |
| private static let iso8601DateFormatter: DateFormatter = { | |
| let formatter = DateFormatter() | |
| formatter.locale = Locale(identifier: "en_US_POSIX") |
| extension KeyedDecodingContainer where Key: CodingKey { | |
| func decodeDate(from key: Key, using formats: String...) throws -> Date { | |
| let dateAsString = try decode(String.self, forKey: key) | |
| let dateFormatter = DateFormatter() | |
| for format in formats { | |
| dateFormatter.dateFormat = format | |
| guard let date = dateFormatter.date(from: dateAsString) else { | |
| continue | |
| } | |
| return date |
| // Playground | |
| protocol Option: RawRepresentable, Hashable, CaseIterable {} | |
| extension Set where Element: Option { | |
| var rawValue: Int { | |
| var rawValue = 0 | |
| for (index, element) in Element.allCases.enumerated() where contains(element) { | |
| rawValue |= (1 << index) | |
| } |
| import UIKit | |
| public extension UIApplication { | |
| /// Returns the topmost view controller in the hierarchy of the given view controller. | |
| /// | |
| /// If no parameter passed, by default the function takes the root view controller set for the key window in the application. | |
| /// | |
| /// ```swift | |
| /// UIApplication.shared.keyWindow?.rootViewController | |
| /// ``` |
| let url: URL = "https://api.themoviedb.org/3/movie/now_playing?api_key=\(apiKey)&page=1" | |
| URLSession.shared | |
| .dataTaskPublisher(for: url) | |
| .map(\.data) | |
| .decode(type: MoviesPage.self, decoder: JSONDecoder()) |