I declared the % token as a post-fixed operator to calculate the percentage, but Xcode reports
`% is not a postfix unary operator`
My test code below is based on an example found here . I also checked the latest Apple documentation for syntax for statement statement , but made it hard to understand why Xcode complains.
How to calculate percentage using % ? And suppose I am working, how would I then return to using % for operations with a module in another function in another place in the same class?
Can anyone suggest a working example based on my code in the Playground?
1.% means percentage
postfix operator % var percentage = 25% postfix func % (percentage: Int) -> Double { return (Double(percentage) / 100) }
2.% means balance
let number = 11 let divisor = 7 print(number % divisor)
source share