Difference between @objc before class and @objc (class_name) over class in swift?

What is the difference between:

@objc class MyClass: NSObject{}

and

@objc(MyClass)
class MyClass: NSObject{}
+4
source share
2 answers

The modifier is @objcdeprecated in Swift 2. All classes that have been marked as @objcmust be a subclass NSObject, which makes the modifier @objcredundant.

@objc(xxx)however, it is used to determine the alternate name for the class (for use at run time and from Objective-C code).

This modifier is only useful if you want to use a different name in your execution code / Objective C.

, . , class X: NSObject {} @objc(MyModule.X) .

+3

. .

@objc(SomeOtherName), , Objective-C , SomeOtherName Swift ( Objective-C).

0

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


All Articles