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
dispatch_source_t CreateDispatchTimer(uint64_t interval, uint64_t leeway, dispatch_queue_t queue, dispatch_block_t block) | |
{ | |
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); | |
if (timer) | |
{ | |
dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), interval, leeway); | |
dispatch_source_set_event_handler(timer, block); | |
dispatch_resume(timer); | |
} | |
return timer; |
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
var gradient: CAGradientLayer = CAGradientLayer() | |
gradient.frame = view.bounds | |
gradient.colors = [UIColor(rgba: "#71B280").CGColor, UIColor(rgba: "#134E5E").CGColor] | |
self.view.layer.insertSublayer(gradient, atIndex: 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
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { | |
[self dismissViewControllerAnimated:YES completion:^{ | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
[UIApplication sharedApplication].idleTimerDisabled = YES; | |
}); | |
}]; | |
} | |
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { | |
self dismissViewControllerAnimated:YES completion:^{ |
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
+ (UIImage *)imageFromText:(NSString *)text size:(CGSize)size fontName:(NSString *)fontName maxFontSize:(CGFloat)maxFontSize minFontSize:(CGFloat)minFontSize | |
{ | |
UIFont *font; | |
CGSize fontSize; | |
for (CGFloat maxSize = maxFontSize; maxSize >= minFontSize; maxSize -= 1.f) { | |
font = [UIFont fontWithName:fontName size:maxSize]; | |
fontSize = [text sizeWithAttributes:@{ NSFontAttributeName : font }]; | |
if (fontSize.width <= size.width) { |
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
import UIKit | |
public extension UIView { | |
public class func instantiateFromNib<T: UIView>(viewType: T.Type) -> T { | |
let url = NSURL(string: NSStringFromClass(viewType)) | |
return NSBundle.mainBundle().loadNibNamed(url?.pathExtension, owner: nil, options: nil).first as! T | |
} | |
public class func 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
import Foundation | |
extension CollectionType where Index == Int { | |
func shuffle() -> [Generator.Element] { | |
var list = Array(self) | |
list.shuffleInPlace() | |
return list | |
} | |
} |
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
private var propertyAssociationKey: UInt8 = 0 | |
extension String { | |
weak var property: CustomClass! { | |
get { | |
return objc_getAssociatedObject(self, &propertyAssociationKey) as? CustomClass | |
} | |
set(newValue) { | |
objc_setAssociatedObject(self, &propertyAssociationKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) | |
} |
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
// | |
// CoreDataStorage.swift | |
// TutorialAppGroup | |
// | |
// Created by Maxim on 10/18/15. | |
// Copyright © 2015 Maxim. All rights reserved. | |
// | |
import Foundation | |
import CoreData |
OlderNewer