16

Is there any keyboard shortcut for '// MARK:' in swift like there is for header doc '/// Description' ?

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Mr. SS
  • 387
  • 2
  • 19

3 Answers3

36

There is no problem to add it as a code snippet to Xcode.

What you should do is:

  • Type: // MARK: <#Description#>, select it and then drag it to the code snippet in the utilities section:

enter image description here

  • Fill the popup form, as follows:

enter image description here

and that's it!

Usage:

As per the screenshot above, the completion handler shortcut is: 'm'; By typing 'm' in the code area, you should see:

enter image description here

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
6

No there isn't any shortcuts for the //MARK. However, you can create a code snippet for it and re-use whenever and wherever you want.

Steps:

  • Declare a //MARK statement on top of extension or method
  • Drag the //MARK into the code snippet section (it's to the left of object library section at bottom right part of Xcode) enter image description here
  • You would be asked to create a name for the snippet. Label it appropriately. And that's it.

  • For usage, Drag and drop this snippet anywhere you want

Zarif Ahmed
  • 343
  • 2
  • 9
6

There is one Command we have to use before any function or Methods or top of Coding line.

COMMAND + OPTION + /

If It is top of collectionView methods it will be like

// MARK: - CollectionView Methods

extension HomeViewController: UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {

/// Collection Views for Fetured, Popular, Categories
///
/// - Parameters:
///   - collectionView: Data to be provided by service. Collection Views are categoriesCollectionView, popularCollectionView, feturedCollectionView
///   - section: retturn Value from Service
/// - Returns: return Value from Service


func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return homeList.count
}
Anil
  • 272
  • 3
  • 14