Skip to content

Instantly share code, notes, and snippets.

View bartjacobs's full-sized avatar

Bart Jacobs bartjacobs

View GitHub Profile
@bartjacobs
bartjacobs / using-fatal-errors-to-add-clarity-and-elegance-to-swift-2.swift
Created January 27, 2019 09:42
Using Fatal Errors to Add Clarity and Elegance to Swift - 2
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: SettingsTableViewCell.reuseIdentifier, for: indexPath) as? SettingsTableViewCell else { fatalError("Unexpected Index Path") }
// Configure Cell
...
return cell
}
import Unbox
struct Restaurant: Unboxable {
let features: [Feature]
init(unboxer: Unboxer) throws {
self.features = try unboxer.unbox(key: "features")
}
}
@bartjacobs
bartjacobs / UIColor.swift
Created November 2, 2017 17:07
From Hex to UIColor and Back in Swift
import UIKit
extension UIColor {
// MARK: - Initialization
convenience init?(hex: String) {
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
import UIKit
protocol ReusableView {
static var reuseIdentifier: String { get }
}
extension ReusableView {
import Foundation
struct WeatherDayData {
let time: Date
let icon: String
let windSpeed: Double?
let temperatureMin: Double
let temperatureMax: Double
import Foundation
enum API {
static let baseURL = URL(string: "https://cocoacasts.com")!
}
class NetworkManager {
- (void)layoutSubviews {
[super layoutSubviews];
// Helpers
CGRect bounds = self.contentView.bounds;
// Update Frames
CGRect frameTextLabel = self.textLabel.frame;
CGRect frameDetailTextLabel = self.detailTextLabel.frame;
CGRect frameActivityIndicatorView = self.activityIndicatorView.frame;
@bartjacobs
bartjacobs / .gitignore
Last active January 2, 2016 17:09 — forked from adamgit/.gitignore
##############################################
# .gitignore for Xcode 5 Project #
# https://gist.github.com/bartjacobs/8334797 #
##############################################
# Temporary Files OS X
.DS_Store
*.swp
*.lock