Reputation: 151
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.
Upvotes: 5
Views: 2551
Reputation: 828
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.
Upvotes: 6
Reputation: 875
Create a Bridging Header
Upvotes: 4