A simple idea using the trick of keypath(...)
derived from libextobjc and ReactiveCocoa and null-object pattern.
Create a category method in NSObject and define a macro PropertyNameForClass()
.
NSObject+PropertyName.h:
#import
// | |
// ViewController.swift | |
// WatchPairedExample | |
// | |
// Created by 張 景隆 on 2015/11/26. | |
// Copyright © 2015年 張 景隆. All rights reserved. | |
// | |
import UIKit | |
import WatchConnectivity |
javascript:(function()%7Bvar%20s=document.getElementById(%22tongwenlet_tw%22);if(s!=null)%7Bdocument.body.removeChild(s);%7Dvar%20s=document.createElement(%22script%22);s.language=%22javascript%22;s.type=%22text/javascript%22;s.src=%22https://raw.githubusercontent.com/stargazer8tw/samples/fe8d4f5d89aebff0359b7f3ea52e141a1d92dcf5/tongwen_bookmarklet/js/bookmarklet_tw.js%22;s.id=%22tongwenlet_tw%22;document.body.appendChild(s);%20%7D)(); |
extension WKInterfaceController { | |
func animateWithDuration(duration: NSTimeInterval, animations: () -> Void, completion: (() -> Void)?) { | |
animateWithDuration(duration, animations: animations) | |
let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(duration * Double(NSEC_PER_SEC))) | |
dispatch_after(delay, dispatch_get_main_queue()) { | |
completion?() | |
} | |
} | |
A simple idea using the trick of keypath(...)
derived from libextobjc and ReactiveCocoa and null-object pattern.
Create a category method in NSObject and define a macro PropertyNameForClass()
.
NSObject+PropertyName.h:
#import
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
//Add some method process in global queue - normal for data processing | |
dispatch_async(dispatch_get_main_queue(), ^(){ | |
//Add method, task you want perform on mainQueue | |
//Control UIView, IBOutlet all here | |
}); |
@import Foundation; | |
@interface KKWatchAppNotificationCenter : NSObject | |
+ (instancetype)sharedCenter; | |
- (void)postNotification:(NSString *)key; | |
- (void)addTarget:(id)target selector:(SEL)selector name:(NSString *)notification; | |
- (void)removeObserver:(NSObject *)observer; | |
@end |
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
// define Swift postfix function like Linux Shell background operator | |
operator postfix & {} | |
@postfix func & (backgroundClosure: () -> ()) { | |
dispatch_async(_queue) { | |
backgroundClosure() | |
} | |
} | |
// testing log function | |
func log(message: String) |
import Foundation | |
extension Int { | |
var days:Int { | |
return 60*60*24*self | |
} | |
var ago:NSDate { | |
return NSDate().dateByAddingTimeInterval(-Double(self)) | |
} | |
} |
// app delegate | |
#import <FBTweak.h> | |
#import <FBTweakShakeWindow.h> | |
#import <FBTweakInline.h> | |
#import <FBTweakViewController.h> | |
#ifdef DEBUG | |
BOOL static const IS_DEBUG = YES; | |
#else | |
BOOL static const IS_DEBUG = NO; |