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
| public class CGRectUtility { | |
| // MARK: Geometry Methods | |
| public class func GMCenteredRectWithinRect(rect: CGRect, containerRect: CGRect) -> CGRect | |
| { | |
| var r: CGRect = rect | |
| r.origin.y = containerRect.size.height / 2 - (r.size.height / 2) | |
| r.origin.x = containerRect.size.width / 2 - (r.size.width / 2) | |
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 | |
| extension Double { | |
| mutating func round(to places: Int) -> Double { | |
| let divisor = pow(10.0, Double(places)) | |
| return Darwin.round(self * divisor) / divisor | |
| } | |
| } |
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 | |
| extension UIViewController { | |
| func hideKeyboardWhenTappedAround() { | |
| let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) | |
| view.addGestureRecognizer(tap) | |
| } | |
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 | |
| extension String { | |
| /* Get length of string */ | |
| var length: Int { | |
| return self.characters.count | |
| } | |
| /* Trim leading or trailing white spaces */ |
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
| class TimerTestViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| Timer.scheduledTimer(timeInterval: interval, target: self, | |
| selector: #selector(ViewController.methodToRepeat(timer:)), | |
| userInfo: nil, repeats: true) | |
| } |
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
| func selectionSort<T: Comparable>(_ a:[T]) -> [T] { | |
| guard array.count > 1 else { return array } | |
| var array = a | |
| for i in 0..<array.count { | |
| if let min = Array(array[i..<array.count]).min() { | |
| if let idx = array.index(of: min) { | |
| array.swapAt(i, idx) | |
| } |
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
| /* | |
| https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
| The sieve of Eratosthenes is one of the most efficient way to find all prime numbers up to any given limit. | |
| It's a simple and ancient algorithm that is know for it's performance. Here is a swift flavor of this algorithm. | |
| */ | |
| func sieveOfEratosthenes(number n: UInt) -> [UInt] { | |
| var list = Array(2...n) | |
| list = list.filter { |
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
| struct Address { | |
| let unitNumber: String | |
| let buildingNumebr: String | |
| } | |
| struct Residance { | |
| var numberOfRooms: Int | |
| var address: Address | |
| } |
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
| enum Direction { | |
| case up | |
| case down | |
| case left | |
| case right | |
| } | |
| struct Position { | |
| var x: Int | |
| var y: Int |
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
| class Machine { | |
| let model: String | |
| var make: String | |
| init(model: String, make: String) { | |
| self.model = model | |
| self.make = make | |
| } | |
| } |
OlderNewer