Although when Apple unveiled Swift for the first time, they said Swift is "Objective-C without C", C language is a treasure in the programming world. There are countless C libraries to help us simplify our work. Even in the iOS system, there are some built-in libraries, such as the libz.dylib for archiving files, or libxml.dylib for parsing xml.

Since Objective-C is a superset of C, we could use all C content seamlessly in Objective-C by introducing proper dependency and header files. However, a main target of Swift is casting off the historical burdens. It is impossible for us to use C code or C library in Swift directly. Take an example, if we want to calculate MD5 of a string, in Objective-C, we just use CC_MD5 method in CommonCrypto, which is a pure C library. In Swift, we cannot import it, and since the library is not mapped to Swift module, the fastest way to do it might be using a bridging file. We can write C code and import C libraries in the {product-module-name}-Bridging-Header.h file, which allows us to invoke Objective-C methods. By importing CommonCrypto.h and using an extension, we can solve the MD5 calculation:

// TargetName-Bridging-Header.h
#import <CommonCrypto/CommonCrypto.h>

// StringMD5.swift
extension 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%02x%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])
    }
}

// Test
print("swifter.tips".MD5)

// Output
// dff88de99ff03d109de22fed4f71a273

Of course, if you are really care about your project and prefer to pure Swift instead of touching C, you can attempt to create your own Swift version of these code. Similar as CommonCrypto in C, you can already find a pure Swift implementation here. But I suggest using the stable C libraries for some time. Swift is still quite young now, the best practice of how to make dependency or use other's code is not determined yet. Besides of that, you can also save your app size by using a dynamic library.