Skip to content

Instantly share code, notes, and snippets.

View ohtwo's full-sized avatar
🌙
° ☾ ☆ ¸. ¸ ★ :.  . • ○ ° ★

Kang Byeonghak ohtwo

🌙
° ☾ ☆ ¸. ¸ ★ :.  . • ○ ° ★
View GitHub Profile
@ohtwo
ohtwo / PagerView.swift
Created August 15, 2024 06:38 — forked from mecid/PagerView.swift
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
@ohtwo
ohtwo / README.md
Created August 5, 2024 01:37 — forked from IsaacXen/README.md
(Almost) Every WWDC videos download links for aria2c.
import UIKit
public extension NSCollectionLayoutAnchor {
struct Offset {
fileprivate var absolute: CGPoint?
fileprivate var fractional: CGPoint?
private init(absolute: CGPoint?, fractional: CGPoint?) {
self.absolute = absolute
self.fractional = fractional
@ohtwo
ohtwo / SheetModalPresentationController.swift
Created October 26, 2022 04:52 — forked from vinczebalazs/SheetModalPresentationController.swift
A presentation controller to use for presenting a view controller modally, which can be dismissed by a pull down gesture. The presented view controller's height is also adjustable.
import UIKit
extension UIView {
var allSubviews: [UIView] {
subviews + subviews.flatMap { $0.allSubviews }
}
func firstSubview<T: UIView>(of type: T.Type) -> T? {
allSubviews.first { $0 is T } as? T
@ohtwo
ohtwo / VerticalButton.swift
Created November 10, 2019 12:04
UIButton with vertiacal alignment image and title
import UIKit
class VerticalButton: UIButton {
override func awakeFromNib() {
super.awakeFromNib()
titleLabel?.textAlignment = .center
}
@ohtwo
ohtwo / version.swift
Created February 14, 2019 05:36
Swift Version Test
```swift
#if swift(>=4.2)
print("Swift4.2")
#elseif swift(>=4.1)
print("Swift4.1")
#elseif swift(>=4.0)
print("Swift4.0")
#elseif swift(>=3.3)
print("Swift3.3")
#elseif swift(>=3.2)
func ==<U: Equatable, T: protocol<RawRepresentable, Equatable> where T.RawValue == U>(lhs: U, rhs: T) -> Bool {
return lhs == rhs.rawValue
}
func !=<U: Equatable, T: protocol<RawRepresentable, Equatable> where T.RawValue == U>(lhs: U, rhs: T) -> Bool {
return lhs != rhs.rawValue
}
@ohtwo
ohtwo / BytesPlayground.swift
Created June 25, 2018 01:51 — forked from brennanMKE/BytesPlayground.swift
Copy bytes from Data with Swift
import Foundation
let size = MemoryLayout<Int16>.stride
let data = Data(bytes: [1, 0, 2, 0, 3, 0]) // little endian for 16-bit values
let int16s = data.withUnsafeBytes { (bytes: UnsafePointer<Int16>) in
Array(UnsafeBufferPointer(start: bytes, count: data.count / size))
}
let length = data.count * MemoryLayout<Int16>.stride
@ohtwo
ohtwo / NSTimer.md
Created May 30, 2018 10:33 — forked from radex/NSTimer.md
Swift Extensions: NSTimer

NSTimer is a great example of an over-verbose, outdated Objective-C API. To run a simple line of code after a delay, you need to write a lot of boilerplate crap.

How about this:

NSTimer.schedule(5.seconds) {
  println("Hello world!")
}
@ohtwo
ohtwo / README.md
Created January 18, 2018 12:05 — forked from unnamedd/README.md
Xcode pre-action to build custom Info.plist

Automatic build versions from git in Xcode (and other goodies)

Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.

1. Xcode Scheme pre-action

Edit Xcode Scheme and add a pre-action script. Copy the contents of preaction.sh into the pre-action script box.