Some small knowledge of IOS Swift (constantly replenished)

Source: Internet
Author: User

1. In the swift file is not able to write C language functions, not compatible with C, direct error. To invoke the C-language function, use the bridged functionality provided by the system, just as you would call OC in Swfit!

2. Swift 2.0 provides @convention (c) to convert Swift's closure function into a C language pointer. This feature is used in the following scenario,

In the C language file, we define a function:

cgfloat mycfunction (CGFloat (callback) (CGFloat x, cgfloat y)) {    return callback (1.1 2.2 );}

The callback function here is a C-language function pointer, which we can use in Swift:

Let Swiftcallback: @convention (c) (CGFloat, cgfloat)-cgfloat = {    in    return x += mycfunction (swiftcallback)

The following simplified methods are also available:

Let result = mycfunction ({    in    return x + y})

Some small knowledge of IOS Swift (constantly replenished)

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.