Reputation: 5702
Any method call to instantiate a CFSocket seem to be missing from the import CoreFoundation
import CoreFoundation
var socket:CFSocket = CFSocket()
The reference documentation doesn't show anything when swift only is selected:
Creating Sockets
4 Objective-C symbols hidden
How can I instantiate a CFSocket under Swift?
Upvotes: 4
Views: 2223
Reputation: 1
replace callout with closure like below:
let socket = CFSocketCreate(kCFAllocatorDefault,
PF_INET,
SOCK_STREAM,
IPPROTO_TCP,
2,
{ (socket,_,_,_,_) in },
nil)
Upvotes: 0
Reputation: 750
i had the same Problem. It is a CF struct not an Object so you have no a constructor.
You can use CFSocketCreate
.
Some think like this:
let socket : CFSocket = CFSocketCreate(_ allocator: CFAllocator!,
_ protocolFamily: Int32,
_ socketType: Int32,
_ `protocol`: Int32,
_ callBackTypes: CFOptionFlags,
_ callout: CFSocketCallBack,
_ context: UnsafePointer<CFSocketContext>)
Upvotes: 1