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 | |
extension UIView { | |
static func loadFromXib() -> UIView? { | |
let bundle = Bundle(for: self) | |
let nib = UINib(nibName: String(describing: self), bundle: bundle) | |
let view = nib.instantiate(withOwner: self, options: nil).first as? UIView | |
return view | |
} |
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
enum HTTPStatusCodes: Int { | |
// 100 Informational | |
case Continue = 100 | |
case SwitchingProtocols | |
case Processing | |
// 200 Success | |
case OK = 200 | |
case Created | |
case Accepted | |
case NonAuthoritativeInformation |
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 UIImage { | |
static func imageByMergingImages(topImage: UIImage, bottomImage: UIImage, scaleForTop: CGFloat = 1.0) -> UIImage { | |
let size = bottomImage.size | |
let container = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
UIGraphicsBeginImageContextWithOptions(size, false, 2.0) | |
UIGraphicsGetCurrentContext()!.interpolationQuality = .high | |
bottomImage.draw(in: container) | |
let topWidth = size.width / scaleForTop |
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 | |
extension NSWorkspace { | |
class func frontmostApp() -> NSRunningApplication? { | |
return self.sharedWorkspace().frontmostApplication | |
} | |
class func runningApp(bundleIdentifier:NSString) -> NSRunningApplication? { | |
let runningApplications = NSWorkspace.sharedWorkspace().runningApplications | |
return runningApplications.filter({$0.bundleIdentifier == bundleIdentifier}).first | |
} |
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 | |
protocol AXUIProtocol { | |
func AXUIWindowArray(processIdentifier pid:pid_t) -> [AXUIElement] | |
func AXUIWindowArray(bundleIdentifier bid:NSString) -> [AXUIElement] | |
} | |
extension AXUIProtocol { | |
func AXUIWindowArray(processIdentifier pid:pid_t) -> [AXUIElement] { | |
let windowList : UnsafeMutablePointer<AnyObject?> = UnsafeMutablePointer<AnyObject?>.alloc(1) |
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 UIApplication { | |
class func visibleViewController(base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController) -> UIViewController? { | |
if let nav = base as? UINavigationController { | |
return visibleViewController(nav.visibleViewController) | |
} | |
if let tab = base as? UITabBarController { | |
let moreNavigationController = tab.moreNavigationController |
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
// As Modal window: | |
func messageBox(_ title: String!, message: String! = nil, | |
firstOption: String? = nil, secondOption: String? = nil, thirdOption: String? = nil, | |
firstAction: (() -> ())? = nil, secondAction: (() -> ())? = nil, thirdAction: (() -> ())? = nil ) { | |
let alert = NSAlert() | |
alert.messageText = title ?? "" | |
alert.informativeText = message ?? "" | |
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 NSView { // UIView | |
// Set source/destination angle. | |
// Angle is set in radians (0..2π), hence 360* rotation = 2π/-2π | |
func spinClockwise(timeToRotate: Double) { | |
startRotation(angle: -1 * CGFloat.pi * 2.0, timeToRotate: timeToRotate) | |
} | |
func spinAntiClockwise(timeToRotate: Double) { | |
startRotation(angle: CGFloat.pi * 2.0, timeToRotate: timeToRotate) |