Skip to content

Instantly share code, notes, and snippets.

View NSFish's full-sized avatar

乐星宇 NSFish

  • 京东
  • 浙江杭州
View GitHub Profile
@NSFish
NSFish / NSFTableViewCellExpander.m
Last active February 19, 2022 02:05
Smooth animation when expand/fold cell even for the last one in the tableView
- (void)nsf_properlyAnimateCell:(__kindof UITableViewCell<NSFTableViewCellExpandable> *)cell
atIndexPath:(NSIndexPath *)indexPath
expand:(BOOL)expand
{
CGFloat beforeRowHeight = [self.tableView.delegate tableView:self.tableView heightForRowAtIndexPath:indexPath];
self.states[indexPath] = @(expand);
if (self.useAutoLayout)
{
[cell configWithExpandState:expand];
@NSFish
NSFish / x.swift
Created March 1, 2019 07:26
Check if a url is universal link
let url = URL(string: "https://my.domain.com/k0kSc8hHzAM?t=1461")!
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in
if !success {
// not a universal link or app not installed
let vc = SFSafariViewController(url: url)
self.present(vc, animated: true)
}
}
@NSFish
NSFish / Macros.h
Created September 6, 2018 21:13
Simulate NSLock with semaphore from GCD to get better performance
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
@NSFish
NSFish / NSFPrioritizedDelegateContainer.h
Last active February 19, 2022 02:05
基于 message forwarding 的轻量依赖注入容器
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSFPrioritizedDelegate : NSObject
@property (readonly) id<NSObject> content;
/// 是否需要在 container 中弱引用 delegate
@property (readonly) BOOL weakRef;
@NSFish
NSFish / NSNumberTest.m
Created July 21, 2018 01:24
[[NSNumber new] will return nil...
- (void)someMethod
{
// will return a NSPlaceholderNumber instance.
NSNumber *a = [NSNumber alloc];
// will simplely just return nil according to https://github.com/NSFish/PrivateFrameworkPseudos/blob/master/Foundation/NSPlaceholderNumber.mm#L1-L5
a = [a init];
// so... nil.
NSNumber *a = [NSNumber new];
}
@NSFish
NSFish / SomeClass.h
Last active July 20, 2018 18:43
Tagged Pointer to the rescue😂.
// Come from https://blog.csdn.net/wangyanchang21/article/details/80570863
@interface SomeClass : NSObject
@property (nonatomic, strong) NSString *string;
@end
@NSFish
NSFish / ViewController.h
Last active July 20, 2018 18:46
UIScrollView get along with Swipe Back gesture
@interface ViewController ()
@property (nonatomic, strong) UIScrollView *scrollView;
@end