Use custom operator in another file

I have a new statement ?=:

    infix operator ?= {}
    func ?=<T>(inout lhs: T?, rhs: T) {
        if lhs == nil {
            lhs = rhs
        }
    }

It is declared in some utils.swiftfile, in the global scope of this file. Then I try to use the just created statement in some class function inside another file:

imageView.image ?= avatarDefault

Basically, I want to install avatarDefaultin imageView.imageonly if it is currently nil...
This causes a compilation error:Operator is not a known binary operator

When I try to declare it again in the same file ( infix operator ?= {}), but still saving another declaration and funcin utils.swift- it compiles and works ...

My question is: why can't I declare a statement in a file (i.e. utils.swift) and then use it throughout the application?

+4
1

, , utils.swift utils. , Project Build Phases utils.swift Compile Sources

0

All Articles