Learning Swift from scratch (Day60)-Core Foundation framework

Source: Internet
Author: User

Learning Swift from scratch (Day60)-Core Foundation framework

The Core Foundation framework is a set of Apis developed by Apple from the Foundation framework. The programming interfaces are for C-language APIs. Although it is troublesome to call this C-language API in Swift, sometimes it is very convenient to use the API of CoreFoundation framework during OS X and iOS development, for example, when it is mixed with the C language.

The Core Foundation framework is closely related to the Foundation framework. They have the same interfaces but are different. The Core Foundation framework is based on the C language style, while the Foundation framework is based on the Objective-C language style. In OS X and iOS code, code in multiple language styles is often mixed, which makes development more troublesome.

Data Type ing

The Core Foundation framework provides some opaque data types that encapsulate some data and operations. They can also be called "classes". They all inherit from the CFType class, CFType is the root class of the Core Foundation framework type used. These data types correspond to corresponding data types in the Foundation framework. These data types also correspond to native Swift data types.

 

Let's take a look at the conversion example between the Swift native type and the Core Foundation type:

 

Import CoreFoundationimport Foundation var cfstr1: CFString = "Hello, World" // create a CFString var str: String = cfstr1 as String // convert the CFString String to the Swift native String var cfstr2: CFString = str // convert the Swift native String to the CFString String

 

In this conversion process, the Core Foundation type needs to be forcibly converted to the Swift native type.

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.