Mr. SS
Mr. SS

Reputation: 387

Is there any shortcut for // MARK: in Xcode like there is for /// <#Description#>?

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

Upvotes: 16

Views: 9804

Answers (4)

m_2
m_2

Reputation: 1

With SwiftUI, creating a code snippet changes by just selecting the MARK line // MARK: <#Description#> and right click the selection, choosing "Create Code Snippet..."

Selecting and Right Click

It will open a prompt to create the snippet just like the accepted answer from @Ahmad F

Prompt to Create Snippet

The usage is the same, just type mark.

Upvotes: 0

Anil
Anil

Reputation: 272

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
}

Upvotes: 6

Ahmad F
Ahmad F

Reputation: 31655

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

Upvotes: 39

Zarif Ahmed
Zarif Ahmed

Reputation: 361

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

Upvotes: 6

Related Questions