Skip to content

Instantly share code, notes, and snippets.

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

Ricky Tan rickytan

💭
I may be slow to respond.
View GitHub Profile
#define RTObjectKeyPath(OBJ, PATH) (((void)(NO && ((void)(((typeof(OBJ))nil).PATH), NO)), @# PATH))
@interface NSString (ComposedCharacter)
/**
* @description @b NSString use UTF-16 encode to store characters internally, in
* most cast, the @c length of a @b NSString is the number visible characters.
* But not for some special Characters like Emoji.
* @"😃🤡⛹🏿‍♀️⚫️🤥🤕💪🏾" this @b NSString only has 7 Emojis, but its @c length is
* 20. Sometimes we only want the human visible charater count.
*
* @code
@rickytan
rickytan / MZKVOKeyPath.h
Last active September 28, 2018 07:25
Safe key path, compile time key-path checking and auto-completion
#define __mz_macro_concat(A, B) __mz_macro_concat_(A, B)
#define __mz_macro_argcount(...) __mz_macro_at(6, __VA_ARGS__, 6, 5, 4, 3, 2, 1)
#define __mz_macro_head(...) __mz_macro_head_(__VA_ARGS__, 0)
#define __mz_macro_at(N, ...) __mz_macro_concat(__mz_macro_at, N)(__VA_ARGS__)
#define __mz_macro_at0(...) __mz_macro_head(__VA_ARGS__)
#define __mz_macro_at1(_0, ...) __mz_macro_head(__VA_ARGS__)
#define __mz_macro_at2(_0, _1, ...) __mz_macro_head(__VA_ARGS__)
#define __mz_macro_at3(_0, _1, _2, ...) __mz_macro_head(__VA_ARGS__)
#define __mz_macro_at4(_0, _1, _2, _3, ...) __mz_macro_head(__VA_ARGS__)
@rickytan
rickytan / UIImage+sRGB.m
Created September 26, 2017 15:09
convert to sRGB space
- (UIImage *)mz_convertToSRGBColorSpace
{
UIImage *newImage = self;
do {
CGImageRef CGImage = self.CGImage;
CGColorSpaceRef srcSpace = CGImageGetColorSpace(CGImage);
CGColorSpaceRef dstSpace = IS_IOS_9 ? CGColorSpaceCreateWithName(kCGColorSpaceSRGB) : CGColorSpaceCreateDeviceRGB();
// 颜色空间一样直接返回 self
if (CFEqual(srcSpace, CFAutorelease(CGColorSpaceCreateDeviceRGB())) ||
@rickytan
rickytan / RTRouter.h
Created October 17, 2016 14:01
A app router designation
#import <Foundation/Foundation.h>
@class RTRouter;
typedef void(^RTRouteCompleteBlock)(void);
@protocol RTRoutable <NSObject>
@optional
+ (BOOL)routerDidRoutePattern:(NSString *)pattern
withParameters:(id)parameters