gunw avatar

[Grammer] 26 - Custom Operators

gunw

Published: 25 Jan 2019 › Updated: 25 Jan 2019[Grammer] 26 - Custom Operators

[Grammer] 26 - Custom Operators

  • Custom Operators : prefix, postfix, infix 중 하나를 커스텀
infix operator *+* : MultiplicationPrecedence // 우선순위 그룹 설정
extension Int {
   static func *+*(left: Int, right: Int) -> Int {
      return (left * right) + (left * right)
   }
}
1 *+* 2 + 3 // 7
  • precedencegroup custom
precedencegroup MyPrecedence {
   higherThan: AdditionPrecedence
}
infix operator *+* : MyPrecedence // 우선순위 그룹 설정
extension Int {
   static func *+*(left: Int, right: Int) -> Int {
      return (left * right) + (left * right)
   }
}

1 *+* 2 + 3 // 7

Leave [Grammer] 26 - Custom Operators to:

Written by

User

Read more #swift4 posts


Best Posts From gunw

We have not curated any of gunw's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From gunw