Skip to content

Instantly share code, notes, and snippets.

extension NSManagedObject {
public class var entityName:String {
get {
return NSStringFromClass(self).componentsSeparatedByString(".").last!
}
}
public var entityNameOfThisObject:String {
get {
import Foundation
import CoreData
class Document : NSManagedObject {
class func newDocument() -> Document {
return self.documentForID("1")
}
class func documentForID(documentID: String) -> Document {
let predicate = NSPredicate(format: "documentID = %@", documentID)
@akisute
akisute / better_silent_1.json
Created August 12, 2014 09:45
Better Silent Notification for iOS 7+
{"aps" : {"content-available" : 1, "sound" : ""}}
@akisute
akisute / silent.json
Created August 12, 2014 09:38
Push Notification Payloads for iOS 7+
{"aps" : {"content-available" : 1}}
- (void)viewDidLoad
{
[super viewDidLoad];
id target = [self.navigationController valueForKey:@"_cachedInteractionController"];
UIGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
[self.view addGestureRecognizer:recognizer];
// Add a dependency between your recognizer and the interactivePopGestureRecognizer
// to prevent multiple recognition, if needed.
@akisute
akisute / LocationManager.swift
Created August 2, 2014 14:23
LocationManager with PromiseKit-Swift. Well I don't like this deferred at all.
import Foundation
import CoreLocation
class LocationManager : NSObject, CLLocationManagerDelegate {
class var sharedInstance : LocationManager {
get {
struct Static {
static let instance : LocationManager = LocationManager()
@akisute
akisute / SSCD01
Last active August 29, 2015 14:03
昔見かけた伝統芸能、プログラムコードは http://people.sju.edu/~jhodgson/cobol/sample.html からお借りしました
* ***************************************************************
* プログラムID SSCD01
* 機能名 S社詳細帳票出力01
* 開発担当者 株式会社akisute
* あきすてさま
* 初版 2004/06/28
*
* 変更履歴
* 2004/06/28 変更者 あきすてさま
* 初版作成。
@akisute
akisute / AppDelegate.m
Created June 25, 2014 08:29
Use UIPasteboard to pass around data between the main app and app extensions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create a pasteboard, and pass some data to it
// the created pasteboard can be specified as persistent as well
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"Widget" create:YES];
pasteboard.persistent = YES;
pasteboard.string = @"やっほー!";
return YES;
}
@akisute
akisute / APIClient.swift
Last active October 6, 2015 17:53
Example of APIClient and TestCase in Swift, using AFNetworking/Bolts
import UIKit
// How to make singleton classes in Swift: http://stackoverflow.com/questions/24024549/dispatch-once-singleton-model-in-swift
// Basically using global constants is the most easy and safe way to go
class APIClient: NSObject {
let functionSessionManager:AFHTTPSessionManager
class var sharedInstance:APIClient {
@akisute
akisute / Promise.swift
Created June 11, 2014 06:05
Promise in Swift, but completely broken in chaining. I can't just simply implement promise chaining X(
import Foundation
enum PromiseState:Int {
case Incomplete = 0
case Rejected = 1
case Resolved = 2
}
class Promise : Hashable {