Skip to content

Instantly share code, notes, and snippets.

View bartjacobs's full-sized avatar

Bart Jacobs bartjacobs

View GitHub Profile
import Combine
let numbers: [Int?] = [1, 2, nil, 3, 4]
numbers.publisher
.filter { $0 != nil }
.sink { print($0) }
numbers.publisher
.compactMap { $0 }
import UIKit
final class CloudinaryURLBuilder {
// MARK: - Properties
private let source: URL
// MARK: -
import UIKit
extension UIColor {
enum Cocoacasts {
static let green = UIColor(red: 0.40, green: 0.36, blue: 0.28, alpha: 1.0)
}
}
// Fetch Video
playbackService.findVideo(withVideoID: id, parameters: nil, completion: { [weak self] (video, _, error) in
if let error = error {
// Handle Error
} else if let video = video {
// Use Video
}
})
// The `playbackService` object is an instance of the `BCOVPlaybackService` class.
var imagesFromCoreData: [Image]? {
guard let _imagesFromCoreData = toImages as? Set<Image> else { return nil }
return Array(_imagesFromCoreData)
}
@bartjacobs
bartjacobs / five-signs-of-code-smell-in-swift-3.m
Created January 27, 2019 09:54
Five Signs of Code Smell in Swift - 3
[managedObjectContext save:nil];
@bartjacobs
bartjacobs / five-signs-of-code-smell-in-swift-2.swift
Created January 27, 2019 09:53
Five Signs of Code Smell in Swift - 2
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == addItemViewController {
if let navigationController = segue.destinationViewController as? UINavigationController,
let addItemViewController = navigationController.viewControllers.first as? AddItemViewController {
addItemViewController.delegate = self
}
}
}
@bartjacobs
bartjacobs / five-signs-of-code-smell-in-swift-1.swift
Created January 27, 2019 09:52
Five Signs of Code Smell in Swift - 1
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == viewController {
let navigationController = segue.destinationViewController as! UINavigationController
let addViewController = navigationController.viewControllers.first as! AddViewController
addViewController.delegate = 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()
}
@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 {