Swift 4.0中'>>>-'运算符是什么?为何Xcode报未解析错误?
>>>- Operator Error in Swift 4.0 Hey there! Let's unpack what's going on with this mysterious >>>- operator you've run into.
First: This isn't a standard Swift operator
Swift 4.0 (and all subsequent versions of Swift) does not include >>>- as part of its standard library. That's why Xcode is throwing the "Use of unresolved operator '>>>-'" error — the compiler has no idea what this operator is supposed to do because it's not built into the language.
So why did you see it in source code?
Chances are, >>>- is a custom operator defined somewhere in the codebase you're looking at. Swift gives developers full control to create their own operators for specific use cases — here are some common scenarios where custom operators pop up:
- Functional programming patterns (like chaining operations or handling monadic types)
- Domain-specific logic (simplifying repeated, project-specific tasks)
- Wrappers for asynchronous operations or state management
To confirm this, try searching the entire codebase for the operator's definition. You'll likely find something like this somewhere:
// Example of a custom infix operator definition infix operator >>>-: AssignmentPrecedence // The actual implementation of what the operator does func >>>-<T, U>(lhs: T, rhs: (T) -> U) -> U { // Custom logic here, e.g., transforming lhs with rhs function return rhs(lhs) }
Why the error happens?
The error pops up because:
- The file where you're using
>>>-hasn't imported the module or source file that defines the operator, OR - The code that defines
>>>-isn't included in your project's build target (so the compiler never sees it)
How to fix it?
- Locate the operator's definition in the source code (search for
operator >>>-) - Make sure the file containing the definition is added to your project's build phases
- If it's part of a separate module, add an
import [ModuleName]statement at the top of the file where you're using the operator
内容的提问来源于stack exchange,提问作者Wimal Weerawansa

