Skip to content

Instantly share code, notes, and snippets.

View kingnight's full-sized avatar
🎯
Focusing

jinkai kingnight

🎯
Focusing
View GitHub Profile
@kingnight
kingnight / 0_reuse_code.js
Created June 14, 2014 01:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
- (void)addSpriteImage:(UIImage *)image
withContentRect:(CGRect)rect
toLayer:(CALayer *)layer
{
//set image
layer.contents = (__bridge id)image.CGImage;
//scale contents to fit
layer.contentsGravity = kCAGravityResizeAspect;
@kingnight
kingnight / gist:ea323d77e9ad18dde19d5aa3493de1b2
Created December 11, 2018 10:11 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
import Foundation
protocol StateType: Hashable {}
protocol EventType: Hashable {}
struct Transition<S: StateType, E: EventType> {
let event: E
let fromState: S
let toState: S
// orogin swift protocol and calling
protocol aProtocol {
func testFunc()
}
class aStruct: aProtocol {
func testFunc() {} // override defualt implementation
}
class bStruct: aProtocol {
func testFunc() {} // override defualt implementation
}
@kingnight
kingnight / protocol-demo.swift
Created November 17, 2019 11:15
sil protocol demo
protocol ListDataProtocol {
func testFunc()
}
class TestClass:ListDataProtocol {
func testFunc() {
print("ahaha")
}
}
@kingnight
kingnight / demo-no-imp.swift
Last active November 17, 2019 11:20
sil file without protocol function define
sil_stage raw
import Builtin
import Swift
import SwiftShims
protocol ListDataProtocol {
}
class TestClass : ListDataProtocol {
@kingnight
kingnight / demo-imp.swift
Created November 17, 2019 11:29
sil file,demo include protocol define
sil_stage raw
import Builtin
import Swift
import SwiftShims
protocol ListDataProtocol {
func testFunc()
}
@kingnight
kingnight / errorcodes.m
Created June 18, 2020 02:41 — forked from samirahmed/errorcodes.m
NSURLErrorDomain codes
kCFURLErrorUnknown = -998,
kCFURLErrorCancelled = -999,
kCFURLErrorBadURL = -1000,
kCFURLErrorTimedOut = -1001,
kCFURLErrorUnsupportedURL = -1002,
kCFURLErrorCannotFindHost = -1003,
kCFURLErrorCannotConnectToHost = -1004,
kCFURLErrorNetworkConnectionLost = -1005,
kCFURLErrorDNSLookupFailed = -1006,
kCFURLErrorHTTPTooManyRedirects = -1007,