Skip to content

Instantly share code, notes, and snippets.

/*
File: UIImage+ImageEffects.h
Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur.
Version: 1.0
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
@wzshare
wzshare / Transaction.m
Created September 10, 2018 07:04
FMDB Transaction Usage
- (void)handleTransaction:(UIButton *)sender {
NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *dbPath = [documentPath stringByAppendingPathComponent:@"test1.db"];
FMDatabase *db = [[FMDatabase alloc]initWithPath:dbPath];
if (![db open]) {
return;
}
BOOL result = [db executeUpdate:@"create table if not exists text1 (name text,age,integer,ID integer)"];
if (result) {
NSLog(@"create table success");
@wzshare
wzshare / pthread_mutex_t.md
Last active September 6, 2018 02:18
Detects when a mutex is used before it’s initialized.

Use the pthread_once(_:_:) function to ensure that initialization is called before a mutex is used.

static pthread_once_t once = PTHREAD_ONCE_INIT;
static pthread_mutex_t mutex;
void init() {    
    pthread_mutex_init(&mutex, NULL);
}
void performWork() {
 pthread_once(&once, init); // Correct
@wzshare
wzshare / NSObject+TCKVO.m
Created August 14, 2018 10:20
use try catch avoid remove observer more than once
#import "NSObject+TCKVO.h"
#import <objc/runtime.h>
@implementation NSObject (TCKVO)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self switchMethod];
});
@wzshare
wzshare / UIViewController+Swizzling.m
Created August 14, 2018 09:39
category example code
#import <objc/runtime.h>
@implementation UIViewController (Swizzling)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
// When swizzling a class method, use the following:
// Class class = object_getClass((id)self);
SEL originalSelector = @selector(viewWillAppear:);
@implementation UIViewController (AlertObject)
- (UIViewController *)visibleViewControllerIfExist {
if (self.presentedViewController) {
return [self.presentedViewController visibleViewControllerIfExist];
}
if ([self isKindOfClass:[UINavigationController class]]) {
return [((UINavigationController *)self).topViewController visibleViewControllerIfExist];