Skip to content

Instantly share code, notes, and snippets.

View 623637646's full-sized avatar
🎯
Focusing

Yanni Wang 王氩 623637646

🎯
Focusing
View GitHub Profile
@623637646
623637646 / Dictionary+Extension.swift
Created March 8, 2024 10:08
How to update a value in a nested dictionary given path fragment in Swift?
extension Dictionary {
subscript(jsonDict key: Key) -> [String:Any]? {
get {
return self[key] as? [String:Any]
}
set {
self[key] = newValue as? Value
}
}
}
@623637646
623637646 / 动态库静态库tips
Last active February 19, 2024 07:36
动态库静态库tips
1. 静态库
只编译不链接
只要头文件在,无需设置依赖
会打包进主工程二进制文件
2. 动态库
既编译又链接
必须设置依赖
不会打包进主工程二进制文件
3. 当且仅当动态库依赖静态库时,才会copy静态库的代码到动态库二进制
@623637646
623637646 / Swift VS Objective-C.txt
Last active December 13, 2023 09:14
Swift VS Objective-C
swift vs Objective-C
`?` 可选值 显式可选 vs 隐式可选
异步编程方式 async 协程编程 vs OKBAsyncLoader
enum 枚举 可携带变量 vs 不可携带变量
函数&方法抛异常 显式抛异常 vs 隐式抛异常
并发 Task结构化并发 vs 非结构化并发
模型序列化反序列化 原生支持Codable vs 第三方库支持
泛型 强大的泛型 vs 鸡肋的泛型
响应式编程,观察者模式 原生Combine vs 第三方库 RxSwift, RecativeCocoa
@623637646
623637646 / 插桩
Created September 19, 2020 15:15
插桩
插桩技术
插桩技术是指将额外的代码注入程序中以收集运行时的信息,可分为两种:
(1)源代码插桩[Source Code Instrumentation(SCI)]:额外代码注入到程序源代码中。
(2)二进制插桩(Binary Instrumentation):额外代码注入到二进制可执行文件中。
@623637646
623637646 / RoundPixelByScale.m
Created June 18, 2021 10:47
Round Pixel By Scale for iOS
CGFloat YNSelfSizingRoundPixelValue(CGFloat value)
{
static CGFloat scale;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^(){
scale = [UIScreen mainScreen].scale;
});
return roundf(value * scale) / scale;
}
@623637646
623637646 / SwiftUIBug.swift
Created August 19, 2023 06:16
SwiftUI bug: Refresh logic of List is invalid in this case.
import SwiftUI
/// This demo shows a bug of SwiftUI. It's related to the refresh logic of "List"
///
/// The steps are:
/// 1. click "Go to next page"
/// 2. click "Click Me"
/// 3. Go back to home page
@623637646
623637646 / download.py
Created July 4, 2020 08:00
xiuren image spider
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2020-03-12 15:56:36
# Project: Girls
from pyspider.libs.base_handler import *
import os
import sys
@623637646
623637646 / ReactiveObjCBug
Last active May 28, 2020 11:57
ReactiveObjC 3.0.0 bug. when hook NSString dealloc method, NSString can't release. Updated: This is not ReactiveObjC bug. Refer to: https://stackoverflow.com/q/62064040/9315497
int i = 0;
while (YES) {
@autoreleasepool {
NSString *string = [[NSString alloc] initWithFormat:@"%d", i];
// or
// NSString *string = [[NSString alloc] init];
[[string rac_willDeallocSignal] subscribeCompleted:^{
NSLog(@"obj dealloc");
}];
@623637646
623637646 / ThreadNotSafetyTests.m
Last active May 13, 2020 16:49
iOS multiple threads is not safety with nonatomic properties.
#import <XCTest/XCTest.h>
@interface ThreadNotSafetyTests : XCTestCase
// no crash
//@property (atomic) NSObject *obj;
// crash
@property (nonatomic) NSObject *obj;
@end
@623637646
623637646 / AspectPositionInstead.m
Last active May 13, 2020 15:01
How to change the return value (for object) with Aspects's AspectPositionInstead. Refer to: https://www.jianshu.com/p/5ba69f35e034
@interface MyObject : NSObject
@property NSString *name;
@end
@implementation MyObject
-(void)dealloc
{
NSLog(@"dealloc");
}
@end