Skip to content

Instantly share code, notes, and snippets.

View darthpelo's full-sized avatar

Alessio Roberto darthpelo

  • Amsterdam, Noord-Holland
View GitHub Profile
@darthpelo
darthpelo / watchType.swift
Created December 7, 2017 10:15
How to determinate Apple Watch model at runtime.
import Foundation
import UIKit // Only to use CGFloat 😬
import WatchKit
enum WatchModelType {
case large
case small
}
struct WatchModel {
@darthpelo
darthpelo / swiftlint.yml
Created March 2, 2018 09:15
Basic aggressive SwiftLint
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Tests
- Pods
- Carthage
- R.generated.swift
- MyPlayground.playground
disabled_rules:
- trailing_whitespace
- multiple_closures_trailing_closure
import Foundation
import Intents
struct SiriService {
struct ActivityInformation {
let activityType: String
let activityTitle: String
let activitySuggestedInvocation: String
}
final class HistoryViewController: BaseViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let information = presenter?.information {
activitySetup(information)
}
}
}
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
return handle(userAcitivity: userActivity)
}
// MARK: - Private
private func handle(userAcitivity activity: NSUserActivity) -> Bool {
switch activity.activityType {
case "com.mobiquity.TakeUrPill.history":
@darthpelo
darthpelo / Email.swift
Last active July 30, 2019 20:26
Improve input validation considering the input as a Type
import Foundation
struct Email {
private var string: String
init(_ string: String) throws {
try Validations.email(string)
self.string = string
}
@darthpelo
darthpelo / EmailValidated.swift
Last active February 2, 2020 14:24
An example regarding how Swift 5.1 Property Wrapper can be useful for a light Input Validation enforcement.
@propertyWrapper
struct EmailValidated {
private(set) var defaultValue: String = ""
var wrappedValue: String {
get { defaultValue }
set { defaultValue = maxLength(newValue) && isValid(newValue)
?
newValue
: