Skip to content

Instantly share code, notes, and snippets.

@loganwright
loganwright / regionForCoords.m
Last active August 29, 2015 14:11 — forked from robmooney/gist:923301
Map Region Encompassing Coords w/ Padding
- (MKCoordinateRegion)regionForCoords:(NSArray *)coords withPaddingFactor:(CGFloat)paddingFactor {
CLLocationDegrees minLat = 90.0;
CLLocationDegrees maxLat = -90.0;
CLLocationDegrees minLon = 180.0;
CLLocationDegrees maxLon = -180.0;
for (NSValue *val in coords) {
CLLocationCoordinate2D coord = [val MKCoordinateValue];
if (coord.latitude < minLat) {
@loganwright
loganwright / IntrospectionExtensions.swift
Created November 24, 2014 20:31
Get properties from a swift object -- NSObject extension
extension NSObject {
class var propertyNames: [String] {
get {
var count: UInt32 = 0
let properties: UnsafeMutablePointer<objc_property_t> = class_copyPropertyList(self.classForCoder(), &count)
var propertyNames: [String] = []
for i in 0..<count {
let property: objc_property_t = properties[Int(i)]
if let name = String(UTF8String: property_getName(property)) {
propertyNames += [name]
@loganwright
loganwright / LGWatchKitListener.swift
Last active August 29, 2015 14:10
"Real Time" Data - WatchKit
//
// LGWatchKitListener.swift
// RemoteCamera
//
// Created by Logan Wright on 11/19/14.
// Copyright (c) 2014 lowriDevs. All rights reserved.
//
import UIKit
@loganwright
loganwright / SwiftLessonOne_Revamp.md
Last active August 29, 2015 14:06
SwiftLessonOne_Revamp

#Introduction to Variables

To declare a variable in Swift, simply assign something to it, like below:

import Cocoa

var str = "Hello, playground"

As you can see, there is no explicit type declared. This is because type inference will notice that the variable str is being assigned a string and the compiler will infer that str is of type String

@loganwright
loganwright / Readme.md
Last active August 4, 2023 03:50
UIView Gesture Recognizer Extension For Swift

Interface for dealing with gesture recognizers via native swift closure syntax

import UIKit

class ViewController: UIViewController {
                            
    override func viewDidLoad() {
        super.viewDidLoad()
 view.addSingleTapGestureRecognizerWithResponder { (tap) -&gt; Void in
@loganwright
loganwright / DateKeys.h
Created August 20, 2014 14:05
Date Keys
//
// DateKeys.h
// VoxNotes
//
// Created by Logan Wright on 5/6/14.
// Copyright (c) 2014 Logan Wright. All rights reserved.
//
#import <Foundation/Foundation.h>
@loganwright
loganwright / SkipParse-Login
Created July 20, 2014 15:50
SkipParse - Login
#Step 1 - General Setup
- Parse Acct
- Parse Proj in Xcode / Parse Dashboard
- Add keys
Parse's docs are really good for general setup, if you want to run through it, that'd probably be fine. Once you get to importing Swift in AppDelegate.m

Swift is great, but there's a lot of useful libraries that still exist in ObjC that we want to be able to use alongside our swift projects. Let's look at how to use Objective-C code in a Swift project!

Let's start a new project. A single view project is fine for what we're doing, just make sure the language is set to Swift. Once a project is created, I'm personally a big fan of running it before I add anything just to make sure everything is configured properly.

Ok, everything is working fine, let's move right in and add an Objective-C class. When you click 'New File' you'll see a new option with Xcode 6 called 'Cocoa Class'. Click that. Once the window is up, let's name our class 'ColorfulLabel', make it a subclass of UILabel, and make sure that our language is set to Objective-C. This way Xcode will generate our .h and .m file simultaneously. Click "Next" and then "Create" our new class.

You should be hit with a prompt that says "Would you like to configure an Objective-C bridging

// Playground - noun: a place where people can play
import Cocoa
/*
One of the new features introduced in Swift is the ability to easily add operator support to custom classes and structs. Don't worry if that doesn't make sense right away, we'll talk more about it now.
Let's start by declaring a custom struct.
*/
@loganwright
loganwright / UIBezierPathSquiggle
Created June 14, 2014 16:48
Squiggle UIBezierPath
- (void) drawSquiggleInRect:(CGRect)rect {
// Assure positive values
rect = CGRectStandardize(rect);
// Find anchor points
CGPoint anchorLowerLeft = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height);
CGPoint anchorTopRight = CGPointMake(rect.origin.x + rect.size.width, rect.origin.y);
// 10.0 works pretty good!