Skip to content

Instantly share code, notes, and snippets.

View ygweric's full-sized avatar
💭
I may be slow to respond.

Eric ygweric

💭
I may be slow to respond.
  • Auckland, New Zealand
View GitHub Profile
import UIKit
func isExactClass<T>(obj: Any, _ _: T.Type) -> Bool{
return type(of: obj) == T.self
}
class Dog {
@ygweric
ygweric / Swizzle
Created November 28, 2016 22:11
Swizzle for class method and instance method with Swift
func swizzleClassMethod(cls: AnyClass, oldSelector: Selector, newSelector: Selector) {
let oldMethod = class_getClassMethod(cls, oldSelector)
let newMethod = class_getClassMethod(cls, newSelector)
method_exchangeImplementations(oldMethod, newMethod)
// following code not work
// if(class_addMethod(cls, oldSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
// class_replaceMethod(cls, newSelector, method_getImplementation(oldMethod), method_getTypeEncoding(oldMethod))
// } else {
@ygweric
ygweric / Snippet.txt
Last active January 10, 2016 04:27
ObjC code snippet
## UI Code Snippet
#### UILabel
```
{
UILabel* lb =[[UILabel alloc]initWithFrame:CGRectZero];
lb.autoresizingMask=UIViewAutoresizingFlexibleWidth;
@ygweric
ygweric / Main.java
Last active December 10, 2015 10:21
convert model of MTLModel(ObjC) to ObjectMapper(Swift)
package com.dogkk;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ygweric
ygweric / util.m
Last active November 16, 2015 03:24
数字转中文大写 obj-c
+ (NSString*)numberToChineseUppercase:(double)num{
int iLen,iNum,iAddZero=0;
NSMutableString *szChMoney = [[NSMutableString alloc] init];
NSArray *hzUnit = @[@"分",@"角",@"元",@"拾",@"佰",@"仟",@"万",@"拾",@"佰",@"仟",@"万",@"亿",@"拾",@"佰",@"仟",@"万",@"拾",@"佰",@"仟"];
NSArray *hzNum = @[@"零",@"壹",@"贰",@"叁",@"肆",@"伍",@"陆",@"柒",@"捌",@"玖"];
NSString *szNum = [NSString stringWithFormat:@"%18.0f",num*100];
szNum = [szNum stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
iLen =(int) szNum.length;