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 AVFoundation | |
class EACAudioManager: NSObject { | |
static let sharedInstance = EACAudioManager() | |
var volumeDidChange = { (newVolume: Float) -> () in } | |
var currentVolume: Float { return AVAudioSession.sharedInstance().outputVolume } | |
override init() { | |
super.init() | |
try! AVAudioSession.sharedInstance().setActive(true) | |
AVAudioSession.sharedInstance().addObserver(self, forKeyPath: "outputVolume", options: NSKeyValueObservingOptions.New, context: nil) |
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 UIStoryboard { | |
func instantiateViewControllerWithTypeAsIdentifier<T>(t: T.Type) -> T { | |
return instantiateViewControllerWithIdentifier(String(t)) as! T | |
} | |
} |
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 UIKit | |
import XCPlayground | |
class ClickableLinkTextView: UITextView { | |
override init(frame: CGRect, textContainer: NSTextContainer?) { | |
super.init(frame: frame, textContainer: textContainer) | |
setUp() | |
} | |
required init?(coder aDecoder: NSCoder) { |
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 UIKit | |
/** | |
You can use this to initalize an object (class or struct) while containing the set up code for it in a block | |
*/ | |
@warn_unused_result | |
func setUpObject<T>(obj: T, withBlock setUp: (inout T) -> ()) -> T { | |
var _obj = obj | |
setUp(&_obj) | |
return _obj |
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
UIView *getStatusBar() { | |
UIView *subViewWindow = [[UIApplication sharedApplication] valueForKey:@"statusBarWindow"]; | |
for (UIView *i in subViewWindow.subviews) { | |
if ([i isKindOfClass:NSClassFromString(@"UIStatusBar")]) { | |
return i; | |
} | |
} | |
return nil; | |
} |
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
// Making a class since we can not add generics to UIStoryboard nor can we make a category for it. | |
@interface UIStoryboardHelper <__covariant T:UIViewController *> : UIStoryboard | |
- (T)vcFromIdentifier:(NSString *)identifier fromStoryboard:(UIStoryboard *)storyboard; | |
@end | |
@implementation UIStoryboardHelper | |
- (UIViewController *)vcFromIdentifier:(NSString *)identifier fromStoryboard:(UIStoryboard *)storyboard { | |
return [storyboard instantiateViewControllerWithIdentifier:identifier]; | |
} | |
@end |
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 Foundation | |
/** | |
original macro | |
#define DHLocalizedString(KEY, TABLE, COMMENT) NSLocalizedStringWithDefaultValue(KEY, TABLE, [NSBundle mainBundle], NSLocalizedStringWithDefaultValue(KEY, TABLE, [NSBundle bundleForClass:[self class]]), COMMENT) | |
*/ | |
func getNameByRemovingPrefixPathAndExtension(name: String) -> String { | |
let url = NSURL(string: name)! |
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
protocol Singleton3_Protocol { | |
static var queue: OperationQueue { get } | |
static func method1() | |
} | |
protocol Name { | |
static var name: String { get set } | |
} | |
protocol Singleton3_Protocol2: Name { |
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
func supportsKeyboard(lang: String?) -> Bool { | |
guard let _lang = lang else { | |
return false | |
} | |
let predicates = [ | |
Predicate(format: "SELF == %@", "en"), | |
Predicate(format: "SELF like[cd] %@", "en-*") | |
] | |
for predicate in predicates { | |
if NSArray(arrayLiteral: _lang).filtered(using: predicate).count > 0 { |
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 UISearchBarMagnifyingGlass: NSObject { | |
@IBOutlet weak var searchBar: UISearchBar! { | |
didSet { | |
if let _color = color, let _searchBar = searchBar { | |
for i in _searchBar.subviews.first!.subviews { | |
if let textField = i as? UITextField, | |
let imageView = textField.leftView as? UIImageView, | |
let image = imageView.image | |
{ | |
let coloredImage = image.withRenderingMode(UIImageRenderingMode.alwaysTemplate) |
OlderNewer