Skip to content

Instantly share code, notes, and snippets.

View cmoulton's full-sized avatar

Christina Moulton cmoulton

View GitHub Profile
//
// ViewController.swift
// starWarsTableViewUpdates
//
// Created by Christina Moulton on 2015-10-17.
// Copyright (c) 2015 Teak Mobile Inc. All rights reserved.
//
import UIKit
//
// ViewController.swift
// starWarsTableViewUpdates
//
// Created by Christina Moulton on 2015-10-17.
// Copyright (c) 2015 Teak Mobile Inc. All rights reserved.
//
import UIKit
@cmoulton
cmoulton / Headers.Swift
Created September 27, 2015 14:28
Add & Remove Session Headers in Alamofire in Swift 2.0
func addSessionHeader(key: String, value: String) {
var headers:[NSObject : AnyObject]
if let existingHeaders =
alamofireManager.session.configuration.HTTPAdditionalHeaders as? [String: String] {
headers = existingHeaders
} else {
headers = Manager.defaultHTTPHeaders
}
headers[key] = value
let config = alamofireManager.session.configuration
@cmoulton
cmoulton / ViewController.swift
Created September 17, 2015 17:59
Start a counter at 10 and decrement when tapped (no lower than 0). Remembers value between runs of the app. https://www.reddit.com/r/swift/comments/3lbk2v/stuck_with_saving_a_number_and_decreasing_it_with/
class ViewController: UIViewController {
let clicksKey = "clicksKey"
let maxClicks = 10
@IBOutlet weak var clicksLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
updateLabel()
}
@cmoulton
cmoulton / ResponseJSONObjectSerializable.swift
Last active December 4, 2018 04:52
Demo code for Strongly-Typed GET and POST Calls With Alamofire at https://grokswift.com/strongly-typed-api-calls/. Uses Swift 2.0, SwiftyJSON 2.3.0, and Alamofire 3.0. (For Swift 3, see https://gist.github.com/cmoulton/733356fd0a29411153155606c0cdc2ba)
public protocol ResponseJSONObjectSerializable {
init?(json: SwiftyJSON.JSON)
}
@cmoulton
cmoulton / UISwiftRestDemo
Last active September 9, 2021 21:01
Quick & dirty REST API calls with Swift 2.2. See http://grokswift.com/simple-rest-with-swift/
// MARK: Using NSURLSession
// Get first todo item
let todoEndpoint: String = "http://jsonplaceholder.typicode.com/todos/1"
guard let url = NSURL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = NSURLRequest(URL: url)