The mixing of OC and Swift

Source: Internet
Author: User

Reference: http://blog.sina.com.cn/s/blog_8d1bc23f0102v5tl.html

Methods of using the OC class in Swift

1. Create a oc.h file

2. Add the header file for the OC class that needs to be poured

3.Bulid Settings Search Bri, added: $ (srcroot)/$ (target_name)/oc.h

4. Testing

Test.h

#import<Foundation/Foundation.h>

@interfaceTest:nsobject

- (void) test;

@end

Test.m

#import "Test.h"

@implementationTest

- (void) Test {
NSLog (@"This is a test");
}

@end

Viewcontroller.swift

Import UIKit

classViewcontroller:uiviewcontroller {

OverrideFunc Viewdidload () {
Super.viewdidload ()

var test:test?//Statement
Test = Test ()//Initialize
Test?. Test ()//Calling Methods
}

OverrideFunc didreceivememorywarning () {
Super.didreceivememorywarning ()
//Dispose of any resources the can be recreated.
}

}

Printing information:

The mixing of OC and Swift

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.