IOS-Swift and Object-C Mixed Programming, ios-object-c

Source: Internet
Author: User

IOS-Swift and Object-C Mixed Programming, ios-object-c
1. preface facts prove that Swift cannot replace Object-C in a short time, and .... the Apple Swift development team said, "We'll recommend people start with Swift, sure, but ObjC isn' t going anywhere. our goal's to work with the platform, not reinvent. "Well, Apple's official attitude towards Swift and ObjC is very clear. Be prepared to learn two languages at the same time. the first thing we need to do is the mixed programming of the two languages. Today, let's get started with-2. swift calls Object-C Code 2. 1. create a Swift project 2. 2. create an Object-C class. Whether to create an ObjectOC bridge headerThen, select YES. Here we are sure to create the file, and then write a simple method 2. 3. Import the header file of the OC file in the bridge file.If the file is not imported, no prompt will be displayed in the Swift file and cannot be called.2. 4. create an object in the Swift file and run the sayhello method successfully. 3. object-C calls Swift code 3. 1. create an Object-C project 3. 2. if you create a Swift class, it will still show whether you need to create a header for the OC bridge. Then, select YES. Here we are sure to create 2. 3. bridge File

This is different from the OC call by Swift. Pay attention to the following:

This is required by Swift to call the OC language. Here we use OC to call the Swift language, so we do not need to import the Swift file in this bridge file._____________ Why? Because while creating it, xcode also creates a hidden file This hidden file is our benchmark for calling the Swift language by OC. So what is its name?  "Project name" + "-" + "Swift". hWe need to import this hidden file in the OC class, though we can't see it, but it actually exists. 2. 4. Create an object in the OC file and run Note: After the OC creates an object, --When a method is called, there is no prompt, or even an error is reported. If this method cannot be found, we don't have to worry about it. Running the command directly proves that the operation is successful, and the error message will disappear. For example, the sayhello method is successfully called. thank you. If you have any questions, please comment on them. I have time to reply! Author: Clear Saup
Source: http://www.cnblogs.com/qingche/
The copyright of this article is shared by the author and the blog. You are welcome to repost it, but you must keep this statement and provide a connection to the original article on the article page.

Related Article

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.