Skip to content

Instantly share code, notes, and snippets.

View brownsoo's full-sized avatar
๐Ÿข
Step by step

brownsoo brownsoo

๐Ÿข
Step by step
View GitHub Profile
@brownsoo
brownsoo / String+getImgSrcFromHtml.swift
Created August 12, 2024 12:13
html img src ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
import Foundation
let htmlString =
"""
<div class="class-fr-editor">
<span class="fr-video"><span class="thumb"><img data-src="https://download.hiclass.net/7e80/8680/9280/cf80/0a685485-0db8-49ff-adff-4e0fe969ed6d.jpg" class="lozad" src="https://download.hiclass.net/7e80/8680/9280/cf80/0a685485-0db8-49ff-adff-4e0fe969ed6d.jpg" data-loaded="true"></span></span>
<p></p>
<p></p>
<p><img class="fr-fic fr-dib lozad" data-src="https://download.hiclass.net/7e80/8680/9280/cf80/8ec6562d-b6c9-46b4-be21-1416dd83c624.jpg" src="https://download.hiclass.net/7e80/8680/9280/cf80/8ec6562d-b6c9-46b4-be21-1416dd83c624.jpg" data-loaded="true"></p>
</div>
@brownsoo
brownsoo / UIImageView+loadGif.swift
Created August 10, 2024 17:57
gif ํŒŒ์ผ ๋””์Šคํ”Œ๋ ˆ์ด
//
// UIImageView+.swift
// HEExample
//
// Created by hyonsoo on 8/11/24.
//
import UIKit
import ImageIO
@brownsoo
brownsoo / UITextView+numberOfLines.swift
Created July 24, 2024 00:02
UITextView ๋ผ์ธ์ˆ˜ ๊ณ„์‚ฐ
import Foundation
import UIKit
public extension UITextView {
func numberOfLines() -> Int {
let numberOfGlyphs = base.layoutManager.numberOfGlyphs
var index = 0, lineCount = 0
var lineRange = NSRange(location: NSNotFound, length: 0)
while index < numberOfGlyphs {
@brownsoo
brownsoo / DigitEnglishHangulPattern.swift
Last active October 7, 2024 06:07
Swift ์ˆซ์ž ์˜์–ด ํ•œ๊ธ€ ์ž…๋ ฅ Regex
let pattern = "[^\\dA-Za-z\\p{Hangul}]"
@brownsoo
brownsoo / BatchUpdates.swift
Last active February 1, 2024 00:42
UIKit ์ฝœ๋ ‰์…˜๋ทฐ ๋ฐฐ์น˜ ์—…๋ฐ์ดํŠธ ์œ„ํ•œ ๋น„๊ต ์œ ํ‹ธ
import Foundation
import UIKit
typealias BatchUpdatable = Identifiable & Equatable
/// ๋ฐฐ์น˜ ์—…๋ฐ์ดํŠธ๋ฅผ ์œ„ํ•œ ๋น„๊ต ๋ชจ๋ธ
///
struct BatchUpdates {
let deleted: [Int]
@brownsoo
brownsoo / UIButton+alignTextBelow.swift
Created January 12, 2024 09:49
UIButton image vertical aligned with text
// from; https://developer-eungb.tistory.com/30
extension UIButton {
func alignTextBelow(spacing: CGFloat = 4.0) {
guard let image = self.imageView?.image else {
return
}
guard let titleLabel = self.titleLabel else {
return
@brownsoo
brownsoo / TaskCancelledOnDismissView.swift
Created November 30, 2023 00:07
SwiftUI ์˜ˆ์‹œ : ๋ทฐ๊ฐ€ ์‚ฌ๋ผ์ง€๋ฉด Task๋Š” ์ž๋™ ์ทจ์†Œ
//
// TaskCancelledOnDismissView.swift
// SwiftUITaskWorkout
//
// Created by Paul Hudson.
// https://twostraws.gumroad.com/l/concurrency
//
import SwiftUI
@brownsoo
brownsoo / TaskWithIdView.swift
Created November 30, 2023 00:05
SwiftUI ์˜ˆ์‹œ - id ๋ณ€๊ฒฝ์œผ๋กœ Task๊ฐ€ ์žฌ์‹คํ–‰๋จ
//
// TaskWithIdView.swift
// SwiftUITaskWorkout
//
//
// Created by Paul Hudson.
// https://twostraws.gumroad.com/l/concurrency
import SwiftUI
@brownsoo
brownsoo / GetPermutations.swift
Created October 10, 2023 04:56
๋ฐฐ์—ด์˜ ์กฐํ•ฉ ๊ตฌํ•˜๊ธฐ (์ˆœ์„œ๋ฌด๊ด€)
/// ๋ฐฐ์—ด์˜ ์กฐํ•ฉ ๊ตฌํ•˜๊ธฐ
/// ์ˆœ์„œ์— ์ƒ๊ด€์—†์ด ๊ฐ™์€ ์š”์†Œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๋ฉด, ๊ฐ™์€ ์กฐํ•ฉ์œผ๋กœ ์ฒ˜๋ฆฌ (๊ฒฐ๊ตญ ์ฒ˜์Œ ์ œ๊ณต๋˜๋Š” ๋ฐฐ์—ด ์š”์†Œ๋“ค์˜ ์ˆœ์„œ๋ฅผ ์œ ์ง€ํ•œ๋‹ค)
/// - Parameters:
/// - arr: ์ œ๊ณต๋˜๋Š” ๋ฐฐ์—ด
/// - select: ๋ช‡๊ฐœ์˜ ์š”์†Œ๋ฅผ ์„ ํƒํ•ด์„œ ์กฐํ•ฉํ• ์ง€ ๊ฒฐ์ •
/// - Returns: ์ œ๊ณต๋œ ๋ฐฐ์—ด์—์„œ select ๊ฐœ๋ฅผ ์„ ํƒํ•ด์„œ ์กฐํ•ฉ๋œ ์ƒˆ ๋ฐฐ์—ด
func getPermutations(_ arr: [Book], select: Int) -> [[Book]] {
var results: [[Book]] = []
if select == 1 {
return arr.map { [$0] }
@brownsoo
brownsoo / IntRangeCase.swift
Created September 30, 2023 05:17
swift - switch range case
extension Int {
/// ์ˆซ์ž ๋ฒ”์œ„์— ๋”ฐ๋ผ ํ…์ŠคํŠธ ํ‘œ์‹œ
func readableCount() -> String {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.groupingSeparator = ""
formatter.maximumFractionDigits = 1
switch self {
case _ where self < 1000:
return "\(self)"