Skip to content

Instantly share code, notes, and snippets.

View nekonora's full-sized avatar
🎸
Making stuff using other stuff.

Filippo Zaffoni nekonora

🎸
Making stuff using other stuff.
View GitHub Profile
///
/// 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`
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!
import UIKit
extension UIView {
func setConstraint(_ constraintBlock: ((UIView) -> Void)) {
translatesAutoresizingMaskIntoConstraints = false
constraintBlock(self)
layoutIfNeeded()
}
@nekonora
nekonora / Storage.swift
Created April 24, 2020 13:34
A useful little storage class for anything conforming to Codable, using UserDefaults and property wrappers
//
// Storage.swift
//
import Foundation
class Storage {
// MARK: - Keys
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) }
@nekonora
nekonora / AnimationSyncToKeyboard.swift
Last active July 14, 2022 04:46
Sync animation to keyboard appearing
@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
}
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 }
import UIKit
class ModularView: UIView {
// MARK: - Meta properties
let xibName = "ModularView"
let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String
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.",