Swift function defined in MySwift.swift
File:
func SomeSwift()
{
}
SomeSwift()
is not defined in any Swift class, it is just a pure function.
After CMD + B to build the project, open Project-Swift.h
, the SomeSwift()
isn't show in there.
Does the function in Swift have to be defined in some Swift class? and with @objc
marked?
like the following:
@objc class SomeSwift: NSObject {
func SomeSwift()
{
}
}
Referring to Apple Documentation about Using Swift from Objective-C:
Means that your class should be
@objc class SomeSwift: NSObject
(You're right!), but you CANNOT access the whole thing in Swift file:Reference.
So, you cannot use the
SomeSwift
top-level function.Even if you tried to add
@objc
before its declaration, the compiler will tell that:with a suggestion to remove
@objc
.