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 progress(incremented: CGFloat) { | |
| if incremented <= bounds.width { | |
| let fromPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 0, height: bounds.height), cornerRadius: viewCornerRadius) | |
| let toPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: incremented, height: bounds.height), cornerRadius: viewCornerRadius) | |
| progressLayer.path = toPath.cgPath | |
| borderLayer.addSublayer(progressLayer) | |
| let animation = CABasicAnimation(keyPath: "path") | |
| animation.fromValue = fromPath.cgPath |
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 Person { | |
| var name: String { | |
| didSet { | |
| listen?(self) | |
| } | |
| } | |
| var phone: Int { | |
| didSet { | |
| listen?(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
| import UIKit | |
| class ViewController: UIViewController { | |
| weak var containerView: UIView! | |
| weak var button: UIButton! | |
| // Note, when programmatically creating views, you: | |
| // | |
| // - Implement the view hierarchy in `loadView` (not to be confused with `viewDidLoad`) |
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 Human: NSObject { | |
| var name: String | |
| var age: Int | |
| init(name: String, age: Int) { | |
| self.name = name | |
| self.age = age | |
| super.init() | |
| } | |
| } |
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
| protocol LoginViewControllerDelegate: class { | |
| func userDidLogin(data: String) | |
| } | |
| class LoginViewController: UIViewController { | |
| weak var delegate: LoginViewControllerDelegate? | |
| ... | |
| @IBAction func loginButtonPressed(sender:UIButton) { |
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
| private weak var previousSearch: MKLocalSearch? | |
| @IBAction func searchField(_ sender: UITextField) { | |
| // in case user location is shown, only remove non user location annotations | |
| let allAnnotations = mapView.annotations.filter { !($0 is MKUserLocation) } | |
| mapView.removeAnnotations(allAnnotations) | |
| // cancel prior search, if it's still underway; you should always only have one search at a time |
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 ViewController: UIViewController { | |
| override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
| segue.destination.transitioningDelegate = self | |
| } | |
| } | |
| extension ViewController: UIViewControllerTransitioningDelegate { | |
| func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
| return AnimationController(presentationMode: .dismiss) | |
| } |
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
| // | |
| // PieView.swift | |
| // MyApp | |
| // | |
| // Created by Robert Ryan on 6/27/17. | |
| // Copyright © 2017 Robert Ryan. All rights reserved. | |
| // | |
| import UIKit |
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 UIKit | |
| import PromiseKit | |
| // recursive structure for purposes of demo | |
| struct File { | |
| let name: String | |
| let subfiles: [File]? | |
| init(name: String, subfiles: [File]? = nil) { |
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 somefunc(completion: ([String]) -> Void) { | |
| let something = ["One", "Two", "Three", "Four", "Five"] | |
| completion(something) | |
| } | |
| func appending() -> Int { | |
| var strings = [String]() | |
| somefunc { (result) in | |
| for i in 0 ..< result.count{ | |
| strings.append(result[i]) |