Skip to content

Instantly share code, notes, and snippets.

View richimf's full-sized avatar
:octocat:
Coding...

Ricardo Montesinos richimf

:octocat:
Coding...
View GitHub Profile
@richimf
richimf / prot_disp.swift
Last active December 15, 2018 21:06
Protocol dispatching
// MARK: - Protocol definitions
protocol InputProtocol {
var a: Int { get }
var b: Int { get }
}
protocol Addition: InputProtocol {}
extension Addition {
func operation() -> Int{
return a + b
@richimf
richimf / FindCopy.sh
Created January 10, 2019 17:59
Find and Copy files bash
declare -a arr=("MyClass1.swift" "MyClass2.swift" "MyClass3.swift")
## now loop through the above array
for i in "${arr[@]}"
do
echo "$i"
find /Users/richie/myapp-ios -name "$i" -exec cp '{}' /Users/richie/Desktop/${i} \;
done
@richimf
richimf / extensions.md
Last active January 22, 2019 22:45
Coredata with Extensions

PUT YOUR DATABASE IN THE SHARED CONTAINER This method simply returns the URL of the Documents directory in the App bundle.

  lazy var applicationDocumentsDirectory: NSURL = {
    let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return urls[urls.count-1] as NSURL
  }()
 
private func setup() {
self.addTarget(self, action: #selector(beginEditing), for: UIControl.Event.editingDidBegin)
self.addTarget(self, action: #selector(textDidChange), for: UIControl.Event.editingChanged)
self.addTarget(self, action: #selector(textEndEditing), for: UIControl.Event.editingDidEnd)
}
@objc func beginEditing() {
print(#function)
}
@richimf
richimf / Observer.swift
Created March 13, 2019 03:34
Observer Pattern
protocol Observer {
func update()
}
class ConcreteObserver: Observer {
var id: String
init(id: String) {
self.id = id
}
func update() {
@richimf
richimf / protocolGenerics.swift
Last active September 29, 2019 21:26
Protocol with Generics
import UIKit
// Creamos un Protocolo
protocol Beverage {
func brewed() -> Self
}
//Creamos una funcion Generic donde el tipo T conforma al Protocolo
func serve<T>(_ drink: T) -> T where T: Beverage {
print("Se ejecuto metodo del generic \(drink.self)")
@richimf
richimf / strategyPattern.swift
Created April 25, 2019 22:12
Strategy Pattern in Swift
import UIKit
/*
What:
A protocol that defines the action we want to encapsulate.
Who:
An object who contains an object who conforms the strategy.
How:
@richimf
richimf / GitHelp.md
Last active March 3, 2020 20:28
Comandos de Git

Git

Ver diferencias de cambios

Una vez modificado un archivo, podemos ver los cambios con:

git diff

Deshacer cambios

@richimf
richimf / GCD.swift
Last active August 20, 2019 18:48
Grand Central Dispatch (GCD) and NSOperationQueue frameworks.
//
/*
In iOS, Apple provides two ways to do multitasking:
The Grand Central Dispatch (GCD) and NSOperationQueue frameworks.
Both of them work perfectly when it’s time to assign tasks to different threads, or different queues other than the main one.
Which one should be use is a subjective matter, but in this tutorial we’ll focus on the first one, the GCD.
*No matter what,there’s one rule that should be always respected:
The main thread must be always remain free so it serves the user interface and user interactions.
@richimf
richimf / buttonAnimationExtension.swift
Created October 5, 2019 03:52 — forked from SAllen0400/buttonAnimationExtension.swift
Core Animation on UIButton Example
// Swift 3
extension UIButton {
func pulsate() {
let pulse = CASpringAnimation(keyPath: "transform.scale")
pulse.duration = 0.6
pulse.fromValue = 0.95
pulse.toValue = 1.0