Operators in Objective C and Swift

Common for Objective C and Swift
  • Assignment Operator ( = )
  • Arithmetic Operator
    • addition +,
    • Subtraction -, 
    • Multiplication *,  
    • Division /
  • Remainder (Modulo) Operator %
  • Unary plus operator (+), Unary minus operator (-), unary operator is prepended directly on the value it operates on.
  • compound assignment/short hand operators (x+=y, x-=y, x*=y, x/=y, x%=y, x&=y, x|=y, x^=y)
  • Increment (++) & decrement operator (—) {int x=9, int y: y= ++x , y = - - x } (Removed in Swift 3)
  • Relational/Comparison operators 
    • Equal to (a == b)
    • Not equal to (a != b)
    • Greater than (a > b)
    • Less than (a < b)
    • Greater than or equal to (a >= b)
    • Less than or equal to (a <=  b)
  • Logical Operator 
    • Logical Not (!a)
    • Logical AND (a && b)
    • Logical OR (a || b)
  • Ternary Conditional Operator ( if condition? expression 1 : expression 2 )
Swift Only
  • Range Operator 
    • Closed Range Operator '1…10', includes 1 and 10 in this range.
    • Half Open Range Operator '1..~10 , includes 1 but not 10
  • Nil-Coalescing Operator (x??y)
The nil-coalescing operator (x ?? y) unwraps an optional x if it contains a value, or returns a default value y if x is nil. The expression a is always of an optional type. The expression y must match the type that is stored inside x.

The nil Coalescing operator is shorthand for the below code:

x != nil ? x! : y

The code above uses the ternary conditional operator and forced unwrapping (x!) to access the value wrapped inside a when x is not nil, and to return x otherwise. The nil-coalescing operator provides a more elegant way to encapsulate this conditional checking and unwrapping in a concise and readable form.

10 comments:

  1. Right,Good to see these helpful information here iPhone Apps Development Company.Thanks lots for sharing them with us.

    ReplyDelete
  2. Fabulous canvas..and thanks a lot for sharing these tips ,they are really helpful.keep it up I really enjoy the blog post.
    Technolgy, online reputation management,Business Information Blog

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Awesome article I really impress it’s very informative and useful.Thanks

    Custom Software Development Australia

    ReplyDelete

  5. I really like the dear information you offer in your articles. I’m able to bookmark your site and show to friends to checkout up here generally.-Sony mobile services in Ambattur

    http://apjsmartworks.com/sony-mobile-service-center-in-ambattur.html

    ReplyDelete
  6. If you want to become a professional IOS developer. you should learn IOS. By learning IOS you can able to create build views. You can handle user interaction via controls like buttons, switches, and sliders etc. We can also able to display data in a table view. You can create alert boxes, handle navigation and transition between views. You can also follow iOS Online Training Bangalore

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Shopclues here came up with an Offer where you can win special Shopclues Prize by just playing a game & win prizes Call @6299249427
    Shopclues Winner List 2019
    Shopclues Prize
    Prize Shopclues
    Shopclues Winner Name
    Shopclues Lucky Draw
    Shopclues Winner List

    ReplyDelete