Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created February 22, 2017 15:01
Show Gist options
  • Save ruan65/6cc4c1f4baca4cdaf7b42ff4fcafded4 to your computer and use it in GitHub Desktop.
Save ruan65/6cc4c1f4baca4cdaf7b42ff4fcafded4 to your computer and use it in GitHub Desktop.
Frequently used static functions for iOs app (swift 3)
import Foundation
import UIKit
struct H {
static func showOneBtnAlert(_ ctx: UIViewController, header: String, msg: String) {
let alert = UIAlertController(title: header, message: msg, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: Btn.ok, style: UIAlertActionStyle.default, handler: nil))
ctx.present(alert, animated: true, completion: nil)
}
static func clearSharedCookies () {
let jar = HTTPCookieStorage.shared
for cookie in jar.cookies! {
jar.deleteCookie(cookie)
}
}
static func setSharedCookies(url: URL, cookie: String) {
let jar = HTTPCookieStorage.shared
let cookieHeaderField = ["Set-Cookie": cookie]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: cookieHeaderField, for: url)
jar.setCookies(cookies, for: url, mainDocumentURL: url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment