iOS Development questions: How do I introduce a head file in Swift?

Source: Internet
Author: User

Recently in learning iOS development, from a simple login, gradually resolved a network access, access control values and other issues, encountered the problem of information encryption.

As an entry point for iOS, there are several issues that need to be addressed by encrypting information:

1, iOS MD5 encryption there is no fixed function, how to use this function.

After checking the data, there are built-in functions in the OBJECT-C

2, how to introduce the function of object-c

First add the header file, on the Xode 7 project right-new file-"ios-" source-"headfile-> next set name, can be arbitrarily named, add the following code in HEAD.H:

#import <CommonCrypto/CommonDigest.h>

3, how to introduce the head file into the project

In Code7, click on the project root directory, select "Build Settings", select "All", search Swift will find "Swift Compiler–code Generation", in "objective-c bridging Header "Input" Projectname/projectname-bridging-header.h "is the head file just added.

After the head introduction is complete, expand the MD5 function and add the following code to any swift:

Stringmd5.swiftextension String {     var md5:string {let        cString = self.cstringusingencoding ( nsutf8stringencoding) Let        length = Cunsignedint (                self.lengthofbytesusingencoding (nsutf8stringencoding)            )        Let result = Unsafemutablepointer<cunsignedchar>.alloc (                        Int (cc_md5_digest_length)                     )        cc_md5 ( cstring!, length, result)        return String (format:            "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%0 2x%02x%02x ",            result[0], result[1], result[2], result[3],            result[4], result[5], result[6], result[7],            RESULT[8], result[9], result[10], result[11],            result[12], result[13], result[14], result[15])    }}

The above code found on the Internet "http://www.cocoachina.com/bbs/read.php?tid-290038.html"

You can use MD5 encryption.

print(poststring. MD5);

iOS Development questions: How do I introduce a head file in 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.