Skip to content

Instantly share code, notes, and snippets.

Avatar
🥝
Working...

Maksym Bilan maximbilan

🥝
Working...
View GitHub Profile
@maximbilan
maximbilan / BasicAuthentication.swift
Created Jul 2, 2016
HTTP Basic Authentication using NSURLSession
View BasicAuthentication.swift
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))
View framework_builder.sh
#
# c.f. StackOverflow question/answer here: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4
#
# Version 2.5
#
# Latest Change:
# - The "copy headers" section now respects the build setting for the location of the public headers
# - Opens the directory with the universal library after build (Can be annoying)
#
# Purpose:
View CenterViewFlowLayout.swift
import UIKit
class CenterViewFlowLayout: UICollectionViewFlowLayout {
override func collectionViewContentSize() -> CGSize {
// Only support single section for now.
// Only support Horizontal scroll
let count = self.collectionView?.dataSource?.collectionView(self.collectionView!, numberOfItemsInSection: 0)
let canvasSize = self.collectionView!.frame.size
var contentSize = canvasSize
View gist:b7a747eb9a56a5d5e54b
let directories = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true)
if let documentDirectory = directories.first {
do {
let documents = try NSFileManager.defaultManager().contentsOfDirectoryAtPath(documentDirectory)
for files in documents {
let urlForm = NSURL.fileURLWithPath(documentDirectory + "/" + files)
do {
try print("\(files): \(urlForm.resourceValuesForKeys([NSURLIsExcludedFromBackupKey]))")
} catch {
print("can't find key")
View iCloudIssue.m
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]);
}
View XIBLoading.swift
override func loadView() {
super.loadView()
...
let nibName = someCondition ? "OneXIB" : "AnotherXIB"
let nib = UINib(nibName: nibName, bundle: nil)
nib.instantiateWithOwner(self, options: nil)
}
View XIBLoading.m
- (void)loadView
{
[super loadView];
...
NSString *nibName = someCondition ? @"OneXIB" : @"AnotherXIB";
UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
[nib instantiateWithOwner:self options:nil];
}
View UIImageDeviceSpecific.swift
import UIKit
public enum DeviceSpecific {
case iPhone
case iPhoneRetina
case iPhone5
case iPhone6
case iPhone6Plus
case iPad
case iPadRetina
View SKTextureGradient.swift
//
// SKTextureGradient.swift
// Linear gradient texture
// Based on: https://gist.github.com/Tantas/7fc01803d6b559da48d6, https://gist.github.com/craiggrummitt/ad855e358004b5480960
//
// Created by Maxim on 1/1/16.
// Copyright © 2016 Maxim Bilan. All rights reserved.
//
import SpriteKit
View UIColor+SaveToPList.swift
import Foundation
public extension UIColor {
class func StringFromUIColor(color: UIColor) -> String {
let components = CGColorGetComponents(color.CGColor)
return "[\(components[0]), \(components[1]), \(components[2]), \(components[3])]"
}
class func UIColorFromString(string: String) -> UIColor {