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:
- Create a new OBJECTIVE-C project that is familiar to all the parents, Called:mixtureofocandswit;
- 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
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 "
- 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.
- 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