Skip to content

Instantly share code, notes, and snippets.

View houze2311's full-sized avatar

Dmitriy Demchenko houze2311

  • Dnipro, Ukraine
View GitHub Profile
@houze2311
houze2311 / NSBundle
Created May 19, 2017 16:32
cheme Version ShortVersion BundleVersion
var firstScheme:String? {
get {
if let schemes: AnyObject? = NSBundle.mainBundle().infoDictionary?["CFBundleURLTypes"]?[0]["CFBundleURLSchemes"] {
if let scheme = schemes?[0] as? String {
return scheme
}
}
return nil
}
@houze2311
houze2311 / UILabel+Strikethrough
Created May 19, 2017 16:31
Set text strikethrough and line height in UILabel
extension UILabel {
func setStrikethrough(text:String, color:UIColor = UIColor.blackColor()) {
let attributedText = NSAttributedString(string: text , attributes: [NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue, NSStrikethroughColorAttributeName: color])
self.attributedText = attributedText
}
func setLineHeight(lineHeight: CGFloat) {
let text = self.text
if let text = text {
let attributeString = NSMutableAttributedString(string: text)
@houze2311
houze2311 / String+Random
Created May 19, 2017 16:30
Ramdom alphanumberic string
var randomString: String {
get {
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
let len = 20 // length
let randomString : NSMutableString = NSMutableString(capacity: len)
for (var i=0; i < len; i++){
let length = UInt32 (letters.length)
let rand = arc4random_uniform(length)
randomString.appendFormat("%C", letters.characterAtIndex(Int(rand)))
@houze2311
houze2311 / Int+yyyyMMddHHmm
Created May 19, 2017 16:29
Time interval (Int) to formatted String
extension Int {
var yyyyMMddHHmm: String {
get {
let date = NSDate(timeIntervalSince1970: NSTimeInterval(self)/1000)
let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
@houze2311
houze2311 / Int+TrimZero
Created May 19, 2017 16:24
Trim decimal point zero
extension Int {
var trimZero: String {
get {
return String(format: "%g", Double(self))
}
}
}
// Swift 3
import UserNotifications
extension UIUserNotificationType {
@available(iOS 10.0, *)
func authorizationOptions() -> UNAuthorizationOptions {
var options: UNAuthorizationOptions = []
if contains(.alert) {
import UIKit
extension UIWindow {
func switchToController(_ controller: UIViewController) {
if rootViewController != nil {
setNewRootViewController(controller)
} else {
rootViewController = controller
}
import UIKit
extension UIApplication {
class func topViewController(_ base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let navigationController = base as? UINavigationController, navigationController.viewControllers.count > 0 {
return topViewController(navigationController.visibleViewController)
}
import UIKit
extension UIView {
func searchVisualEffectsSubview() -> UIVisualEffectView? {
if let visualEffectView = self as? UIVisualEffectView {
return visualEffectView
} else {
for subview in subviews {
if let found = subview.searchVisualEffectsSubview() {
import UIKit
import CoreGraphics
extension UIView {
func insetsInContentView(_ contentView: UIView) -> UIEdgeInsets {
return UIEdgeInsets(
top: frame.minY,
left: frame.minX,
bottom: contentView.frame.height - frame.minY - frame.height,