Skip to content

Instantly share code, notes, and snippets.

View NikhilManapure's full-sized avatar
🎯
Focusing

Nikhil Manapure NikhilManapure

🎯
Focusing
View GitHub Profile
// MARK: - KVO
var observedPaths: [String] = []
// Usage - observeKVO(keyPath: #keyPath(camera.inputCamera.whiteBalanceMode))
func observeKVO(keyPath: String) -> Bool {
if shouldObserveKVO {
if self.classForCoder.automaticallyNotifiesObservers(forKey: keyPath) {
observedPaths.append(keyPath)
addObserver(self, forKeyPath: keyPath, options: [.old, .new], context: nil)
@NikhilManapure
NikhilManapure / Blurable.swift
Created July 1, 2017 07:51
Blurable extension with blur and unBlur function
extension UIView {
func blur() {
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.addSubview(blurEffectView)
}
func unBlur() {
@NikhilManapure
NikhilManapure / NormalizingOrientation.swift
Created June 22, 2017 09:50
Code for making image's orientation as .up
func imageByNormalizingOrientation() -> UIImage {
if imageOrientation == .up {
return self
}
UIGraphicsBeginImageContextWithOptions(size, false, scale)
draw(in: CGRect(origin: CGPoint.zero, size: size))
let normalizedImage: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return normalizedImage!
}
#if !TARGET_INTERFACE_BUILDER
// this code will run in the app itself
#else
// this code will execute only in IB
#endif
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
titleLabel.text = "Sample title"
imageView.image = UIImage(named: "defaultProfile")
}
@IBDesignable class NMView: UIView {
override func draw(_ rect: CGRect) {
layer.borderWidth = 1
// Draw your view
}
override func layoutSubviews() {
super.layoutSubviews()
//Layout your subviews according to reference to self.bounds
}
class NMView: UIView {
@IBInspectable var text: String? {
didSet { label.text = text }
}
var label: UILabel!
}
play(sound: "ShortRing", ofType: .wav)
func disposeSoundIDs() {
for soundID in notificationSoundLookupTable.values {
AudioServicesDisposeSystemSoundID(soundID)
}
}
var notificationSoundLookupTable = [String: SystemSoundID]()