This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This should not be difficult, but it is. | |
// If you miss the `isBeingPresented` check it breaks. | |
// it will force the portrait only viewcontroller into landscape (an unsupported orientation!) during dismiss | |
import UIKit | |
class ViewController: UIViewController { | |
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
.portrait | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct WeakEnum<Enum: RawRepresentable>: Codable where Enum: Codable & Equatable, Enum.RawValue: Codable { | |
let rawValue: Enum.RawValue | |
let value: Enum? | |
init(rawValue: Enum.RawValue) { | |
self.rawValue = rawValue | |
self.value = Enum.init(rawValue: rawValue) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImpactFeedbackGenerator { | |
fileprivate init() { | |
} | |
static func create() -> ImpactFeedbackGenerator { | |
if #available(iOS 10.0, *) { | |
return ConcreteImpactFeedbackGenerator() | |
} else { | |
return ImpactFeedbackGenerator() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OneBigSwitchExample { | |
enum Type { case First, Second } | |
var magic: String = "" | |
var cool: String = "" | |
var fast: Bool = false | |
func foo(type: Type) { | |
switch type { | |
case .First: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// so smoooooth. | |
func smoothstep(x: CGFloat) -> CGFloat { | |
return x*x*(3-2*x) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReadableContentGuideHelperView: UIView { | |
var onChange: ((CGRect)->())? | |
static func addToView(view: UIView) -> ReadableContentGuideHelperView { | |
let helperView = ReadableContentGuideHelperView() | |
view.addSubview(helperView) | |
if #available(iOS 9.0, *) { | |
helperView.setupAnchors(view) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreImage | |
extension UIImage { | |
func rectsForFaces() -> [CGRect] { | |
guard let cgImage = CGImage else { return [] } | |
let ciImage = CoreImage.CIImage(CGImage: cgImage) | |
let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh] | |
let detector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options) | |
let hallOfFaces = detector.featuresInImage(ciImage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
class func imageWithColor(color: UIColor, size: CGSize=CGSize(width: 1, height: 1)) -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
color.setFill() | |
UIRectFill(CGRect(origin: CGPoint.zero, size: size)) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIView { | |
func forEachSubviewOfType<V: UIView>(type: V.Type, @noescape apply block: V -> Void) { | |
for view in subviews { | |
if let view = view as? V { | |
block(view) | |
} else { | |
view.forEachSubviewOfType(V.self, apply: block) | |
} | |
} | |
} |
NewerOlder