1

I’m trying to forward Ensembles logging to my logger class. But I'm getting EXC_BAD_ACCESS on first call to CDELog

code for setting CDESetLogCallback :

    lazy var opaquePointerLogFunc : COpaquePointer = {
                let mutablePointer = UnsafeMutablePointer<(String,CVarArgType...) -> Void>.alloc(1)
                mutablePointer.initialize(myLog)
                let opaquePointer = COpaquePointer(mutablePointer)
                return opaquePointer
            }()


    func myLog(message:String, args : CVarArgType ...){
            println(__FUNCTION__)
            //never gets called
        }

    CDESetLogCallback(self.opaquePointerLogFunc)
bytecode77
  • 14,163
  • 30
  • 110
  • 141
CryingHippo
  • 5,026
  • 1
  • 28
  • 32
  • This isn't really an Ensembles problem as such, more a Swift-to-Objective-C issue. I don't have much experience with passing Swift funcs to Objective-C, but have you simply tried passing the function name, rather than generating a pointer type? Actually, looking closer, it seems you are trying to pass a method, not a function. I think you will need a func outside the class to make this work. – Drew McCormack Aug 10 '15 at 07:38
  • Thanks for the comment. Seems like it's not possible with Swift 1.2. I ended up writing ObjC wrapper. – CryingHippo Aug 10 '15 at 09:23

0 Answers0