在Swift Xcode 7.2.1中使用未解析的标识符'kCFStreamEventHasBytesAvailable'

时间:2016-05-09 18:10:00

标签: swift sockets network-programming xcode7.2

我在Swift中编写Socket编程。对于所有CoreFoundation常量,我收到错误:

  

使用未解析的标识符

  1. 我已导入CoreFoundation

    import Foundation
    import CoreFoundation
    import CFNetwork
    
  2. 添加了corefoundation框架

  3. 尝试了Bridging标题
  4. 但以上都没有解决错误。

    添加代码

    import Cocoa
    import Foundation
    import CoreFoundation
    import CFNetwork
    
    class ViewController: NSViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
    
    
        // Do any additional setup after loading the view.
         CFSocketCreate(nil,             // Default allocator
            PF_INET,             // Protocol Family
            SOCK_STREAM,             // Socket Type
            IPPROTO_TCP,             // Protocol
            kCFSocketConnectCallBack,             // Callback flags
            (MyCFSocketCallback as! CFSocketCallBack),             // Callback method
            nil)
    
    }
    
    func MyCFSocketCallback(sref: CFSocketRef!, type: CFSocketCallBackType, inAddress: CFDataRef!, pData: UnsafePointer<Void>, pInfo: UnsafeMutablePointer<Void>) {
    
        switch type {
        case kCFSocketConnectCallBack:
    
            NSLog("Strem Event Open Completed")
            break;
        case kCFSocketAcceptCallBack:
    
            NSLog("Accept ")
            break;
    
        default:
            NSLog("received unexpected CFReadStream callback, CFStreamEventType")
        }
    
    }
    

    Code Snippet的截屏:
    Screen shot of Code Snippet

0 个答案:

没有答案