Skip to content

Instantly share code, notes, and snippets.

View pookjw's full-sized avatar

Jinwoo Kim pookjw

View GitHub Profile
import SwiftUI
struct ContentView: View {
@EnvironmentObject var myViewModel: MyViewModel
@State private var showDetailView = false
var presentationButton: some View {
Button(action: { self.showDetailView.toggle() },
label: { Text("Button") })
.sheet(isPresented: self.$showDetailView,
@pookjw
pookjw / randomHangul.swift
Last active January 7, 2021 01:01
Swift에서 랜덤 한글 가져오기
public extension Character {
static func randomHangul() -> Character {
let startHexIndex: String = "AC00"
let endHexIndex: String = "D7AF"
guard let startDecIndex = Int(startHexIndex, radix: 16) else { return "엥" }
guard let endDecIndex = Int(endHexIndex, radix: 16) else { return "엥" }
let randomIndex = Int.random(in: startDecIndex...endDecIndex)
guard let unicode = UnicodeScalar(randomIndex) else { return "엥" }
@pookjw
pookjw / NSString+RandomHangul.m
Created January 7, 2021 01:00
Objective-C에서 랜덤 한글 가져오기
#import "NSString+RandomHangul.h"
@implementation NSString (RandomHangul)
+ (NSString *)randomHangul {
NSUInteger startIntIndex = 0xAC00;
NSUInteger endIntIndex = 0xD7AF;
NSUInteger randomIndex = rand() % (endIntIndex + 1 - startIntIndex) + startIntIndex;
return [NSString stringWithFormat:@"%C", (unichar)randomIndex];

adjustsLetterSpacingToFitWidth

UILabel에는 adjustsLetterSpacingToFitWidth라는 것이 있다.

@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth;

IB에서는 Tighten Letter Spacing이라고 적혀 있는데, property 이름을 보면 이게 무슨 역할인지 알 수 있다.

import UIKit
extension UIView {
public func removeAllInteractions() {
interactions.forEach { [weak self] interaction in
self?.removeInteraction(interaction)
}
}
}
@pookjw
pookjw / NSTableView+scrollToTop.swift
Created March 14, 2021 06:49
Scroll to top for NSTableView
import Cocoa
extension NSTableView {
internal func scrollToTop() {
guard let headerViewHeight: CGFloat = headerView?.frame.height else {
scroll(.zero)
return
}
scroll(CGPoint(x: 0, y: -headerViewHeight))
}
import Cocoa
extension NSTextField {
internal func setLabelStyle() {
isEditable = false
isSelectable = false
maximumNumberOfLines = 0
isBezeled = false
drawsBackground = false
preferredMaxLayoutWidth = 0
//
// ViewController.swift
// ConcurrencyApp
//
// Created by Jinwoo Kim on 6/8/21.
//
import UIKit
extension OperationQueue {
import Foundation
import Combine
extension Publisher {
func withUnretained<T: AnyObject>(_ object: T) -> Publishers.CompactMap<Self, (T, Self.Output)> {
compactMap { [weak object] output in
guard let object = object else {
return nil
}
return (object, output)
#import <UIKit/UIKit.h>
@interface _TtC4Toss11AppDelegate
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;
@end
@interface _TtC9KakaoTalk17TalkSceneDelegate
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts;
@end