-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0cd3036
Showing
16 changed files
with
974 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EveryProjectHelpers.xcodeproj/xcuserdata |
Large diffs are not rendered by default.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...yProjectHelpers.xcodeproj/xcuserdata/Georg.xcuserdatad/xcschemes/xcschememanagement.plist
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>SchemeUserState</key> | ||
<dict> | ||
<key>EveryProjectHelpers.xcscheme</key> | ||
<dict> | ||
<key>orderHint</key> | ||
<integer>8</integer> | ||
</dict> | ||
</dict> | ||
<key>SuppressBuildableAutocreation</key> | ||
<dict> | ||
<key>566B78F21E3F766B00148249</key> | ||
<dict> | ||
<key>primary</key> | ||
<true/> | ||
</dict> | ||
<key>566B78FB1E3F766B00148249</key> | ||
<dict> | ||
<key>primary</key> | ||
<true/> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Foundation | ||
|
||
extension Bool { | ||
public var not: Bool { | ||
return !self | ||
} | ||
|
||
@discardableResult public mutating func reverse() -> Bool { | ||
return self != self | ||
} | ||
|
||
@discardableResult public mutating func setToTrue() -> Bool { | ||
self = true | ||
return true | ||
} | ||
|
||
@discardableResult public mutating func setToFalse() -> Bool { | ||
self = false | ||
return true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
extension UIColor { | ||
|
||
/// Create UIcolor from color hex representation | ||
/// | ||
/// - Parameter hex: color hex string representation like #333333 or CCCCCC | ||
/// - Returns: color from hex | ||
/// | ||
/// **Example:** | ||
/// ``` | ||
/// colorWithHexString("#333333") | ||
/// colorWithHexString("333333") | ||
/// colorWithHexString("CCCCCC") | ||
/// colorWithHexString("5f9eb7") | ||
/// ``` | ||
open class func colorWithHexString (_ hex:String) -> UIColor { | ||
var cString: String = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased(); | ||
|
||
if (cString.hasPrefix("#")) { | ||
cString = (cString as NSString).substring(from: 1) | ||
} | ||
|
||
if (cString.characters.count != 6) { | ||
return UIColor.gray | ||
} | ||
|
||
let rString = (cString as NSString).substring(to: 2) | ||
let gString = ((cString as NSString).substring(from: 2) as NSString).substring(to: 2) | ||
let bString = ((cString as NSString).substring(from: 4) as NSString).substring(to: 2) | ||
|
||
var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0; | ||
Scanner(string: rString).scanHexInt32(&r) | ||
Scanner(string: gString).scanHexInt32(&g) | ||
Scanner(string: bString).scanHexInt32(&b) | ||
|
||
return UIColor(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: CGFloat(1)) | ||
} | ||
|
||
/// Retutns default tint color #007AFF | ||
open class var defaultTintColor: UIColor { | ||
// #007AFF | ||
return UIColor(red: 0.0, green: 122.0/255.0, blue: 1.0, alpha: 1.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// EveryProjectHelpers.h | ||
// EveryProjectHelpers | ||
// | ||
// Created by MadGeorge on 30/01/2017. | ||
// Copyright © 2017 MadGeorge. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
//! Project version number for EveryProjectHelpers. | ||
FOUNDATION_EXPORT double EveryProjectHelpersVersionNumber; | ||
|
||
//! Project version string for EveryProjectHelpers. | ||
FOUNDATION_EXPORT const unsigned char EveryProjectHelpersVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <EveryProjectHelpers/PublicHeader.h> | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Foundation | ||
|
||
/// Shortcut for NSLocalizedString with empty comment | ||
public func L(_ key: String) -> String { | ||
return NSLocalizedString(key, comment: "") | ||
} | ||
|
||
/// Run closure in background | ||
/// | ||
/// Do not call UI on execution! | ||
public func future(closure: @escaping ()->()) { | ||
let backQueue = DispatchQueue.global() | ||
backQueue.async(execute: closure) | ||
} | ||
|
||
/// Run closure in background after delay | ||
/// | ||
/// Do not call UI on execution! | ||
public func delaiedFuture(_ delayInSeconds: Double, closure: @escaping ()->()) { | ||
let delay = DispatchTime.now() + delayInSeconds | ||
let backQueue = DispatchQueue.global() | ||
backQueue.asyncAfter(deadline: delay, execute: closure) | ||
} | ||
|
||
/// Run closure after delay on main thread | ||
/// | ||
/// Safe for UI calls | ||
public func delayCall(_ delayInSeconds: Double, closure: @escaping()->()) { | ||
let delay = DispatchTime.now() + delayInSeconds | ||
DispatchQueue.main.asyncAfter(deadline: delay) { | ||
closure() | ||
} | ||
} | ||
|
||
/// Run any closure on main thread explisitly | ||
public func ui(_ closure: @escaping ()->()){ | ||
DispatchQueue.main.async(execute: closure) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import UIKit | ||
|
||
/// Designable view with linear gradient settings | ||
@IBDesignable | ||
open class GradientView: UIView { | ||
|
||
@IBInspectable var topGradientColor: UIColor! | ||
@IBInspectable var bottomGradientColor: UIColor! | ||
@IBInspectable var locationTop: CGFloat = 0.0 | ||
@IBInspectable var locationBottom: CGFloat = 1.0 | ||
|
||
override open func awakeFromNib() { | ||
super.awakeFromNib() | ||
|
||
backgroundColor = UIColor.clear | ||
} | ||
|
||
override open func draw(_ rect: CGRect) { | ||
let colorSpace = CGColorSpaceCreateDeviceRGB(); | ||
let context = UIGraphicsGetCurrentContext(); | ||
|
||
let gradientColors = [topGradientColor.cgColor, bottomGradientColor.cgColor]; | ||
|
||
let gradientLocations: [CGFloat] = [locationTop, locationBottom] | ||
|
||
let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors as CFArray, locations: gradientLocations) | ||
|
||
let startPoint = CGPoint(x: 0, y: 0) | ||
|
||
let endPoint = CGPoint(x: 0, y: bounds.height) | ||
|
||
context?.drawLinearGradient(gradient!, start: startPoint, end: endPoint, options: []) | ||
} | ||
|
||
} | ||
|
||
/// Designable view with radial gradient settings | ||
@IBDesignable | ||
open class RadialGradientView: UIView { | ||
|
||
@IBInspectable var topGradientColor: UIColor! = UIColor.black | ||
@IBInspectable var bottomGradientColor: UIColor! = UIColor.white | ||
@IBInspectable var startRadius: CGFloat = 10 | ||
|
||
override open func awakeFromNib() { | ||
super.awakeFromNib() | ||
|
||
backgroundColor = UIColor.clear | ||
} | ||
|
||
override open func draw(_ rect: CGRect) { | ||
let colorSpace = CGColorSpaceCreateDeviceRGB(); | ||
let context = UIGraphicsGetCurrentContext(); | ||
|
||
let gradientColors = [topGradientColor.cgColor, bottomGradientColor.cgColor]; | ||
|
||
let gradientLocations: [CGFloat] = [0.0, 1.0] | ||
|
||
let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors as CFArray, locations: gradientLocations) | ||
|
||
var radius = frame.width | ||
if radius < frame.height { | ||
radius = frame.height | ||
} | ||
|
||
context?.drawRadialGradient(gradient!, startCenter: center, startRadius: startRadius, endCenter: center, endRadius: radius, options: []) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
<key>NSPrincipalClass</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
|
||
public protocol Localizer { | ||
/// Returns localised string for specified **key** parameter | ||
func l(_ key: String) -> String | ||
} | ||
|
||
public struct DefaultLocalizer : Localizer { | ||
public func l(_ key: String) -> String { | ||
return NSLocalizedString(key, comment: "") | ||
} | ||
} | ||
|
||
/// Use for expected result independed from system localisation | ||
public struct MockLocalizer : Localizer { | ||
/// Returns same key for specified key | ||
/// | ||
/// Use it in tests when you need expected result independed from system localisation | ||
|
||
public init() {} | ||
|
||
public func l(_ key: String) -> String { | ||
return key | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Foundation | ||
|
||
public protocol NumberShortcatable {} | ||
|
||
extension Double { public var isOne: Bool { return self == 1 } } | ||
extension Float { public var isOne: Bool { return self == 1 } } | ||
extension Int { public var isOne: Bool { return self == 1 } } | ||
extension Int8 { public var isOne: Bool { return self == 1 } } | ||
extension Int16 { public var isOne: Bool { return self == 1 } } | ||
extension Int32 { public var isOne: Bool { return self == 1 } } | ||
extension Int64 { public var isOne: Bool { return self == 1 } } | ||
extension UInt { public var isOne: Bool { return self == 1 } } | ||
extension UInt8 { public var isOne: Bool { return self == 1 } } | ||
extension UInt16 { public var isOne: Bool { return self == 1 } } | ||
extension UInt32 { public var isOne: Bool { return self == 1 } } | ||
extension UInt64 { public var isOne: Bool { return self == 1 } } | ||
|
||
extension Double { public var isZero: Bool { return self == 0 } } | ||
extension Float { public var isZero: Bool { return self == 0 } } | ||
extension Int { public var isZero: Bool { return self == 0 } } | ||
extension Int8 { public var isZero: Bool { return self == 0 } } | ||
extension Int16 { public var isZero: Bool { return self == 0 } } | ||
extension Int32 { public var isZero: Bool { return self == 0 } } | ||
extension Int64 { public var isZero: Bool { return self == 0 } } | ||
extension UInt { public var isZero: Bool { return self == 0 } } | ||
extension UInt8 { public var isZero: Bool { return self == 0 } } | ||
extension UInt16 { public var isZero: Bool { return self == 0 } } | ||
extension UInt32 { public var isZero: Bool { return self == 0 } } | ||
extension UInt64 { public var isZero: Bool { return self == 0 } } | ||
|
||
|
||
extension Double { public var incremented: Double { return self + 1 } } | ||
extension Float { public var incremented: Float { return self + 1 } } | ||
extension Int { public var incremented: Int { return self + 1 } } | ||
extension Int8 { public var incremented: Int8 { return self + 1 } } | ||
extension Int16 { public var incremented: Int16 { return self + 1 } } | ||
extension Int32 { public var incremented: Int32 { return self + 1 } } | ||
extension Int64 { public var incremented: Int64 { return self + 1 } } | ||
extension UInt { public var incremented: UInt { return self + 1 } } | ||
extension UInt8 { public var incremented: UInt8 { return self + 1 } } | ||
extension UInt16 { public var incremented: UInt16 { return self + 1 } } | ||
extension UInt32 { public var incremented: UInt32 { return self + 1 } } | ||
extension UInt64 { public var incremented: UInt64 { return self + 1 } } | ||
|
||
extension Double { @discardableResult public mutating func increment() -> Double { self += 1; return self; } } | ||
extension Float { @discardableResult public mutating func increment() -> Float { self += 1; return self; } } | ||
extension Int { @discardableResult public mutating func increment() -> Int { self += 1; return self; } } | ||
extension Int8 { @discardableResult public mutating func increment() -> Int8 { self += 1; return self; } } | ||
extension Int16 { @discardableResult public mutating func increment() -> Int16 { self += 1; return self; } } | ||
extension Int32 { @discardableResult public mutating func increment() -> Int32 { self += 1; return self; } } | ||
extension Int64 { @discardableResult public mutating func increment() -> Int64 { self += 1; return self; } } | ||
extension UInt { @discardableResult public mutating func increment() -> UInt { self += 1; return self; } } | ||
extension UInt8 { @discardableResult public mutating func increment() -> UInt8 { self += 1; return self; } } | ||
extension UInt16 { @discardableResult public mutating func increment() -> UInt16 { self += 1; return self; } } | ||
extension UInt32 { @discardableResult public mutating func increment() -> UInt32 { self += 1; return self; } } | ||
extension UInt64 { @discardableResult public mutating func increment() -> UInt64 { self += 1; return self; } } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import UIKit | ||
|
||
// UITableViewCell and UICollectionViewCell Reuse Identifier from class | ||
|
||
public protocol ReuseIdentifiable: class { | ||
static var defaultReuseIdentifier: String { get } | ||
} | ||
|
||
extension ReuseIdentifiable { | ||
public static var defaultReuseIdentifier: String { | ||
return String(describing: self) | ||
} | ||
} | ||
|
||
extension UITableViewCell: ReuseIdentifiable {} | ||
extension UICollectionViewCell: ReuseIdentifiable {} | ||
|
||
// UIViewController controller storyboard id from class | ||
|
||
public protocol SelfDescribingControllerClass { | ||
static var storyboardID: String { get } | ||
} | ||
|
||
extension SelfDescribingControllerClass { | ||
public static var storyboardID: String { | ||
return String(describing: self) | ||
} | ||
} | ||
|
||
extension UIViewController: SelfDescribingControllerClass {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import UIKit | ||
|
||
extension UIImage { | ||
open class func create(with color: UIColor, rect: CGRect = CGRect(x: 0, y: 0, width: 100, height: 100)) -> UIImage { | ||
UIGraphicsBeginImageContext(rect.size) | ||
let context = UIGraphicsGetCurrentContext()! | ||
|
||
context.setFillColor(color.cgColor) | ||
context.fill(rect) | ||
|
||
let img = UIGraphicsGetImageFromCurrentImageContext() | ||
UIGraphicsEndImageContext() | ||
|
||
return img! | ||
} | ||
} |
Oops, something went wrong.