Skip to content

Instantly share code, notes, and snippets.

@wuxiaowei
wuxiaowei / NSApplication+MXUtilities.h
Created May 16, 2018 09:46 — forked from joerick/NSApplication+MXUtilities.h
Launch at login category on NSApplication
//
// NSApplication+MXUtilities.h
// Mixim
//
// Created by Joe Rickerby on 15/09/2014.
// Copyright (c) 2014 Mixim Technology Ltd. Released under BSD Licence.
//
#import <Cocoa/Cocoa.h>
@wuxiaowei
wuxiaowei / LaunchStarter.swift
Created May 2, 2018 05:36 — forked from plapier/LaunchStarter.swift
Add Login item using Launch Services (Shared List File) in Swift
//
// toggleLaunchAtStartup.swift
// Recents
//
// Created by Phil LaPier on 5/21/15.
// Copyright (c) 2015 Philip LaPier. All rights reserved.
//
// With help from: https://github.com/RamonGilabert/Prodam/blob/master/Prodam/Prodam/LaunchStarter.swift
import Foundation
@wuxiaowei
wuxiaowei / NSTimer+Blocks
Created January 9, 2017 02:36 — forked from justin/NSTimer+Blocks
NSTimer+Blocks
typedef void (^SGBlock)();
@interface NSTimer (Blocks)
+ (id)scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)shouldRepeat block:(SGBlock)block;
+ (id)timerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)shouldRepeat block:(SGBlock)block;
@end
extension NSTimer {
class func scheduledTimerWithTimeInterval(interval: NSTimeInterval, repeats: Bool, handler: NSTimer! -> Void) -> NSTimer {
let fireDate = interval + CFAbsoluteTimeGetCurrent()
let repeatInterval = repeats ? interval : 0
let timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, fireDate, repeatInterval, 0, 0, handler)
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes)
return timer
}
}