Skip to content

Instantly share code, notes, and snippets.

View mrugeshtank's full-sized avatar
🎯
Focusing

Mrugesh Tank mrugeshtank

🎯
Focusing
View GitHub Profile
@mrugeshtank
mrugeshtank / removeSettings.sh
Created February 21, 2020 09:56
This script will remove settings bundle from iOS app when configuration is Release
BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
if [ "$CONFIGURATION" == "Release" ]; then
rm -Rf $BUILD_APP_DIR/Settings.bundle
fi
@mrugeshtank
mrugeshtank / Trimmed+propertyWrapper.swift
Created February 18, 2020 09:47
by this way you can always get trimmed value no more extension or method required
@propertyWrapper
struct Trimmed {
private(set) var value: String?
var wrappedValue: String? {
get {
return value
}
set {
value = newValue?.trimmingCharacters(in: .whitespacesAndNewlines)
}
@mrugeshtank
mrugeshtank / ConstraintsExtesnions.swift
Created February 12, 2020 10:43
extension for constraints for applying programmatically in swift 5.1
extension UIView {
func addSubviewsUsingAutoLayout(_ views: UIView ...) {
subviews.forEach {
self.addSubview($0)
$0.translatesAutoresizingMaskIntoConstraints = false
}
}
}
@objc extension NSLayoutAnchor {
@mrugeshtank
mrugeshtank / UITableView+emptyMessage.swift
Created January 23, 2020 02:38
add empty message when there is no data one UITableView
extension UITableView {
func setEmptyMessage(_ message: String) {
let messageLabel = UILabel(frame: CGRect(x: 0, y: 0, width: self.bounds.size.width, height: self.bounds.size.height))
messageLabel.text = message
messageLabel.textColor = .black
messageLabel.numberOfLines = 0;
messageLabel.textAlignment = .center;
messageLabel.font = UIFont.preferredFont(forTextStyle: .title3)
messageLabel.sizeToFit()
private var __maxLengthsForTextView = [UITextView: Int]()
private var kAssociationKeyMaxLengthTextView: Int = 0
extension UITextView:UITextViewDelegate {
@IBInspectable var maxLength: Int {
get {
if let length = objc_getAssociatedObject(self, &kAssociationKeyMaxLengthTextView) as? Int {
return length
} else {
return Int.max
@mrugeshtank
mrugeshtank / UITextField+maxLength.swift
Created January 23, 2020 02:33
UITextField with maxLength property
private var __maxLengthsForTextField = [UITextField: Int]()
extension UITextField {
//https://stackoverflow.com/a/43099816/3110026
@IBInspectable var maxLength: Int {
get {
guard let l = __maxLengthsForTextField[self] else {
return 150 // (global default-limit. or just, Int.max)
}
return l
}
@mrugeshtank
mrugeshtank / MyView.swift
Created January 23, 2020 02:31
load UIView from nib (xib)
class MyView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
fromNib()
}
init() {
super.init(frame: CGRect.zero)
fromNib()
}
@mrugeshtank
mrugeshtank / UserDefault+PropertyWrapper.swift
Created January 11, 2020 10:10
This piece of code shows how much propertyWrapper can be useful
@propertyWrapper
struct UserDefault<T> {
let key: String
let defaultValue: T
init(_ key: String, defaultValue: T) {
self.key = key
self.defaultValue = defaultValue
}
@mrugeshtank
mrugeshtank / database.rules.json
Created March 29, 2019 11:17 — forked from codediodeio/database.rules.json
Common Database Rules for Firebase
// No Security
{
"rules": {
".read": true,
".write": true
}
}
@mrugeshtank
mrugeshtank / README.md
Created December 29, 2018 05:30 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

All hex value from 100% to 0% alpha: