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 | |
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 { |
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 | |
import UIKit | |
@objc public class LeftAlignedSearchBar: UISearchBar, UISearchBarDelegate { | |
override public var placeholder:String? { | |
didSet { | |
if #available(iOS 9.0, *) { | |
if let text = placeholder { | |
if text.characters.last! != " " { | |
let attr = UITextField.appearanceWhenContainedInInstancesOfClasses([LeftAlignedSearchBar.self]).defaultTextAttributes |
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 Cocoa | |
@NSApplicationMain | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2) | |
let popover = NSPopover() | |
var eventMonitor: EventMonitor? | |
func applicationDidFinishLaunching(aNotification: NSNotification) { |
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 Cocoa | |
public class EventMonitor { | |
private var monitor: AnyObject? | |
private let mask: NSEventMask | |
private let handler: NSEvent? -> () | |
public init(mask: NSEventMask, handler: NSEvent? -> ()) { | |
self.mask = mask |
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
NSString *url = @"https://www.youtube.com/watch?v=ZGNvt_L_cag"; | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=v(=|/))([-a-zA-Z0-9_]+)|(?<=youtu.be/)([-a-zA-Z0-9_]+)" options:NSRegularExpressionCaseInsensitive error:nil]; | |
NSTextCheckingResult *match = [regex firstMatchInString:url options:0 range:NSMakeRange(0, [url length])]; | |
NSRange range = [match rangeAtIndex:0]; | |
NSString *youTubeID = [url substringWithRange:range]; | |
NSLog(@"%@", youTubeID); |
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 url = "https://www.youtube.com/watch?v=ZGNvt_L_cag" | |
do { | |
let regex = try NSRegularExpression(pattern: "(?<=v(=|/))([-a-zA-Z0-9_]+)|(?<=youtu.be/)([-a-zA-Z0-9_]+)", options: NSRegularExpressionOptions.CaseInsensitive) | |
let match = regex.firstMatchInString(url, options: NSMatchingOptions.ReportProgress, range: NSMakeRange(0, url.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))) | |
let range = match?.rangeAtIndex(0) | |
let youTubeID = (url as NSString).substringWithRange(range!) | |
print(youTubeID) | |
} catch { | |
} |
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 |
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
import Foundation | |
extension CollectionType where Index == Int { | |
func shuffle() -> [Generator.Element] { | |
var list = Array(self) | |
list.shuffleInPlace() | |
return list | |
} | |
} |