#pragma mark in Swift?
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.
What is the equivalent of #pragma mark - in swift?
Use something like that:
// MARK: - UITableViewDataSource
Or use extensions
: I love the way how UITableViewDataSource
delegate is implemented in this answer
Swift: Understanding // MARK
The // MARK:
and // MARK: -
syntax in Swift functions identically to the #pragma mark
and #pragma mark -
syntax in Objective-C.
When using this syntax (plus // TODO:
and // FIXME:
), you can get some extra information to show up in the quick jump bar.
Consider these few lines of source code:
// MARK: A mark comment lives here.
func isPrime(_ value: UInt) -> Bool { return true }
And for reference, the quick jump bar is at the top in Xcode:
It exists mostly to help with quick navigation within the file.
Note that the dash (// MARK: -
) causes a nice separation line to show up. Consider this MARK
comment:
// MARK: - A mark comment lives here.
The darker gray separator line just above the bolded option in that menu comes from the dash.
Additionally, we can achieve this separator line without a comment by simply not having any text after the dash:
// MARK: -
As mentioned, // TODO:
and // FIXME:
comments will also appear here.
// MARK: - Prime functions
func isPrime(_ value: UInt) -> Bool {
// TODO: Actually implement the logic for this method
return true
}
func nthPrime(_ value: UInt) -> Int {
// FIXME: Returns incorrect values for some arguments
return 2
}
- FIXMEs get a little band-aid icon that help them standout.
- MARK icon looks like a table of contents
- TODO icons look more like a checklist
Clicking on any line in the quick jump bar takes you directly to that line in the source code.
Is it Possible MARK: (#pragma mark) in Localizable.string file
Yes, it's possible.
You're missing a few required semi-colons. I guess it is used for string-termination or similar under the hood...
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html
Is it possible to have a #pragma mark hierarchy?
Simply only use the -
before and after your main section to surround it in lines, exclude the dash for the subsections, and then the method names will show as always.
#pragma mark - Public Methods -
#pragma mark Helper Methods
- (void)aMethod{}
#pragma mark Other Type of Methods
- (void)anotherMethod{}
#pragma mark - Private Methods -
#pragma mark Some Type of Method
- (void)aPrivateMethod{}
Related Topics
Swift 3 Incorrect String Interpolation With Implicitly Unwrapped Optionals
Nsobject Subclass in Swift: Hash VS Hashvalue, Isequal VS ==
Is Key-Value Observation (Kvo) Available in Swift
Why Is Swift Compile Time So Slow
What Is the "Some" Keyword in Swift(Ui)
Checking If an Object Is a Given Type in Swift
Choosing Coredata Entities from Form Picker
Firebase Getting Data in Order
Nsfilemanager Fileexistsatpath:Isdirectory and Swift
Extensions in My Own Custom Class
How to Convert Data to Hex String in Swift
Swift 2 - Unsafemutablepointer≪Void≫ to Object
Xcode 8 Beta 3 Use Legacy Swift Issue
What Is the 'Open' Keyword in Swift
How to Change the Textual Representation Displayed For a Type in Swift
Does Swift Have Documentation Generation Support
Lidar and Realitykit - Capture a Real World Texture For a Scanned Model