Skip to content

Instantly share code, notes, and snippets.

View pedrommcarrasco's full-sized avatar

Pedro Carrasco pedrommcarrasco

View GitHub Profile
@pedrommcarrasco
pedrommcarrasco / how-to-have-multiple-icons.swift
Created June 29, 2019 23:28
How To Have Multiple Icons (Change Icon)
// To set the light icon
UIApplication.shared.setAlternateIconName("light") {
guard let error = $0 else { return }
os_log("Error setting alternative icon: %@", error.localizedDescription)
}
// To set the light icon
UIApplication.shared.setAlternateIconName("dark") {
guard let error = $0 else { return }
os_log("Error setting alternative icon: %@", error.localizedDescription)
@pedrommcarrasco
pedrommcarrasco / how-to-have-multiple-icons
Last active July 22, 2020 11:42
How To Have Multiple Icons (iPad)
<key>CFBundleIcons~ipad</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>default</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
@pedrommcarrasco
pedrommcarrasco / how-to-have-multiple-icons
Last active December 12, 2019 01:14
How To Have Multiple Icons
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>default</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
@pedrommcarrasco
pedrommcarrasco / how-to-be-display-your-dependencies.swift
Last active September 5, 2019 09:11
How To Display Your Dependencies - Parser
struct Acknowledgments: Decodable {
let specs: [Framework]
}
struct Framework: Decodable {
let name: String
let homepage: String
let version: String
}
@pedrommcarrasco
pedrommcarrasco / how-to-be-lazy-in-extensions.swift
Last active February 18, 2019 14:45
How to be Lazy in Extensions - Solution
public extension UIView {
private struct AssociatedKey {
static var constrictor: UInt8 = 0
}
var constrictor: Constrictor {
if let constrictor = objc_getAssociatedObject(self, &AssociatedKey.constrictor) as? Constrictor {
return constrictor
} else {
@pedrommcarrasco
pedrommcarrasco / how-to-be-lazy-in-extensions.swift
Created February 18, 2019 14:05
How to be Lazy in Extensions - First Attempt
lazy var constrictor = Constrictor(object: self)()
//
// ViewController.swift
// Example
//
// Created by Pedro Carrasco on 21/05/2018.
// Copyright © 2018 Pedro Carrasco. All rights reserved.
//
import UIKit
import Constrictor
//
// ViewController.swift
// Example
//
// Created by Pedro Carrasco on 21/05/2018.
// Copyright © 2018 Pedro Carrasco. All rights reserved.
//
import UIKit
import Constrictor
@pedrommcarrasco
pedrommcarrasco / lets-talk-about-double-standards.swift
Last active January 7, 2019 11:15
Let's Talk About: Double Standards - Copy-Pastability (after)
private enum Constant {
static let scenarioAFile = "screenScenarioA"
static let scenarioBFile = "screenScenarioB"
}
func testScenarioA() {
// Arrange & Act
updateStructureWithJSON(named: Constant.scenarioAFile)
let result = screenStructureManager.current
let expectedResult: [Component] = [.header, .products]
@pedrommcarrasco
pedrommcarrasco / lets-talk-about-double-standards.swift
Last active January 7, 2019 11:16
Let's Talk About: Double Standards - Copy-Pastability (before)
private enum Constant {
static let scenarioAFile = "screenScenarioA"
static let scenarioBFile = "screenScenarioB"
}
func testScenarioA() {
// Arrange
guard let filePath = Bundle(for: type(of: self)).path(forResource: Constant.scenarioAFile, ofType: FileType.json),
let data = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
let jsonObject = try? JSONSerialization.jsonObject(with: data, options: .allowFragments),