Skip to content

Instantly share code, notes, and snippets.

View quocnb's full-sized avatar
♟️

Quoc Nguyen quocnb

♟️
View GitHub Profile
extension Sequence {
func forEach(_ closure: (Element) -> () -> Void) {
for element in self {
closure(element)()
}
}
}
let arr = [view1, view2]
arr.forEach(UIView.removeFromSuperview)
public struct URLCredentialHelper {
enum URLCredentialError {
static let invalidUrl = NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL, userInfo: nil)
}
static func store(user: String, password: String, url: String) throws {
let protectionSpace = try createProtectionSpace(for: url)
let credentital = URLCredential(user: user, password: password, persistence: .permanent)
URLCredentialStorage.shared.set(credentital, for: protectionSpace)
}
import UIKit
class MarginLabel: UILabel {
var insets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
override func drawText(in rect: CGRect) {
super.drawText(in: rect.inset(by: insets))
}