About Objective-c and Swift

Source: Internet
Author: User

Recently infatuated with Stanford's iOS public class, although English is not good, the back has not translated, I still bite the bullet to see several times, finally is finished, just want to say a word:amazing!! !

OK, say the matter, now do the project is done before the objective-c old project, is it not until Objective-c was completely eliminated I can really experience swift?

No,no,no!!! I don't want to DELAY, I want IT now! congratulations! CAN do IT:

In fact, iOS can now be mixed, and then let's talk about how to add swift to previous old projects, we'll test it first:

  1. Create a new OBJECTIVE-C project that is familiar to all the parents, Called:mixtureofocandswit;
  2. New class Person, but this person class must inherit from NSObject or its subclasses , or an error will occur ' use of undeclared identifier ' person ' ':
      Import Foundation  class   Person:nsobject {var name:string ?}  var age:uint ?   
    But when new, Xcode asks the pro to create a bridging file that will be configured when the SWIFT project imports the OC code, regardless of the
  3. Then in the new project Viewcontroller inside import, how to import it? There's no such thing as a header file in Swift! In fact, Xcode will automatically generate a header file based on your swift code, so what is the name of the header file?
    Since we are mixed here, the name of this auto-generated header file is dynamically changing but there is a rule: ' Xxx-swift.h ', in which XXX is your current project name, here, of course, 'mixtureofocandswit- Swift.h ', you can introduce this in your Viewcontroller:

    #import " mixtureofocandswit-swift.h "
  4. At this point you can introduce your swift code:
    -(void) viewdidload {    [super Viewdidload];         *person = [[Person alloc] init];    }

    But it's still an error, why? It's because I think I'm still in circles, and I'm done talking.

  5. The Target->build settings->packaging->define Module is set to Yes, then, Build IT, and you have GOT and do ...

About Objective-c and Swift

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.