Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 397 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#pragma mark in Swift?

#11
Use

// MARK: SectionName

or

// MARK: - SectionName

This will give a line above pragma mark, making it more readable.

For ease just add

// MARK: - <#label#>


to your code snippets.


**Alternate way -**

Use it in this way

private typealias SectionName = ViewController
private extension SectionName {
// Your methods
}

This will not only add mark(just like pragma mark) but also segregate the code nicely.
Reply

#12
There are Three options to add `#pragma_mark` in Swift:

1) `// MARK: - your text here -`

2) `// TODO: - your text here -`

3) `// FIXME: - your text here -`

Note: Uses `-` for add separators
Reply

#13
You can use `// MARK:`

---

There has also been discussion that liberal use of class extensions might be a better practice anyway. Since extensions can implement protocols, you can e.g. put all of your table view delegate methods in an extension and group your code at a more semantic level than `#pragma mark` is capable of.
Reply

#14
You may also be interested in **Swift 4.2 / XCode 10** compiler directives like

#warning("Some string to display")

and

#error("Some error to display")

It might be useful when you really don't want to miss something.

[![enter image description here][1]][1]


[1]:
Reply

#15
> Add a to-do item: Insert a comment with the prefix TODO:. For
> example: // TODO: [your to-do item].
>
> Add a bug fix reminder: Insert a comment with the prefix FIXME:. For
> example: // FIXME: [your bug fix reminder].
>
> Add a heading: Insert a comment with the prefix MARK:. For example:
> // MARK: [your section heading].
>
> Add a separator line: To add a separator above an annotation, add a
> hyphen (-) before the comment portion of the annotation. For example:
> // MARK: - [your content]. To add a separator below an annotation, add
> a hyphen (-) after the comment portion of the annotation. For
> example: // MARK: [your content] -.
Reply

#16
Professional programer must be use this tag for good code.
It is also good for team work.

// MARK: example Web Service start here
// TODO: example 1
// FIXME: Please change BASE url before live

It is easy to find method like this

![It is easy to find method like this][1]


[1]:
Reply

#17
Try this:

// MARK: Reload TableView

func reloadTableView(){

tableView.reload()
}


Reply

#18
Pragma mark is a way to improve the readability of your code. The pragma comments would appear like tags on the Xcode jumpbar.


//MARK: <Your comment goes here>


Example: In the code,

//MARK: Properties

// MARK: View Life cycle

//MARK: Helper methods


This is how it would appear in the Xcode jump bar.




[![enter image description here][1]][1]


[1]:
Reply

#19
In Xcode 11 they added minimap which can be activated `Editor -> Minimap`.

Minimap will show each mark text for fast orientation in code.
Each mark is written like `// MARK: Variables`

[![enter image description here][1]][1]


[1]:
Reply

#20
`Pragma mark - [SOME TEXT HERE]` was used in *Objective-C to group several function together* by line separating.

In *Swift* you can achieve this using `MARK, TODO OR FIXME`

i. *MARK :* `//MARK: viewDidLoad`

This will create a *horizontal line* with functions grouped under viewDidLoad(shown in screenshot 1)

[![Screenshot 1][1]][1]

ii. *TODO :* `//TODO: - viewDidLoad`

This will group function under *TODO: - viewDidLoad* category (shown in screenshot 2)

[![Screenshot 2][2]][2]

iii. *FIXME :* `//FIXME - viewDidLoad`

This will group function under *FIXME: - viewDidLoad* category (shown in screenshot 3)

[![Screenshot 3][3]][3]

Check this [apple documentation][4] for details.


[1]:

[2]:

[3]:

[4]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through