How can you determine if a Swift class inherits from another class or is protocol compliant?

For example, if we have a class Foothat inherits from the class Barand conforms to the protocol Baz:

class Bar {}

protocol Baz {}

class Foo: Bar, Baz {}

What to do if we do not know in advance what Baris a class, but Bazis a protocol (for example, when reading another user's code). In this case, this may be clear due to the presence of several announcements after class Foo:. In Swift, a protocol conformance expression should appear after the superclass is declared in the inheritance clause. On the other hand, it can also be a class without inheritance that conforms to several protocols.

And what if there is only one declaration in the inheritance clause?

class Foo: Bar {}

Or:

class Foo: Baz {}

Objective-C, , . Swift . ?

+4
1

Swift , . , .

, . .

:

, Protocol Class , . :

classprotocol

, , Xcode.

+4

Source: https://habr.com/ru/post/1547175/


All Articles