Skip to content

Instantly share code, notes, and snippets.

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

Kang Byeonghak ohtwo

🌙
° ☾ ☆ ¸. ¸ ★ :.  . • ○ ° ★
View GitHub Profile
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 / UIViewController+InspectableAttribute.swift
Last active July 22, 2022 06:30
Variable in extension has default value
struct InspectableComponent {
var isHideBackBarButtonTitle = true
}
protocol HasInspectableComponent {
var inspectableComponent: InspectableComponent { get set }
}
protocol InspectableAttribute: HasInspectableComponent { }
@ohtwo
ohtwo / gmsmarker.swift
Last active October 27, 2020 01:19
GMSMarker with Drop Shadow
import Foundation
import GoogleMaps
func getShadowMarker() -> GMSMarker {
let marker = GMSMarker()
let image = UIImageView(image: UIImage(named: "marker"))
marker.iconView = image
marker.iconView?.contentMode = .center
marker.iconView?.bounds.size.width *= 2
@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.