Skip to content

Instantly share code, notes, and snippets.

View bartjacobs's full-sized avatar

Bart Jacobs bartjacobs

View GitHub Profile
@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
- (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;
import Foundation
enum API {
static let baseURL = URL(string: "https://cocoacasts.com")!
}
class NetworkManager {
import Foundation
struct WeatherDayData {
let time: Date
let icon: String
let windSpeed: Double?
let temperatureMin: Double
let temperatureMax: Double
import UIKit
protocol ReusableView {
static var reuseIdentifier: String { get }
}
extension ReusableView {
@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 Unbox
struct Restaurant: Unboxable {
let features: [Feature]
init(unboxer: Unboxer) throws {
self.features = try unboxer.unbox(key: "features")
}
}
@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
}
@bartjacobs
bartjacobs / using-fatal-errors-to-add-clarity-and-elegance-to-swift-3.swift
Created January 27, 2019 09:43
Using Fatal Errors to Add Clarity and Elegance to Swift - 3
import Foundation
enum Section: Int {
case news
case profile
case settings
var title: String {
switch self {
@bartjacobs
bartjacobs / using-fatal-errors-to-add-clarity-and-elegance-to-swift-1.swift
Created January 27, 2019 09:46
Using Fatal Errors to Add Clarity and Elegance to Swift - 1
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: SettingsTableViewCell.reuseIdentifier, for: indexPath) as? SettingsTableViewCell {
// Configure Cell
cell.textLabel?.text = "Some Setting"
return cell
} else {
return UITableViewCell()
}