Skip to content

Instantly share code, notes, and snippets.

View pookjw's full-sized avatar

Jinwoo Kim pookjw

View GitHub Profile
#import <AVFoundation/AVFoundation.h>
#import <VideoToolbox/VideoToolbox.h>
@interface AVPlayerVideoOutput (Category)
@property (class, nonatomic, readonly) BOOL cp_isSupported;
@end
@implementation AVPlayerVideoOutput (Category)
+ (BOOL)cp_isSupported {
#import <AVFoundation/AVFoundation.h>
@interface Observer: NSObject
@end
@implementation Observer
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([object isKindOfClass:[AVPlayer class]]) {
if ([keyPath isEqualToString:@"currentItem"]) {
AVPlayerItem * _Nullable oldPlayerItem = change[NSKeyValueChangeOldKey];
if (oldPlayerItem) {
import SwiftUI
import RealityKit
import Darwin.POSIX.dlfcn
struct ContentView: View {
var body: some View {
NavigationStack {
NavigationLink("Push") {
RealityView { _ in}
.onDisappear {
import Darwin.POSIX.dlfcn
import ObjectiveC.runtime
func foo() {
let handle = dlopen("/System/Library/Frameworks/TVServices.framework/TVServices", RTLD_NOW)
assert(handle != nil)
let TVSDevice: AnyClass = objc_lookUpClass("TVSDevice")!
let supportsUltrawide_method = class_getClassMethod(TVSDevice, Selector(("supportsUltrawide")))!
import Photos
extension PHImageManager {
func requestImage(
for asset: PHAsset,
targetSize: CGSize,
contentMode: PHImageContentMode,
options: PHImageRequestOptions?,
bufferingPolicy limit: AsyncThrowingStream<(UIImage?, [AnyHashable : Any]?), any Error>.Continuation.BufferingPolicy = .unbounded
) -> (stream: AsyncThrowingStream<(UIImage?, [AnyHashable : Any]?), any Error>, requestID: PHImageRequestID) {
@preconcurrency import Foundation
extension _KeyValueCodingAndObserving {
func observe<Value>(
_ keyPath: KeyPath<Self, Value>,
options: NSKeyValueObservingOptions = [],
bufferingPolicy limit: AsyncStream<NSKeyValueObservedChange<Value>>.Continuation.BufferingPolicy = .unbounded
) -> AsyncStream<NSKeyValueObservedChange<Value>> {
let (stream, continuation) = AsyncStream<NSKeyValueObservedChange<Value>>.makeStream(bufferingPolicy: limit)
private final class SerialExecutorToTaskExecutor: TaskExecutor {
private let unownedSerialExecutor: UnownedSerialExecutor
init(unownedSerialExecutor: UnownedSerialExecutor) {
self.unownedSerialExecutor = unownedSerialExecutor
}
func enqueue(_ job: consuming ExecutorJob) {
job.runSynchronously(on: unownedSerialExecutor)
}
import Foundation
extension _KeyValueCodingAndObserving {
func observe<Value>(
_ keyPath: KeyPath<Self, Value>,
options: NSKeyValueObservingOptions = [],
bufferingPolicy limit: AsyncStream<NSKeyValueObservedChange<Value>>.Continuation.BufferingPolicy = .unbounded
) -> AsyncStream<NSKeyValueObservedChange<Value>> {
guard !options.contains(.initial) else { fatalError() }
extension AsyncStream.Continuation.BufferingPolicy: @retroactive @unchecked Sendable {}
final class SerialExecutorToTaskExecutor: TaskExecutor {
private let unownedSerialExecutor: UnownedSerialExecutor
init(unownedSerialExecutor: UnownedSerialExecutor) {
self.unownedSerialExecutor = unownedSerialExecutor
}
func enqueue(_ job: consuming ExecutorJob) {
@_rawLayout(like: Bool)
struct ManyBools: ~Copyable {
static let max = MemoryLayout<Bool>.stride * 8
subscript(_ index: Int) -> Bool {
get {
guard (0..<ManyBools.max).contains(index) else { fatalError() }
return withUnsafeBytes(of: self) { ptr in
ptr