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 Foundation | |
class Solution { | |
func generate(_ numRows: Int) -> [[Int]] { | |
var result = [[Int]]() | |
for i in 0..<numRows { | |
var array = Array(repeating: 1, count: i + 1) | |
if i > 1 { | |
let previousArray = result[i-1] |
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 extension UIView { | |
class func fromNib<T: UIView>() -> T { | |
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T | |
} | |
} |
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
// | |
// SwiftyAccountKit.swift | |
// SwiftyAccountKit | |
// | |
// Created by Maxim on 7/13/17. | |
// Copyright © 2017 Maxim Bilan. All rights reserved. | |
// | |
import AccountKit |
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
extension String { | |
func trim(_ string: String) -> String { | |
var set = Set<Character>() | |
for c in string.characters { | |
set.insert(Character(String(c))) | |
} | |
return trim(set) | |
} | |
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 upload(data: Data, urlString: String, mimeType: String, completion: @escaping (Bool, Error?) -> Void) { | |
let requestURL = URL(string: urlString)! | |
let client = AFHTTPSessionManager(baseURL: requestURL) | |
var request = URLRequest(url: requestURL) | |
request.httpMethod = "PUT" | |
request.httpBody = data | |
request.setValue(mimeType, forHTTPHeaderField: "Content-Type") | |
request.setValue("\(data.count)", forHTTPHeaderField: "Content-Length") | |
request.setValue("public-read", forHTTPHeaderField: "x-amz-acl") | |
let task = client?.dataTask(with: request, completionHandler: { (response, responseObject, error) in |
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
extension Date { | |
struct Formatter { | |
static let iso8601: DateFormatter = { | |
let formatter = DateFormatter() | |
formatter.calendar = Calendar(identifier: .iso8601) | |
formatter.locale = Locale.current | |
formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX" |
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 ViewController: UIViewController { | |
let placeholder = "Placeholder" | |
@IBOutlet weak var textView: UITextView! | |
override func viewDidLoad() { | |
super.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
let image = UIImage(named: "example") | |
let instagramURL = NSURL(string: "instagram://app") | |
if UIApplication.sharedApplication().canOpenURL(instagramURL!) { | |
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] | |
let saveImagePath = (documentsPath as NSString).stringByAppendingPathComponent("Image.igo") | |
let imageData = UIImagePNGRepresentation(image!) | |
do { | |
try imageData?.writeToFile(saveImagePath, options: NSDataWritingOptions(rawValue: 0)) | |
} catch { | |
print("Instagram sharing error") |
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
extension NSLayoutConstraint { | |
func setMultiplier(multiplier:CGFloat) -> NSLayoutConstraint { | |
let newConstraint = NSLayoutConstraint( | |
item: firstItem, | |
attribute: firstAttribute, | |
relatedBy: relation, | |
toItem: secondItem, | |
attribute: secondAttribute, |
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 SystemConfiguration | |
public class Reachability { | |
class func isConnectedToNetwork() -> Bool { | |
var zeroAddress = sockaddr_in() | |
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress)) | |
zeroAddress.sin_family = sa_family_t(AF_INET) | |
let defaultRouteReachability = withUnsafePointer(&zeroAddress) { | |
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) |
NewerOlder