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
/// | |
/// Swift script to parse, find & replace a set of values with corresponding keys | |
/// from a given file. | |
/// In this case for example it's used to replace strings in `"my.String".localized()` | |
/// with their R.swift generated counterparts. | |
/// | |
/// How to use: | |
/// - copy the script into the project root folder | |
/// - set permissions: `chmod -R +x CleanKeys.swift` | |
/// - run: `./CleanKeys.swift` |
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 | |
import UIKit | |
class ModalScreenVC: UIViewController { | |
// MARK: - Outlets | |
/// A subview filling this controller's view with desired top margin | |
@IBOutlet private var contentView: UIView! | |
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 setConstraint(_ constraintBlock: ((UIView) -> Void)) { | |
translatesAutoresizingMaskIntoConstraints = false | |
constraintBlock(self) | |
layoutIfNeeded() | |
} | |
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
// | |
// Storage.swift | |
// | |
import Foundation | |
class Storage { | |
// MARK: - Keys | |
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 MyViewController: UIScrollViewDelegate { | |
func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
if scrollView == tableView { // Table view for example | |
var scrollY = scrollView.contentOffset.y + scrollView.contentInset.top + 40 | |
if scrollY < 0 { scrollY = 0 } | |
constraintToChange.constant = -scrollY | |
if 0...10 ~= scrollY { viewToHide.alpha = 1 - (scrollY.rounded() / 10.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
@objc func keyboardWillShow(_ notification: NSNotification) { | |
let keyboardAnimationDetail = notification.userInfo | |
let animationCurve: Int = { | |
if let keyboardAnimationCurve = keyboardAnimationDetail?[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int { | |
let curve: Int? = UIView.AnimationCurve(rawValue: keyboardAnimationCurve)?.rawValue | |
return curve ?? 0 | |
} else { | |
return 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 | |
public extension UIDevice { | |
static let modelName: String = { | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
let machineMirror = Mirror(reflecting: systemInfo.machine) | |
let identifier = machineMirror.children.reduce("") { identifier, element in | |
guard let value = element.value as? Int8, value != 0 else { return identifier } |
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 | |
class ModularView: UIView { | |
// MARK: - Meta properties | |
let xibName = "ModularView" | |
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 appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String |
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 attributedText = NSMutableAttributedString( | |
string: "First string", | |
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14, weight: .semibold)]) | |
attributedText.append(NSAttributedString( | |
string: "Bold string", | |
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14, weight: .heavy)])) | |
attributedText.append(NSAttributedString( | |
string: "Last string.", |
NewerOlder