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
// | |
// UIResponder+FirstResponder.swift | |
// Thor | |
// | |
// Created by Max Campolo on 8/20/17. | |
// Copyright © 2017 Max Campolo. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
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
let label = UILabel() | |
label.bounds = CGRect(x: 0, y: 0, width: CGFloat(size), height: CGFloat(size)) | |
label.font = UIFont(name: "AppleColorEmoji", size: CGFloat(size)) | |
label.numberOfLines = 0 | |
label.minimumScaleFactor = 0.01 | |
label.adjustsFontSizeToFitWidth = true | |
label.lineBreakMode = .byTruncatingTail |
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
public extension UIWindow { | |
public var visibleViewController: UIViewController? { | |
return UIWindow.getVisibleViewControllerFrom(self.rootViewController) | |
} | |
public static func getVisibleViewControllerFrom(vc: UIViewController?) -> UIViewController? { | |
if let nc = vc as? UINavigationController { | |
return UIWindow.getVisibleViewControllerFrom(nc.visibleViewController) | |
} else if let tc = vc as? UITabBarController { | |
return UIWindow.getVisibleViewControllerFrom(tc.selectedViewController) |
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 Double { | |
var suffixNumber: String { | |
get { | |
var num = self | |
let sign = num < 0 ? "-" : "" | |
num = fabs(num) | |
if num < 1000.0 { | |
return "\(sign)\(Int(num))" |
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 UILabel { | |
func willTruncate() -> Bool { | |
guard let labelText = text else { | |
return false | |
} | |
let mText = labelText as NSString | |
let attributes = [NSFontAttributeName : font] | |
let labelSize = mText.boundingRectWithSize(CGSize(width: bounds.width, height: CGFloat.max), options: .UsesLineFragmentOrigin, attributes: attributes, context: nil) | |
return Int(ceil(CGFloat(labelSize.height) / font.lineHeight)) > numberOfLines |
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 { | |
/** | |
Set a shadow on a UIView. | |
- parameters: | |
- color: Shadow color, defaults to black | |
- opacity: Shadow opacity, defaults to 1.0 | |
- offset: Shadow offset, defaults to zero | |
- radius: Shadow radius, defaults to 0 | |
- viewCornerRadius: If the UIView has a corner radius this must be set to match |
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
// Remove or add a file | |
git rm path/to/file | |
git add path/to/file | |
// Resetting state | |
// Revert working copy | |
git checkout . | |
// Revert unpushed commits | |
git reset | |
// Revert one commit |
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 Double { | |
public static let kRectX = 30.0 | |
public static let kRectY = 30.0 | |
public static let kRectWidth = 30.0 | |
public static let kRectHeight = 30.0 | |
} | |
public func makeRect() -> CGRect { | |
return CGRect(x: .kRectX, y: .kRectY, width: .kRectWidth, height: .kRectHeight) | |
} |
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
// Recursive | |
find . -name "*.filetype" | wc -l | |
// Nonrecursive | |
ls -l *.filetype | wc -l |
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
#!/bin/bash | |
# Auto Increment Version Script | |
buildPlist=$INFOPLIST_FILE | |
echo $buildPlist | |
CFSVString=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$buildPlist") | |
CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist") | |
BUILD_NR=${CFBundleVersion##*.} | |
BUILD_NR=$(($BUILD_NR + 1)) | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NR" "$buildPlist" |
NewerOlder