(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| let emitterLayer = CAEmitterLayer() | |
| emitterLayer.frame = navigationView.bounds | |
| emitterLayer.renderMode = .additive | |
| emitterLayer.emitterMode = .outline | |
| emitterLayer.emitterShape = .line | |
| emitterLayer.emitterSize = CGSize(width: 50, height: 0) | |
| emitterLayer.emitterPosition = CGPoint(x: navigationView.bounds.width / 2, y: navigationView.bounds.height) | |
| emitterLayer.velocity = 1 | |
| emitterLayer.seed = (arc4random() % 100) + 1 | |
| navigationView.layer.insertSublayer(emitterLayer, at: 0) |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| var backgroundColor: [UInt8] = [0, 0, 0, 0] | |
| let GaussianBlurKernel: [Int16] = | |
| [ 1, 4, 6, 4, 1, | |
| 4, 16, 24, 16, 4, | |
| 6, 24, 36, 24, 6, | |
| 4, 16, 24, 16, 4, | |
| 1, 4, 6, 4, 1 | |
| ] |
| import Accelerate | |
| import UIKit | |
| public extension UIImage { | |
| public func applyLightEffect() -> UIImage? { | |
| return applyBlur(radius: 30, tintColor: UIColor(white: 1, alpha: 0.3)) | |
| } | |
| public func applyExtraLightEffect() -> UIImage? { | |
| return applyBlur(radius: 20, tintColor: UIColor(white: 0.97, alpha: 0.82)) |
| // Assumes ARGB8888 | |
| CGImageRef CGImageCreateBlurredImage(CGImageRef inImage, NSUInteger blurRadius) | |
| { | |
| if (!inImage) { return NULL; } | |
| uint32_t radius = (blurRadius % 2) ? (uint32_t)blurRadius : (uint32_t)++blurRadius; | |
| vImage_Error error; | |
| vImage_CGImageFormat imageFormat = {(uint32_t)CGImageGetBitsPerComponent(inImage), (uint32_t)CGImageGetBitsPerPixel(inImage), CGImageGetColorSpace(inImage), CGImageGetBitmapInfo(inImage), 0, NULL, kCGRenderingIntentDefault}; | |
| vImage_Buffer source; |
| #!/usr/bin/env bash | |
| # This function lets you easily create series of commands into a single call | |
| # It will print each successive command, run it and, as long as it returned | |
| # with code 0, continue to the next step. | |
| # If any step fails, it will stop and let you pick it back up after you fix the | |
| # issues. | |
| # | |
| # Example of script using this function: | |
| # !/usr/bin/env bash |
Author: Chris Lattner
| import UIKit | |
| struct UILabelDebugOptions: OptionSet { | |
| let rawValue: Int | |
| static let bounds = UILabelDebugOptions(rawValue: 1 << 0) | |
| static let ascender = UILabelDebugOptions(rawValue: 1 << 1) | |
| static let descender = UILabelDebugOptions(rawValue: 1 << 2) | |
| static let xHeight = UILabelDebugOptions(rawValue: 1 << 3) | |
| static let capHeight = UILabelDebugOptions(rawValue: 1 << 4) |
| import UIKit | |
| struct UILabelDebugOptions: OptionSet { | |
| let rawValue: Int | |
| static let bounds = UILabelDebugOptions(rawValue: 1 << 0) | |
| static let ascender = UILabelDebugOptions(rawValue: 1 << 1) | |
| static let descender = UILabelDebugOptions(rawValue: 1 << 2) | |
| static let xHeight = UILabelDebugOptions(rawValue: 1 << 3) | |
| static let capHeight = UILabelDebugOptions(rawValue: 1 << 4) |
| // Multi to single thread execution | |
| // Credits go to https://www.reddit.com/r/swift/comments/7ijbt0/whats_a_good_way_to_make_sync_calls_from_swift_to/dr4iwxr/ | |
| import Foundation | |
| import PlaygroundSupport | |
| PlaygroundPage.current.needsIndefiniteExecution = true | |
| DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3000)) { | |
| print("Done") | |
| PlaygroundPage.current.finishExecution() |