Skip to content

Instantly share code, notes, and snippets.

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
class Person {
var name: String {
didSet {
listen?(self)
}
}
var phone: Int {
didSet {
listen?(self)
@robertmryan
robertmryan / ViewController.swift
Created May 20, 2017 21:19
Swift 3 Programmatically Created View Hierarchy (i.e. neither storyboard nor NIB)
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`)
class Human: NSObject {
var name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
super.init()
}
}
protocol LoginViewControllerDelegate: class {
func userDidLogin(data: String)
}
class LoginViewController: UIViewController {
weak var delegate: LoginViewControllerDelegate?
...
@IBAction func loginButtonPressed(sender:UIButton) {
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
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)
}
//
// PieView.swift
// MyApp
//
// Created by Robert Ryan on 6/27/17.
// Copyright © 2017 Robert Ryan. All rights reserved.
//
import UIKit
import UIKit
import PromiseKit
// recursive structure for purposes of demo
struct File {
let name: String
let subfiles: [File]?
init(name: String, subfiles: [File]? = nil) {
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])