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 | |
extension String { | |
func isValidEmail() -> Bool { | |
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}" | |
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) | |
return emailTest.evaluateWithObject(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
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
# | |
# 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: |
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 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 |
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 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") |
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
override func loadView() { | |
super.loadView() | |
... | |
let nibName = someCondition ? "OneXIB" : "AnotherXIB" | |
let nib = UINib(nibName: nibName, bundle: nil) | |
nib.instantiateWithOwner(self, options: 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
- (void)loadView | |
{ | |
[super loadView]; | |
... | |
NSString *nibName = someCondition ? @"OneXIB" : @"AnotherXIB"; | |
UINib *nib = [UINib nibWithNibName:nibName bundle:nil]; | |
[nib instantiateWithOwner:self options: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
import UIKit | |
public enum DeviceSpecific { | |
case iPhone | |
case iPhoneRetina | |
case iPhone5 | |
case iPhone6 | |
case iPhone6Plus | |
case iPad | |
case iPadRetina |
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
// | |
// 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 |