iOS Development--Error summary & common errors and warnings in development summary (13)

Source: Internet
Author: User

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:

    • This method uses a type or syntax that is not supported by objective-c

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.