This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //: Playground - noun: a place where people can play | |
| /* | |
| Created by: Gemma del Olmo | |
| */ | |
| import UIKit | |
| class Person { | |
| let age : Int | |
| let firstName : String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //STEPS TO IMPLEMENT STRATEGY PATTERN ON PROTOCOL ORIENTED MVVM VIEWCONTROLLER WITH MVVM CELLS | |
| //1: The ViewController will have a collection of cell viewModels | |
| //2: There must be a drawer class for each cell that implements the cell drawer protocol | |
| //3: Each of the cellViewModels must implement the viewModel generic protocol in order to have a reference to the cellDrawer | |
| //DRAWER AND VIEWMODEL PROTOCOLS | |
| protocol <#YOUR_DRAWER_PROTOCOL_NAME#> { | |
| func cellFor(tableView: UITableView, atIndexPath: IndexPath) -> UITableViewCell | |
| func draw(_ cell: UITableViewCell, cellViewModel: Any, viewModel: <#CONTROLLER_VIEWMODEL_PROTOCOL#>) | |
| func heightFor(tableView: UITableView, atIndexPath: IndexPath, cellViewModel: Any) -> CGFloat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| do { | |
| let testDictionary = ["1": "Foo", | |
| "2": "Bar"] | |
| let JSONData = try JSONSerialization.data(withJSONObject: | |
| testDictionary , | |
| options: .prettyPrinted) | |
| let JSONString = NSString(data: JSONData, | |
| encoding: String.Encoding.ascii.rawValue) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIImageView { | |
| func addImageFromURL(urlString: String) { | |
| guard let imgURL: NSURL = NSURL(string: urlString) else { return } | |
| let request: NSURLRequest = NSURLRequest(url: imgURL as URL) | |
| NSURLConnection.sendAsynchronousRequest( | |
| request as URLRequest, queue: OperationQueue.main, | |
| completionHandler: {(response: URLResponse? ,data: Data? ,error: Error? ) -> Void in | |
| if error == nil { | |
| self.image = UIImage(data: data!) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIColor { | |
| public convenience init(hex: Int) { | |
| let components = ( | |
| R: CGFloat((hex >> 16) & 0xff) / 255, | |
| G: CGFloat((hex >> 08) & 0xff) / 255, | |
| B: CGFloat((hex >> 00) & 0xff) / 255 | |
| ) | |
| self.init(red: components.R, green: components.G, blue: components.B, alpha: 1) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension String { | |
| func validateEmail() -> Bool { | |
| let emailRegEx = "^.+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*$" | |
| let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) | |
| return emailTest.evaluate(with: self) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIImage | |
| { | |
| func tint(color:UIColor) -> UIImage? { | |
| UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale) | |
| guard let context = UIGraphicsGetCurrentContext() else { return nil } | |
| context.scaleBy(x: 1.0, y: -1.0) | |
| context.translateBy(x: 0.0, y: -size.height) | |
NewerOlder