Skip to content

Instantly share code, notes, and snippets.

class CustomAnnotation: MKPointAnnotation {
var color = UIColor.red
var size = CGSize(width: 20, height: 20)
}
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
@IBAction func didTapButton(_ sender: UIButton) {
extension UIColor{
static func hex(_ hex: String) -> UIColor? {
var string = hex.trimmingCharacters(in: .whitespacesAndNewlines)
if string.hasPrefix("#") {
string.remove(at: string.startIndex)
}
if string.characters.count == 6, let rgbValue = UInt32(string, radix: 16) {
return UIColor(
@robertmryan
robertmryan / RocketAnnotation.swift
Created January 4, 2017 20:14
In MKAnnotation, the coordinate, title, and subtitle should be dynamic
class RocketAnnotation: NSObject, MKAnnotation {
dynamic var coordinate: CLLocationCoordinate2D
dynamic var title: String?
dynamic var subtitle: String?
init(coordinate: CLLocationCoordinate2D) {
self.coordinate = coordinate
super.init()
}
}
@robertmryan
robertmryan / ProtocolDefaultImplementationExample.swift
Last active January 23, 2017 06:35
Swift protocol default implementation idiosyncrasy
// note, P does not declare `greet` as requirement
protocol P {}
// ... but this does provide a "default" implementation
extension P {
func greet() {print("hello")}
}
class ViewController: UICollectionViewController {
var objects: [CustomObject]!
override func viewDidLoad() {
super.viewDidLoad()
// add 100 custom objects
objects = ...
[{
"DAY": "MONDAY",
"EVENTS": [{
"TITLE": "TEST DRIVEN DEVELOPMENT",
"SPEAKER": "JASON SHAPIRO",
"TIME": "9:00 AM",
"ROOM": "MATISSE",
"DETAILS": "EXPLORE THE TOPICS AND TOOLS RELATED TO TEST DRIVEN DEVELOPMENT."
}, {
"TITLE": "JAVA TOOLS",
//
// ViewController.swift
// MyApp4
//
// Created by Robert Ryan on 3/10/17.
// Copyright © 2017 Robert Ryan. All rights reserved.
//
import UIKit
import Alamofire
// ViewController.swift
import UIKit
import EventKit
import EventKitUI
class ViewController: UIViewController {
let store = EKEventStore()
@IBAction func didTapButton(_ sender: AnyObject) {
let runLoop = CFRunLoopGetCurrent()
startAsyncNetworkingStuff() { result in
print(result ?? "No result")
CFRunLoopStop(runLoop)
}
CFRunLoopRun()
print("end")
func pillarPlacement(x: CGFloat, y: CGFloat) -> CGPoint {
let pillarX: CGFloat
let pillarY: CGFloat
let random = Int(arc4random_uniform(2))
if random == 1 {
pillarX = x + 39
pillarY = y - 29
} else {
pillarX = x - 40