Created
February 22, 2017 15:01
-
-
Save ruan65/6cc4c1f4baca4cdaf7b42ff4fcafded4 to your computer and use it in GitHub Desktop.
Frequently used static functions for iOs app (swift 3)
This file contains hidden or 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 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