iOS development--The call of functional &swift and Object-c

Source: Internet
Author: User

In Swift, the #import OC file is available in the bridge header file, and the entire Swift project can use the OC files, and the methods exposed in. h can be used by the project//oc file TestOC.h
1 #import2 3  4 5 @interfaceTestoc:nsobject6 7  8 9- (void) SayHello;Ten  One- (void) Saywhat: (NSString *) name Andage: (NSString *) age; A  -+ (void) Sayhellotwo; -  the   -  - @end

Testoc.m
1 #import "TestOC.h"2 3  4 5 @implementationTestoc6 7- (void) SayHello8 9 {Ten  OneNSLog (@"Hello to you"); A  - } -  the   -  -- (void) Saywhat: (NSString *) name Andage: (NSString *) Age -  + { -  +NSLog (@"%@,%@", name,age); A  at } -  -   -  -+ (void) Sayhellotwo -  in { -  toNSLog (@"I want to make friend with you"); +  -   the  * } $ Panax Notoginseng   -  the @end

Bridge header File

#import "TestOC.h"

Swift file

Methods for calling OC files

1 Let he = Testoc ()23        He.sayhello ()45  6  7         he.saywhat ("achao", Andage:" " )89 testoc.sayhellotwo ()

It is clear that when calling OC's multi-parameter function in Swift, the first part of the function becomes the name of the Swift function before the parentheses, and then the first parameter of the function does not have a name, and the rest of the function seats the parameter name of the SWIFT function, which is the label

Calling a class method is directly a class name using point syntax calls, calling a multi-parameter class function, and so on

iOS development--The call of functional &swift and Object-c

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.