Equivalent of or alternative to CGPathApply in Swift?

后端 未结 4 1044
情深已故
情深已故 2020-12-03 03:42

In the pre-release documentation there appears to be no Swift version of CGPathApply. Is there an equivalent or alternative? I\'m trying to get all subpaths of a CGPath so t

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 04:02

    Dmitry Rodionov has produced a function for converting a Swift function to a CFunctionPointer (see https://github.com/rodionovd/SWRoute/wiki/Function-hooking-in-Swift).

    #define kObjectFieldOffset sizeof(uintptr_t)
    
    struct swift_func_object {
        uintptr_t *original_type_ptr;
    #if defined(__x86_64__)
        uintptr_t *unknown0;
    #else
        uintptr_t *unknown0, *unknown1;
    #endif
        uintptr_t function_address;
        uintptr_t *self;
    };
    
    
    uintptr_t _rd_get_func_impl(void *func)
    {
        struct swift_func_object *obj = (struct swift_func_object *)*(uintptr_t *)(func + kObjectFieldOffset);
        
        //printf("-->Address of C-Func %lx unk=%lx ori=%lx<--\n", obj->function_address, obj->unknown0, obj->original_type_ptr);
        return obj->function_address;
    }

    I am using this successfully with CGPathApply along with a Swift callback function. (code at http://parker-liddle.org/CGPathApply/CGPathApply.zip) Although as Dmitry says this is a reverse engineered function and not a supported one.

提交回复
热议问题