This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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)) |
This file contains hidden or 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 hidden or 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") |