XcodeCodeSnippets - Code snippets for Xcode.

Overview

PRs Welcome

XcodeCodeSnippets

A set of snippets for Xcode.

Requirements

Xcode 7.3.1 or later.

Installation

To install or update the snippets you need:

  • Quit Xcode
  • On the command line:
cd ~/Downloads
git clone https://github.com/ismetanin/XcodeCodeSnippets
mkdir -p $HOME/Library/Developer/Xcode/UserData/CodeSnippets
cp XcodeCodeSnippets/CodeSnippets/* $HOME/Library/Developer/Xcode/UserData/CodeSnippets
rm -rf XcodeCodeSnippets

Or if you have a cloned repository:

  • On the command line, cd into the directory with snippets and write sh ./install.sh

List of snippets

MARKs

There are MARKs for Swift and Objective-C. For Swift there is prefix before each // MARK: - and for Objective-C prefix is #pragma mark -.

Shortcuts are equal to snippet body for example for // MARK: - Properties shortcut is Properties.

Available MARKs
Snippet
Just empty mark (// MARK: - or #pragma mark - )
Nested types
Constants
Subviews
NSLayoutConstraints
Properties
Public properties
Readonly properties
IBOutlets
Initialization and deinitialization
UITableViewCell
UIViewController
Actions
IBActions
Public methods
Internal methods
Private methods

Code

  • A template for creating TableViewAdapter, shortcut: Table View Adapter

    Code
     import UIKit
    
     protocol <#Your#>TableViewAdapterOutput {
     }
    
     final class <#Your#>TableViewAdapter: NSObject {
         // MARK: - Properties
    
         private let output: <#Your#>TableViewAdapterOutput
    
         private var items: [String]
         private var tableView: UITableView
    
         // MARK: - Initialization and deinitialization
    
         init(tableView: UITableView, output: <#Your#>TableViewAdapterOutput) {
             self.output = output
             self.tableView = tableView
             self.items = []
             super.init()
             setupTable()
         }
    
         // MARK: - Internal methods
    
         func configure(with items: [String]) {
             self.items = items
             tableView.reloadData()
         }
    
         // MARK: - Private methods
    
         private func setupTable() {
             tableView.delegate = self
             tableView.dataSource = self
             tableView.register(
                 UINib(nibName: String(describing: <#Your#>TableViewCell.self), bundle: nil),
                 forCellReuseIdentifier: String(describing: <#Your#>TableViewCell.self)
             )
         }
     }
    
     // MARK: - UITableViewDataSource
    
     extension <#Your#>TableViewAdapter: UITableViewDataSource {
         func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
             return items.count
         }
    
         func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
             let cell = tableView.dequeueReusableCell(
                 withIdentifier: String(describing: <#Your#>TableViewCell.self),
                 for: indexPath
             ) as? TableViewCell
             cell?.backgroundColor = .red
             return cell ?? <#Your#>UITableViewCell()
         }
     }
    
     // MARK: - UITableViewDelegate
    
     extension <#Your#>TableViewAdapter: UITableViewDelegate {
         func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
             tableView.deselectRow(at: indexPath, animated: true)
         }
     }
  • A code block for creating user property in UserDefaults extension, shortcut: Defaults Key

    Code
     var <#defaultsKey#>: <#Type#> {
         get { return <#typeof#>(forKey: #function) }
         set { set(newValue, forKey: #function) }
     }
  • A code block for layouting child view anchors equal to the parent view anchors, shortcut: Constraints - layout child as parent

    Code
     <#childView#>.translatesAutoresizingMaskIntoConstraints = false
    
     NSLayoutConstraint.activate([
         <#childView#>.topAnchor.constraint(equalTo: <#parentView#>.safeAreaLayoutGuide.topAnchor, constant: 0),
         <#childView#>.bottomAnchor.constraint(equalTo: <#parentView#>.safeAreaLayoutGuide.bottomAnchor, constant: 0),
         <#childView#>.leadingAnchor.constraint(equalTo: <#parentView#>.safeAreaLayoutGuide.leadingAnchor, constant: 0),
         <#childView#>.trailingAnchor.constraint(equalTo: <#parentView#>.safeAreaLayoutGuide.trailingAnchor, constant: 0)
         ])
  • A code block for user property creating in NSNotification.Name extension, shortcut: NSNotification Name

    Code
    static let <#notificationName#> = NSNotification.Name("<#projectName#>.notifications.<#notificationName#>")
  • A code block for creating template comments for unit test, shortcut: testtemplate

    Code
    // given
    
    // when
    
    // then
    
  • A code block for creating template constants enum, shortcut: Constants enum

    Code
     // MARK: - Nested types
    
     private enum Constants {
    
     }
  • A code block for creating keyboard notifications detector, shortcut: Keyboard detector

    Code
    func addKeyboardObservers() {
         NotificationCenter.default.addObserver(self,
                                                selector: #selector(keyboardWillShow),
                                                name: UIResponder.keyboardWillShowNotification,
                                                object: nil)
         NotificationCenter.default.addObserver(self,
                                                selector: #selector(keyboardWillHide),
                                                name: UIResponder.keyboardWillHideNotification,
                                                object: nil)
     }
    
     @objc
     func keyboardWillShow(notification: NSNotification) {
         guard
             let frame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
         else {
             return
         }
     }
    
     @objc
     func keyboardWillHide() {
    
     }

Author

Ivan Smetanin, [email protected]

License

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

You might also like...
An Xcode Plugin to upload code snippets directly into Slack and Gist
An Xcode Plugin to upload code snippets directly into Slack and Gist

XCSnippetr Share code snippets to Slack and Gist without leaving Xcode ever again! 😱 Features Upload code snippets using Slack's and Github's APIs. T

Swift package to interact with Xcode Code Snippets in a type-safe manner

XCSnippets Swift package to provide type-safe interaction with (user-defined) Xcode Code Snippets Overview import XCSnippets let directory = Persiste

Swift package to interact with Xcode Code Snippets in a type-safe manner

XCSnippets Swift package to provide type-safe interaction with (user-defined) Xcode Code Snippets Overview import XCSnippets let directory = Persiste

🍮 A collection of Swift snippets to be used in Xcode

Swift Snippets ❤️ Support my app ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcu

SnippetsLibrary - Code snippets library for SwiftUI Devs.
SnippetsLibrary - Code snippets library for SwiftUI Devs.

SnippetsLibrary is a helpful tool for SwiftUI developers to help with their daily coding life. SnippetsLibrary contains all the needed code snippets for you to view, edit, or add more and more. This will make your daily work easier and faster.

Some helpful swift code snippets

HelpfulSwiftSnippets Some helpful swift code snippets Network Manager - a generic network manager that deals with downloading data from the internet u

A μlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and emoji.

CountryKit CountryKit A μlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and e

Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode
Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode

Stream Deck Xcode Plugin This repository contains a Stream Deck plugin to add so

XTextHandler - Xcode Source Editor Extension Tools (Xcode 8 Plugins)
XTextHandler - Xcode Source Editor Extension Tools (Xcode 8 Plugins)

Download Let's Swift! xTextHandler has been rewritten in Swift. The Objective-C version can be found in: https://github.com/cyanzhong/xTextHandler-obj

Awesome-xcode-scripts - A curated list of useful xcode scripts 📝 .
Awesome-xcode-scripts - A curated list of useful xcode scripts 📝 .

Awesome Xcode Scripts A curated list of useful Xcode scripts 📝 . Content How to Setup Scripts Build Number Auto-Increment Script Build Number Auto-In

Synx - A command-line tool that reorganizes your Xcode project folder to match your Xcode groups
Synx - A command-line tool that reorganizes your Xcode project folder to match your Xcode groups

A command-line tool that reorganizes your Xcode project folder to match your Xcode groups. Xcode Finder Installation $ gem install synx Usage Basic ⚠

This repository contains 🎨 My Xcode theme that I use. It is compatible with all versions of Xcode.
This repository contains 🎨 My Xcode theme that I use. It is compatible with all versions of Xcode.

DRL Xcodetheme Installation Automatic (via script) ./install.sh which will install the file in Xcode FontAndColorThemes directory. Restart Xcode Go t

LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.
LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.

LinkedLog Xcode Plugin LinkedLog is a Xcode plugin that includes a Xcode PCH file template that adds the macros LLog and LLogF. The LLog macro will wo

Xcode plugin that brings ⇧⌘T from AppCode over to Xcode

Aviator An Xcode Plugin that brings ⇧⌘T over to Xcode This minimal plugin allows you to use the key combo ⇧⌘T to toggle between source and test files.

 A guide on setting up Xcode with all the essential Applications, Tools, and Frameworks to make your development experience with Xcode great!
A guide on setting up Xcode with all the essential Applications, Tools, and Frameworks to make your development experience with Xcode great!

A guide on setting up Xcode with all the essential Applications, Tools, and Frameworks to make your development experience with Xcode great!

This Xcode plugin shows Xcode app version in the Dock and App Switcher icon
This Xcode plugin shows Xcode app version in the Dock and App Switcher icon

Xcode Icon Version Tired of this Xcode icon always showing multiple times in your App Switch with no help watshoever as to which version you are curre

Solarized Dark Theme for Xcode. Compatible with all modern versions of Xcode since 2013!
Solarized Dark Theme for Xcode. Compatible with all modern versions of Xcode since 2013!

Solarized Dark for Xcode Note I've moved away from using Solarized to a Night-Shift/Dark-Mode-friendly palette of my own creation; Cognac. It's availa

A command-line tool and Xcode Extension for formatting Swift code
A command-line tool and Xcode Extension for formatting Swift code

Table of Contents What? Why? How? Command-line tool Xcode source editor extension Xcode build phase Via Applescript VSCode plugin Sublime Text plugin

An Xcode formatter plug-in to format your swift code.
An Xcode formatter plug-in to format your swift code.

Swimat Swimat is an Xcode plug-in to format your Swift code. Preview Installation There are three way to install. Install via homebrew-cask # Homebrew

Comments
  • Comments snippets xcode9 bug

    Comments snippets xcode9 bug

    Related issue #5

    Changes:

    • Fix completion scope and content of comment snippets
    • Add "//" to each snippet
    • Fix README

    Notes:

    • Now code snippets works without "//" in "all" completion scopes
    opened by ismetanin 0
Owner
Ivan Smetanin
Ivan Smetanin
Swift package to interact with Xcode Code Snippets in a type-safe manner

XCSnippets Swift package to provide type-safe interaction with (user-defined) Xcode Code Snippets Overview import XCSnippets let directory = Persiste

Marco Eidinger 3 Jun 24, 2022
Awesome-xcode-scripts - A curated list of useful xcode scripts 📝 .

Awesome Xcode Scripts A curated list of useful Xcode scripts ?? . Content How to Setup Scripts Build Number Auto-Increment Script Build Number Auto-In

Aashish Tamsya 110 Dec 26, 2022
Synx - A command-line tool that reorganizes your Xcode project folder to match your Xcode groups

A command-line tool that reorganizes your Xcode project folder to match your Xcode groups. Xcode Finder Installation $ gem install synx Usage Basic ⚠

Venmo 6.1k Jan 2, 2023
CodeEditTextView - An Xcode-inspired code editor view written in Swift powered by tree-sitter for CodeEdit

An Xcode-inspired code editor view written in Swift powered by tree-sitter for CodeEdit. Features include syntax highlighting (based

CodeEdit 243 Jan 8, 2023
Swift-VIPER-Module - Xcode template for VIPER Architecture written in Swift 4

⚠️ Deprecated ⚠️ This library is deprecated. When you decide to use VIPER architecture in your project, it is very tired create new modules, because y

Juanpe Catalán 533 Nov 17, 2022
ViperC - Xcode template for VIPER Architecture for both Objective-C and Swift.

ViperC Xcode template for VIPER Architecture for both Objective-C and Swift. ViperC creates modules for you when you want to use VIPER architecture in

Abdullah Selek 79 Nov 2, 2022
VIPERModuleTemplate - Template of VIPER Module for Xcode

Once you've decided to use a VIPER architecture in your app, you should know about the routine. For each screen/module you should create at least 6 fi

Bogdan Evsenev 17 Dec 10, 2021
Xcode-developer-disk-image-all-platforms - A repo which shares all developer disk images for iOS, tvOS, watchOS

Disclaimer: The available resources and files from this repo are uploaded from many contributors. The files are unverified, untested, and could have n

Hai K 253 Dec 21, 2022
Awesome-gitignore-templates - A curated collection of useful gitignore templates for different programming languages while pushing your code to git. 😊 📝

Awesome Gitignore Templates A curated collection of useful gitignore templates for different programming languages while pushing your code to git. ??

Aashish Tamsya 19 Jun 11, 2022
XCSnippetsApp - macOS application to explore code snippets from the Swift and iOS community, view and edit the snippets before adding them conveniently to Xcode

XCSnippetsApp macOS application to explore code snippets from the Swift and iOS community, view and edit the snippets before adding them conveniently

Marco Eidinger 119 Dec 27, 2022