Swift Nested Calling

时间:2017-04-10 02:30:20

标签: swift3

class BFCommon {
    class BFUser {

    }

    extension BFUser {
        static func sayHello() {
            print("Hello")
        }
    }
}

BFCommon.BFUser.sayHello

Need help fixing my code to call a function like so.

BFCommon.BFUser.sayHello

1 个答案:

答案 0 :(得分:1)

Exactly as the error message suggests, extensions can only be declared at the file scope:

class BFCommon {
    class BFUser {}
}

extension BFCommon.BFUser {
    static func sayHello() {
        print("Hello")
    }
}

BFCommon.BFUser.sayHello()