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 *fontFamilies = [UIFont familyNames]; | |
for (int i = 0; i < [fontFamilies count]; i++){ | |
NSString *fontFamily = fontFamilies[i]; | |
NSArray *fontNames = [UIFont fontNamesForFamilyName:fontFamilies[i]]; | |
NSLog (@"%@: %@", fontFamily, fontNames); | |
} |
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
#define FLT_EQUAL(a, b) (fabs((a) - (b)) < FLT_EPSILON) | |
#define FLT_ZERO(a) (fabs(a) < FLT_EPSILON) |
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
- (BOOL)addSkipBackupAttribute{ | |
if (![[NSFileManager defaultManager] fileExistsAtPath:[self path]]) return NO; | |
NSError *error = nil; | |
BOOL success = [self setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error]; | |
if(!success){ | |
NSLog(@"Error excluding %@ from backup %@", [self lastPathComponent], error); | |
} | |
return success; | |
} |
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
// MARK: - Box | |
final public class Box<T> { | |
public let unbox:T | |
public init(_ value: T) { self.unbox = value } | |
} | |
// MARK: - Result enum | |
public enum Result<T: Printable> { |
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 func flushCookies() { | |
let storage = NSHTTPCookieStorage.sharedHTTPCookieStorage() | |
if let cookieJar = storage.cookies as? [NSHTTPCookie] { | |
for cookie in cookieJar { storage.deleteCookie(cookie) } | |
} | |
NSUserDefaults.standardUserDefaults().synchronize() | |
} |
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 CGFloat { | |
var toRadians: CGFloat { | |
return self * CGFloat(M_PI) / 180.0 | |
} | |
var toDegress: CGFloat { | |
return self * 180 / CGFloat(M_PI) | |
} | |
} |
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
struct Settings { | |
// Make sure to add the "-D DEBUG" flag in the project settings for the Swift Compiler | |
static var Debug: Bool { | |
#if DEBUG | |
return true | |
#else | |
return false | |
#endif | |
} |
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 CGPoint { | |
public enum CoordinateSystem { | |
case UIKit | |
case SpriteKit | |
} | |
public func coordinates(from from: CoordinateSystem, to: CoordinateSystem) -> CGPoint { | |
if from == to { return self } | |
else { |
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
// MARK: - NSUserDefaults | |
extension NSUserDefaults { | |
class func performOnceForKey(key: String, perform: () -> Void, elsePerform: (() -> Void)? = nil) { | |
let once = self.standardUserDefaults().objectForKey(key) | |
self.standardUserDefaults().setBool(true, forKey: key) | |
self.standardUserDefaults().synchronize() | |
if once == nil { perform() } |
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 CollectionType { | |
/// Returns the first element where `predicate` returns `true` for the | |
/// corresponding value, or `nil` if such value is not found. | |
/// | |
/// - Complexity: O(`self.count`). | |
func firstMatching(@noescape predicate: (Self.Generator.Element) -> Bool) -> Self.Generator.Element? { | |
for (_, element) in self.enumerate() { | |
if predicate(element) { return element } | |
} |
OlderNewer