Skip to content

Instantly share code, notes, and snippets.

Christina Moulton, iOS Dev cmoulton

Block or report user

Report or block cmoulton

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cmoulton
cmoulton / Simple Alamofire Calls in Swift 4
Last active May 24, 2019
Simple Alamofire Calls in Swift 4
View Simple Alamofire Calls in Swift 4
import Alamofire
func makeGetCallWithAlamofire() {
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
Alamofire.request(todoEndpoint)
.responseJSON { response in
// check for errors
guard response.result.error == nil else {
// got an error in getting the data, need to handle it
print("error calling GET on /todos/1")
@cmoulton
cmoulton / URLSession Calls in Swift 4
Last active May 23, 2019
URLSession Calls in Swift 4
View URLSession Calls in Swift 4
func makeGetCall() {
// Set up the URL request
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
guard let url = URL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = URLRequest(url: url)
// set up the session
@cmoulton
cmoulton / Todo+Networking.swift
Created Nov 16, 2016
Demo code for Strongly-Typed GET and POST Calls With Alamofire at https://grokswift.com/strongly-typed-api-calls/. Uses Swift 3.0 and Alamofire 4.0.
View Todo+Networking.swift
import Foundation
import Alamofire
enum BackendError: Error {
case objectSerialization(reason: String)
}
extension Todo {
class func endpointForID(_ id: Int) -> String {
return "https://jsonplaceholder.typicode.com/todos/\(id)"
@cmoulton
cmoulton / Simple Alamofire Calls in Swift 3.0.1
Last active Jul 12, 2018
Simple Alamofire Calls in Swift 3.0.1
View Simple Alamofire Calls in Swift 3.0.1
func alamofireGet() {
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
Alamofire.request(todoEndpoint)
.responseJSON { response in
// check for errors
guard response.result.error == nil else {
// got an error in getting the data, need to handle it
print("error calling GET on /todos/1")
print(response.result.error!)
return
@cmoulton
cmoulton / Custom HTTP Headers with Swift and Alamofire.swift
Last active Apr 30, 2019
Custom HTTP Headers with Swift 3 or 4 and Alamofire 4.0-4.7: See https://grokswift.com/custom-headers-alamofire4-swift3/ for explanations
View Custom HTTP Headers with Swift and Alamofire.swift
// MARK: - Adding a header to a single request
func doRequestWithHeaders1() {
let headers: HTTPHeaders = [
"X-Mashape-Key": MY_API_KEY,
"Accept": "application/json"
]
Alamofire.request("https://mashape-community-urban-dictionary.p.mashape.com/define?term=smh", headers: headers)
.responseJSON { response in
debugPrint(response)
@cmoulton
cmoulton / URLSession Calls in Swift 3.0.1
Last active Feb 24, 2019
URLSession Calls in Swift 3.0.1
View URLSession Calls in Swift 3.0.1
func makeGetCall() {
// Set up the URL request
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
guard let url = URL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = URLRequest(url: url)
// set up the session
@cmoulton
cmoulton / BasicAuth.swift
Created Jun 29, 2016
Alamofire Basic Auth
View BasicAuth.swift
func doGetWithBasicAuthCredential() -> Void {
let username = "myUsername"
let password = "myPassword"
let credential = NSURLCredential(user: username, password: password, persistence: NSURLCredentialPersistence.ForSession)
Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(username)/\(password)")
.authenticate(usingCredential: credential)
.responseString { _, _, result in
if let receivedString = result.value
@cmoulton
cmoulton / HeaderAuth.swift
Created Jun 29, 2016
HTTP Header Auth with Alamofire
View HeaderAuth.swift
func doMashape() -> Void {
let manager = Alamofire.Manager.sharedInstance
let headers = ["X-Mashape-Key": "MY_API_KEY", "Accept": "application/json"]
manager.request(.GET, "https://mashape-community-urban-dictionary.p.mashape.com/define?term=hipster", headers: headers)
.responseString { _, _, result in
if let receivedString = result.value {
print(receivedString)
}
}
}
@cmoulton
cmoulton / DetailViewController.swift
Last active Aug 10, 2017
Using DZNEmptyDataSet in a UIViewController
View DetailViewController.swift
//
// DetailViewController.swift
// objcInterop
//
// Created by Christina Moulton on 2015-07-02.
// Copyright (c) 2015 Teak Mobile Inc. All rights reserved.
//
import UIKit
import DZNEmptyDataSet
View ScrollDemoViewController.swift
import UIKit
class ScrollDemoViewController: UITableViewController {
var objects = [AnyObject]()
override func awakeFromNib() {
super.awakeFromNib()
}
override func viewDidLoad() {
You can’t perform that action at this time.