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 login = "test" | |
let password = "12345" | |
let url = NSURL(string: "http://test.com/api/v1/example.json") | |
let request = NSMutableURLRequest(URL: url!) | |
let config = NSURLSessionConfiguration.defaultSessionConfiguration() | |
let userPasswordString = "\(login):\(password)" | |
let userPasswordData = userPasswordString.dataUsingEncoding(NSUTF8StringEncoding) | |
let base64EncodedCredential = userPasswordData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) |
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
import UIKit | |
public extension UIView { | |
public class func instantiateFromNib<T: UIView>(viewType: T.Type) -> T { | |
return NSBundle.mainBundle().loadNibNamed(NSStringFromClass(viewType).pathExtension, owner: nil, options: nil).first as! T | |
} | |
public class func instantiateFromNib() -> Self { | |
return instantiateFromNib(self) | |
} |
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 Array2D<T> { | |
var columns: Int | |
var rows: Int | |
var matrix: [T] | |
init(columns: Int, rows: Int, defaultValue: T) { | |
self.columns = columns | |
self.rows = rows | |
matrix = Array(count: columns * rows, repeatedValue: defaultValue) |
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
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
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
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; | |
NSArray *documents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil]; | |
NSURL *URL; | |
NSString *completeFilePath; | |
for (NSString *file in documents) { | |
completeFilePath = [NSString stringWithFormat:@"%@/%@", basePath, file]; | |
URL = [NSURL fileURLWithPath:completeFilePath]; | |
NSLog(@"File %@ is excluded from backup %@", file, [URL resourceValuesForKeys:[NSArray arrayWithObject:NSURLIsExcludedFromBackupKey] error:nil]); | |
} |
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) | |
} | |
NewerOlder