Summary of common errors and warnings in development (13)
Mixed summary
Objective-c Calling Swift code
Objective-c calling Swift code two steps
The first step tells Xcode which classes need to be used (automatic processing of classes that inherit from NSObject, this step is not required), and the keyword @objc (className) to mark
1 Import UIKit 2 @objc (Ilwritebyswift) 3 class ilwritebyswift {4 var name:string! 5 class func newinstance (), ilwritebyswift {6 return ilwritebyswift ()7 }8 }
The second step introduces the header file, the Xcode header file naming rules for
1 $ (swift_module_name)-swift.h
Examples are as follows:
#import " ilswift-swift.h "
Tips
Unclear swift_module_name can be viewed through the following steps
Can't find $ (swift_module_name)-swift.h
1. If you encounter this problem, follow the steps below to perform a routine check
OK import swift_module_name)-swift.h header file name is correct
Swift_module_name)-swift.h was not rebuilt after clean, executed xcode->product->build
2. header file loop
In mixed programming projects, because of the simultaneous use of both languages, the following requirements often arise: in the case of the Swift project, a class objectvie-c write is required, and the Class A uses some of the functions of Swift, the loop of the header file, which causes the compiler not to properly build the $ (swift_ module_name)-swift.h, when you encounter this problem, do the following with the. h file
// Delete the following header file // #import "Ilswift-swift.h" // importing classes through code @class Ilswiftbean;
At the top of the objevtive-c. m file, add
#import " ilswift-swift.h "
The use of undecalared identifier error appears or the method is not found, as follows:
There are several possible reasons for this:
The Swift class used is not inherited from NSObject, and the keyword can be added
Swift_module_name)-swift.h No real-time updates, xcode->product->build
This swift file uses a type or syntax that is not supported by OBJECTIVE-C, such as private
There are some problems not found in the method, Xcode no Smart tip:
The type of conversion not supported by Apple's official
Generics
Tuples
Enumerations defined in Swift
Structures defined in Swift
Top-level functions defined in Swift
Global variables defined in Swift
Typealiases defined in Swift
Swift-style Variadics
Nested types
Curried functions
iOS Development--Error summary & common errors and warnings in development summary (13)