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!")
}
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 |
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 |
```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 | |
} |
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 |
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!")
}
Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.
Edit Xcode Scheme and add a pre-action script.
Copy the contents of preaction.sh
into the pre-action script box.
struct InspectableComponent { | |
var isHideBackBarButtonTitle = true | |
} | |
protocol HasInspectableComponent { | |
var inspectableComponent: InspectableComponent { get set } | |
} | |
protocol InspectableAttribute: HasInspectableComponent { } |
// Fonts | |
for family in UIFont.familyNames | |
{ | |
print("\(family)") | |
for names in UIFont.fontNames(forFamilyName: family) | |
{ | |
print("== \(names)") | |
} | |
} |