Skip to content

Instantly share code, notes, and snippets.

#import <Cocoa/Cocoa.h>
NS_HEADER_AUDIT_BEGIN(nullability, sendability)
@class SVTextField;
@protocol SVTextFieldDelegate <NSTextFieldDelegate>
@optional - (BOOL)textField:(SVTextField *)textField shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string;
@end
@interface SVTextField : NSTextField
#import <Foundation/Foundation.h>
@interface MyPlaceholderValue : NSObject
- (instancetype)initWithInteger:(NSInteger)number;
@end
@implementation MyPlaceholderValue
- (id)initWithInteger:(NSInteger)number {
CFNumberRef result = CFNumberCreate(NULL, kCFNumberNSIntegerType, &number);
- (IBAction)foo:(id)sender {
unsigned int ivarsCount;
// 버그 : Xcode 15.0 beta 7 SDK에서 UITitlebar symbol이 정의되어 있지 않으므로 UITitlebar.class라고 표기하면 에러
Ivar *ivars = class_copyIvarList(NSClassFromString(@"UITitlebar"), &ivarsCount);
auto result = std::ranges::find_if(std::ranges::subrange(ivars, ivars + ivarsCount), [](Ivar ivar) {
auto name = ivar_getName(ivar);
return !std::strcmp(name, "_hostWindow");
});
//
// NSManagedObject+Concurrency.swift
//
//
// Created by Jinwoo Kim on 8/12/23.
//
import CoreData
extension NSManagedObject {
import Foundation
import Observation
actor NumberViewModel: Observable {
// MARK: - Number
private let _numberStorage: UnsafeMutablePointer<Int> = .allocate(capacity: 1)
private nonisolated var _number: Int {
get {
observationRegistrar.access(self, keyPath: \._number)
@pookjw
pookjw / AsyncStream+UITraitChangeObservable.swift
Last active June 8, 2023 09:30
AsyncStream + UITraitChangeObservable
import UIKit
extension UITraitChangeObservable where Self: AnyObject {
@MainActor
func traitChangesStream<TraitEnvironment: UITraitEnvironment>(traitEnvironment: TraitEnvironment.Type, traits: [UITrait]) -> AsyncStream<(TraitEnvironment, UITraitCollection)> {
let stream = AsyncStream<(TraitEnvironment, UITraitCollection)>.makeStream()
let registration = registerForTraitChanges(traits, handler: { (traitEnvironment: TraitEnvironment, previousTraitCollection: UITraitCollection) in
stream.continuation.yield(with: .success((traitEnvironment, previousTraitCollection)))
})
@pookjw
pookjw / Combine+UITraitChangeObservable.swift
Last active June 8, 2023 09:30
Combine + UITraitChangeObservable
import UIKit
import Combine
extension UITraitChangeObservable where Self: AnyObject {
func traitChanges<TraitEnvironment: UITraitEnvironment>(traitEnvironment: TraitEnvironment.Type, traits: [UITrait]) -> some Publisher<(TraitEnvironment, UITraitCollection), Never> {
let subject = PassthroughSubject<(TraitEnvironment, UITraitCollection), Never>()
let registration = registerForTraitChanges(traits, handler: { [weak subject] (traitEnvironment: TraitEnvironment, previousTraitCollection: UITraitCollection) in
subject?.send((traitEnvironment, previousTraitCollection))
})
@pookjw
pookjw / UIWindowSceneDidChangeScreenNotification.mm
Last active April 19, 2023 15:31
Detect screen changes on UIKit.
// File: UIWindowScene+DidChangeScreenNotification.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
static NSNotificationName const __UIWindowSceneDidChangeScreenNotification = @"__UIWindowSceneDidChangeScreenNotification";
@interface UIWindowScene (DidChangeScreenNotification)
@end
@pookjw
pookjw / hook_uiscene_create.m
Created February 10, 2023 02:34
Create UIWindow overlay on every UIWindowScene objects.
#import <UIKit/UIKit.h>
#import <substrate.h>
static void *DO_UIWindowScene_Association_Key;
@interface FBSScene : NSObject
@end
@interface UIScene (DO_Private)
+ (UIScene *)_sceneForFBSScene:(FBSScene *)arg1 create:(BOOL)arg2 withSession:(UISceneSession *)arg3 connectionOptions:(UISceneConnectionOptions *)arg4;
import Foundation
extension URLComponents {
func url(removingPercentEncoding: Bool) -> URL? {
guard let url: URL else {
return nil
}
guard removingPercentEncoding,
let refinedPath: String = url.absoluteString.removingPercentEncoding else {