Skip to content

Instantly share code, notes, and snippets.

Avatar
° ☾ ☆ ¸. ¸ ★ :.  . • ○ ° ★

Kang Byeonghak ohtwo

° ☾ ☆ ¸. ¸ ★ :.  . • ○ ° ★
View GitHub Profile
@ohtwo
ohtwo / VerticalButton.swift
Created Nov 10, 2019
UIButton with vertiacal alignment image and title
View VerticalButton.swift
import UIKit
class VerticalButton: UIButton {
override func awakeFromNib() {
super.awakeFromNib()
titleLabel?.textAlignment = .center
}
@ohtwo
ohtwo / version.swift
Created Feb 14, 2019
Swift Version Test
View version.swift
```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)
View RawRepresentable-Equatable.swift
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 Jun 25, 2018 — forked from brennanMKE/BytesPlayground.swift
Copy bytes from Data with Swift
View BytesPlayground.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 — forked from radex/NSTimer.md
Swift Extensions: NSTimer
View NSTimer.md

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 Jan 18, 2018 — forked from unnamedd/README.md
Xcode pre-action to build custom Info.plist
View README.md

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.

@ohtwo
ohtwo / UIViewController.swift
Created Dec 22, 2017
Variable in extension has default value
View UIViewController.swift
struct InspectableComponent {
var isHideBackBarButtonTitle = true
}
protocol HasInspectableComponent {
var inspectableComponent: InspectableComponent { get set }
}
protocol InspectableAttribute: HasInspectableComponent { }
View fonts.swift
// Fonts
for family in UIFont.familyNames
{
print("\(family)")
for names in UIFont.fontNames(forFamilyName: family)
{
print("== \(names)")
}
}
@ohtwo
ohtwo / gmsmarker.swift
Last active Oct 27, 2020
GMSMarker with Drop Shadow
View gmsmarker.swift
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
View Meter.swift
import Foundation
public struct Meter {
fileprivate var value: Double
public init(_ value: Double) {
self.value = value
}
public init(_ value: Int) {