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
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
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
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 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 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
// | |
// 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 |
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
- (void)loadView | |
{ | |
[super loadView]; | |
... | |
NSString *nibName = someCondition ? @"OneXIB" : @"AnotherXIB"; | |
UINib *nib = [UINib nibWithNibName:nibName bundle:nil]; | |
[nib instantiateWithOwner:self options:nil]; | |
} |