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
enum ScreenSize { | |
static let width = UIScreen.main.bounds.size.width | |
static let height = UIScreen.main.bounds.size.height | |
static let maxLength = max(ScreenSize.width, ScreenSize.height) | |
static let minLength = min(ScreenSize.width, ScreenSize.height) | |
} | |
enum DeviceTypes { | |
static let idiom = UIDevice.current.userInterfaceIdiom |
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 | |
struct AnchoredConstraints { | |
var top, leading, bottom, trailing, width, height: NSLayoutConstraint? | |
} | |
extension UIView { | |
@discardableResult | |
func anchor(top: NSLayoutYAxisAnchor?, leading: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, trailing: NSLayoutXAxisAnchor?, padding: UIEdgeInsets = .zero, size: CGSize = .zero) -> AnchoredConstraints { |
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 | |
extension UIView { | |
func addSubviews(_ views: UIView...) { | |
for view in views { addSubview(view) } | |
} | |
} |
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 String { | |
var isValidEmail: Bool { | |
let emailFormat = "" | |
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailFormat) | |
return emailPredicate.evaluate(with: self) | |
} | |
var isValidPassword: Bool { | |
//Regex restricts to 8 character minimum, 1 capital letter, 1 lowercase letter, 1 number |
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
/* | |
Filter | |
*/ | |
let familyNames = ["Park", "Lee", "Jong", "Kim", "Choi"] | |
let longFamilyNames = familyNames.filter { $0.count > 3 } | |
print(longFamilyNames) | |
// ["Park", "Jong", "Choi"] | |
let familyNames = ["Park", "Lee", "Jong", "Kim", "Choi"] |
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 | |
extension String { | |
func toDate(format: String) -> Date? { | |
let formatter = DateFormatter() | |
formatter.dateFormat = format | |
return formatter.date(from: 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
import UIKit | |
enum UIHelper { | |
/// Convert Zeplin line height to iOS line spacing | |
static func lineSpacing(from lineHeight: CGFloat, font: UIFont) -> CGFloat { | |
let value = lineHeight - font.lineHeight | |
return value | |
} |
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 collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) { | |
// works from iOS 12 and below | |
view.layer.zPosition = 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
import UIKit | |
protocol Moveable { | |
func move(to point: CGPoint) | |
} | |
extension Moveable { | |
func move(to point: CGPoint = .zero) { | |
move(to: point) | |
} |
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 | |
enum Dough: String { | |
case basic | |
case cheeseCrust | |
} | |
enum Topping: String, CaseIterable { | |
case pepperoni | |
case sausage |
OlderNewer