Swift Method Conventions in Natural Language Sentences

Asked 2 months ago, Updated 2 months ago, 1 views

When describing a method name in a natural language sentence, I think I wrote it like + [Foo bar] or - [Foo baz:qux:] in Objective-C, but how do you usually write it in Swift?

swift

2022-09-30 14:15

3 Answers

For Ruby, the instance method is written with a connection of "#" like Range#each, and the class method is written with a connection of "." like Range.new.Are there any standardized conventions for writing documents or books like this?

In Objective-C, it has been customary to distinguish between "+" and "-" such as +[Foobar] and -[Foobaz:qux:], or to write -objectsForKeys:notFoundMarker: if the receiver is clear in context.

I don't think Swift has been decided yet.

If I have to say anything, I think there are many books and sites that follow Apple's documentation and write drawRect(_:).

There are no conventions like Ruby that distinguish class methods from instance methods (or static methods), and many of them simply write dots like Array.append(_:) without distinction.


2022-09-30 14:15

Although not Swift, Java is officially documented as ClassName.methodName().Argument lists to distinguish overloads may include only type names, such as ClassName.methodName(Type1,Type2,...), or parameter names, such as ClassName.methodName(Type1arg1,Type2arg2,...).There is no notation to distinguish between static methods (class methods) and nonstatic methods (instance methods).

In comments in Javadoc format, ClassName#methodName(), but in documents that are printed as a result of processing by the document generator, # is replaced with ..
個人 In most cases, ClassName#methodName() is written in personal blog posts, but it is probably using the description in Javadoc as it is (wrongly).

C# is also in the form ClassName.MethodName().

C++ is in the form of ClassName::MemberFuncName() using the scope resolution operator :.It also appears frequently in the specification.


2022-09-30 14:15

I myself have never mentioned this in the Natural Language Sentence, but in the stack trace that the questioner mentioned, it is displayed in the Swift environment as shown in the picture below.

Enter a description of the image here

Class methods appear to be distinguished from instance methods in static, as described in static Hoge.fuga()->().


2022-09-30 14:15

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.