This file contains 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
// 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) |
This file contains 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
public protocol ResponseJSONObjectSerializable { | |
init?(json: SwiftyJSON.JSON) | |
} |
This file contains 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
class ViewController: UIViewController { | |
let clicksKey = "clicksKey" | |
let maxClicks = 10 | |
@IBOutlet weak var clicksLabel: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
updateLabel() | |
} |
This file contains 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 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 |
This file contains 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
// | |
// ViewController.swift | |
// starWarsTableViewUpdates | |
// | |
// Created by Christina Moulton on 2015-10-17. | |
// Copyright (c) 2015 Teak Mobile Inc. All rights reserved. | |
// | |
import UIKit |
This file contains 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
// | |
// ViewController.swift | |
// starWarsTableViewUpdates | |
// | |
// Created by Christina Moulton on 2015-10-17. | |
// Copyright (c) 2015 Teak Mobile Inc. All rights reserved. | |
// | |
import UIKit |
This file contains 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 | |
class ScrollDemoViewController: UITableViewController { | |
var objects = [AnyObject]() | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
} | |
override func viewDidLoad() { |
This file contains 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
// | |
// DetailViewController.swift | |
// objcInterop | |
// | |
// Created by Christina Moulton on 2015-07-02. | |
// Copyright (c) 2015 Teak Mobile Inc. All rights reserved. | |
// | |
import UIKit | |
import DZNEmptyDataSet |
This file contains 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 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) | |
} | |
} | |
} |
This file contains 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 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 |
OlderNewer