I want to use C libraries such as stdio.h, stdlib.h, etc. in my swift application. But I can't import . How can I do?
import <stdio.h> // BAD
#include <stdio.h> // BAD
#import <stdio.h> // BAD
import Foundation // cannot use printf etc.
To import C functions in pure Swift on the OS-X platform use:
import Darwin
This can be seen as one of the sub-imports inside Foundation.swift, but importing it individually avoids potentially unnecessary processing of Cocoa and other iOS/OSX framework modules.
NeilJaff's answer works because it causes Foundation and all submodules to be imported, but import Darwin
is more targeted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With