Skip to content

artemnovichkov/xcode-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xcode snippets

Usage

  • Associated Object Declaration (associated_object)
private struct AssociatedKeys {
    static var <#name#> = "<#name#>"
}

var <#name#>: String? {
    get {
        return objc_getAssociatedObject(self, &AssociatedKeys.<#name#>) as? String
    }

    set {
        if let newValue = newValue {
            objc_setAssociatedObject(self, &AssociatedKeys.<#name#>, newValue as String?, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
    }
}
  • Delay for calling (async_after)
DispatchQueue.main.asyncAfter(deadline: .now() + <#when: dispatch_time_t#>) {
}
  • Guard Self Declaration (guard_self)
guard let `self` = self else {
    return
}
  • Lazy Button Declaration (lazy_button)
private(set) lazy var button: UIButton = {
    let button = UIButton()
    button.setTitle("", for: .normal)
    button.setTitleColor(.black, for: .normal)
    button.addTarget(self, action: #selector(), for: .touchUpInside)
    return button
}()
  • Lazy Label Declaration (lazy_ll)
private(set) lazy var titleLabel: UILabel = {
    let label = UILabel()
    label.font = .systemFont(ofSize: 17, weight: .regular)
    label.textColor = .black
    return label
}()
  • Lazy Table View Declaration (lazy_table)
private(set) lazy var tableView: UITableView = {
    let tableView = UITableView()
    tableView.tableFooterView = UIView()
    return tableView
}()
fileprivate lazy var tableViewManager: TableViewManager = {
    return TableViewManager(tableView: self.tableView)
}()
  • Mark snippet (mark)
// MARK: - <#Title#>
  • Protocol Function Declaration (funcp)
func <#name#>(<#parameters#>)
  • Swift Singleton Declaration (shared)
static let shared = <# class #>

private init() {}
  • View Did Appear Declaration (viewDidAppear)
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
}

Installation

Manual

Drag .codesnippet files into ~/Library/Developer/Xcode/UserData/CodeSnippets.

Automatic

Run the command in your terminal:

curl -fsSL https://raw.githubusercontent.com/artemnovichkov/xcode-snippets/master/install.sh | sh

Author

Artem Novichkov, novichkoff93@gmail.com

License

Xcode Snippets is available under the MIT license. See the LICENSE file for more info.