Skip to content

Instantly share code, notes, and snippets.

View Appletone's full-sized avatar
💻
Coding

Lin Chia Hua Appletone

💻
Coding
  • Taipei, Taiwan
View GitHub Profile
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?()
}
}
@Appletone
Appletone / 新新同文堂 bookmarklet
Last active June 19, 2019 02:32
新新同文堂.js
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)();
@Appletone
Appletone / ViewController.swift
Last active March 17, 2016 16:43
評估你的 App 是否加入 Apple Watch 功能
//
// ViewController.swift
// WatchPairedExample
//
// Created by 張 景隆 on 2015/11/26.
// Copyright © 2015年 張 景隆. All rights reserved.
//
import UIKit
import WatchConnectivity
@Appletone
Appletone / NSManagedObject.swift
Created January 7, 2016 14:04
Create a new NSManagedObject with init method (Xcode 7.2 Swift 2.1 ) from: http://stackoverflow.com/a/33583941
extension NSManagedObject {
// Returns the unqualified class name, i.e. the last component.
// Can be overridden in a subclass.
class func entityName() -> String {
return String(self)
}
convenience init(context: NSManagedObjectContext) {
let eName = self.dynamicType.entityName()
// Fix for IOS 9 pop-over arrow anchor bug
// ---------------------------------------
// - IOS9 points pop-over arrows on the top left corner of the anchor view
// - It seems that the popover controller's sourceRect is not being set
// so, if it is empty CGRect(0,0,0,0), we simply set it to the source view's bounds
// which produces the same result as the IOS8 behaviour.
// - This method is to be called in the prepareForSegue method override of all
// view controllers that use a PopOver segue
//
// example use:
@Appletone
Appletone / protocols.md
Created January 13, 2016 07:32 — forked from rbobbins/protocols.md
Notes from "Protocol-Oriented Programming in Swift"

PS: If you liked this talk or like this concept, let's chat about iOS development at Stitch Fix! #shamelessplug

Protocol-Oriented Programming in Swift

Speaker: David Abrahams. (Tech lead for Swift standard library)

  • "Crusty" is an old-school programmer who doesn't trust IDE's, debuggers, programming fads. He's cynical, grumpy.

  • OOP has been around since the 1970's. It's not actually new.

  • Classes are Awesome

    • Encapsulation
    • Access control
@Appletone
Appletone / UIViewController+UIImagePickerController.swift
Last active January 13, 2016 08:32
Making UIViewController Image Pickerable
protocol ImagePickable {
var imagePicker:UIImagePickerController { get set }
func openPhotoLibrary()
}
var AssociatedObjectHandle: UInt8 = 0
extension UIViewController : ImagePickable, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var imagePicker:UIImagePickerController {
get {
var fetchedResultsProcessingOperations: [NSBlockOperation] = []
private func addFetchedResultsProcessingBlock(processingBlock:(Void)->Void) {
fetchedResultsProcessingOperations.append(NSBlockOperation(block: processingBlock))
}
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
switch type {
case .Insert:
class MyManager {
private static let sharedInstance = MyManager()
class var sharedManager : MyManager {
return sharedInstance
}
}
@Appletone
Appletone / Array.swift
Created July 20, 2016 08:56
Array Next Element
extension Array where Element: Hashable {
func after(item: Element) -> Element? {
if let index = self.indexOf(item) where index + 1 < self.count {
return self[index + 1]
}
return nil
}
}