简体   繁体   中英

Not able to extend an Objective-C class in Swift

I am using Swift 3.0 on Xcode 8.0 beta. I have installed a library using pods (FMDB) and now I am trying to extend one of its class in swift. I am able to use the API from my extended class but it crashes at runtime.

-[FMResultSet polygonsForColumnIndex:]: unrecognized selector sent to instance 0x608000056890

Below is the code for the extension:

public extension FMResultSet {

    public func polygons(forColumnIndex index: Int32) -> [NMAMapPolygon] {

It crashes here when called:

let rs = db.executeQuery("select AsGeoJSON(geometry) from COM262_Project", withArgumentsIn: nil)
        while (rs?.next())! {

            //Crashes here!
            let polygons = rs?.polygons(forColumnIndex: 0)    
        }

Note : Extensions work for other libraries like Alamofire.

Have you tried setting the function as @objc eg

public extension FMResultSet {
    @objc public func polygons(forColumnIndex index: Int32) -> [NMAMapPolygon] {

On top of that have you changed the build setting Enable Modules to Yes .. Or if your using a config file CLANG_ENABLE_MODULES = YES

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM