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 application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { | |
// Override point for customization after application launch. | |
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
var nav1 = UINavigationController() | |
var first = FirstViewController(nibName: nil, bundle: nil) | |
nav1.viewControllers = [first] | |
var second = SecondViewController(nibName: nil, bundle: nil) | |
var nav2 = UINavigationController() |
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 | |
extension UISegmentedControl { | |
func goVertical() { | |
self.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2)) | |
for segment in self.subviews { | |
for segmentSubview in segment.subviews { | |
if segmentSubview is UILabel { | |
(segmentSubview as UILabel).transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_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
// FAILURE | |
var array = [["name": "glen"]] | |
for item in array { | |
item["rank"] = "advanced" // Generates an @lvalue error | |
} | |
// Even though array is immutable, it's of type <Array<Dictionary<String,String>>, | |
// item is assigned by let automatically. | |
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
var startNumber = 240 | |
var timer = Timer() | |
func runTime() { | |
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: (#selector(ViewController.tTimer)), userInfo: nil, repeats: true) | |
} | |
@objc func tTimer() { | |
if startNumber > 0 { | |
startNumber -= 1 | |
numberLabel.text = String(startNumber) |
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 | |
extension UIStackView { | |
func removeAllArrangedSubviews() { | |
let removedSubviews = arrangedSubviews.reduce([]) { (allSubviews, subview) -> [UIView] in | |
self.removeArrangedSubview(subview) | |
return allSubviews + [subview] | |
} |
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 saveImage(image: UIImage, name:String) { | |
let req = NSMutableURLRequest(url: NSURL(string:"http://127.0.0.1:3001/")! as URL) | |
let ses = URLSession.shared | |
req.httpMethod="POST" | |
req.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type") | |
req.setValue(name, forHTTPHeaderField: "X-FileName") | |
let jpgData = UIImageJPEGRepresentation(image, 1.0) | |
req.httpBodyStream = InputStream(data: jpgData!) | |
let task = ses.uploadTask(withStreamedRequest: req as URLRequest) | |
task.resume() |
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
// | |
// Created by Ben Asher on 6/13/18. | |
// Copyright © 2018-present PlanGrid. All rights reserved. | |
// | |
import Foundation | |
import MapKit | |
import UserNotifications | |
#if swift(>=4.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
extension NSLayoutAnchor { | |
@objc @discardableResult func eq(_ anchor: NSLayoutAnchor, _ constant: CGFloat = 0.0) -> NSLayoutConstraint { | |
let c = constraint(equalTo: anchor, constant: constant) | |
c.isActive = true | |
return c | |
} | |
@objc @discardableResult func lte(_ anchor: NSLayoutAnchor, _ constant: CGFloat = 0.0) -> NSLayoutConstraint { | |
let c = constraint(lessThanOrEqualTo: anchor, constant: constant) | |
c.isActive = 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
import SwiftUI | |
import UIKit | |
import YouTubePlayer | |
final class YouTubeView: UIViewRepresentable { | |
typealias UIViewType = YouTubePlayerView | |
@ObservedObject var playerState: YouTubeControlState | |