This file contains hidden or 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 embedView(_ view: UIView, inset: UIEdgeInsets = UIEdgeInsets.zero) { | |
let topConstraint = NSLayoutConstraint( | |
item: self, | |
attribute: .top, | |
relatedBy: .equal, | |
toItem: view, | |
attribute: .top, | |
multiplier: 1, | |
constant: inset.top |
This file contains hidden or 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 Foundation | |
protocol ReusableView: class { | |
static var identifier: String { get } | |
} | |
extension ReusableView where Self: UIView { | |
static var identifier: String { | |
return String(describing: self) | |
} |
This file contains hidden or 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 Foundation | |
extension Optional | |
{ | |
@discardableResult | |
func ifSome(_ handler: (Wrapped) -> Void) -> Optional { | |
switch self { | |
case .some(let wrapped): handler(wrapped); return self | |
case .none: return self | |
} |
This file contains hidden or 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
if let outputs = camera.captureSession.outputs { | |
for output in outputs { | |
if let output = output as? AVCaptureStillImageOutput { | |
if let videoConnection = output.connection(withMediaType: AVMediaTypeVideo) { | |
output.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (imageDataSampleBuffer, error) in | |
if let imageDataSampleBuffer = imageDataSampleBuffer { | |
let data: Data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer) | |
let rawMetadata = CMCopyDictionaryOfAttachments(nil, imageDataSampleBuffer, CMAttachmentMode(kCMAttachmentMode_ShouldPropagate)) | |
let metadata = CFDictionaryCreateMutableCopy(nil, 0, rawMetadata) as NSMutableDictionary |
This file contains hidden or 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
let blur = GPUImageGaussianSelectiveBlurFilter() | |
func addBlur() { | |
gpuImage?.removeAllTargets() | |
blur.blurRadiusInPixels = 20.0 | |
blur.excludeBlurSize = 0.0 | |
blur.excludeCircleRadius = 0.0 | |
This file contains hidden or 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 CornerRadiusWithShadowView: UIView { | |
var cornerRadius: CGFloat = 2.0 | |
var shadowOffsetWidth: Double = 0.0 | |
var shadowOffsetHeight: Double = 3.0 | |
var shadowColor: UIColor = .black | |
var shadowOpacity: Float = 0.5 | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
layer.cornerRadius = cornerRadius |
This file contains hidden or 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 CameraViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { | |
static let sourceType: UIImagePickerControllerSourceType = .photoLibrary | |
static let imagePickerController: UIImagePickerController? = { | |
if UIImagePickerController.isSourceTypeAvailable(sourceType) { | |
let imagePickerController = UIImagePickerController() | |
imagePickerController.sourceType = sourceType | |
return imagePickerController | |
} else { | |
return nil |
This file contains hidden or 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 RealmSwift | |
class Item: Object { | |
dynamic var name: String = "" | |
dynamic var date: Date = Date() | |
static var all: [Item] { | |
get { | |
do { | |
let realm = try Realm() |
This file contains hidden or 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
enum Fonts: String { | |
case NemoNightmares | |
case Zapfino | |
var uiFont: UIFont? { | |
get { | |
return UIFont(name: self.rawValue, size: 15) | |
} | |
} | |
} |
This file contains hidden or 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
for family in UIFont.familyNames { | |
print(“\(family)”) | |
for name in UIFont.fontNames(forFamilyName: family) { | |
print(“ \(name)”) // This name | |
} | |
} |
NewerOlder