Thursday, January 09, 2020

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators:


  • Closed Range operators 
  • Half-Open Range Operators
  • One-Sided Ranges

Closed Range Operators: 


  • a...b
  • It defines a range starting from a to b. 
  • it includes the values of  a and b
  • value a must not be greather than b

Usage:  for index in 1...5

Half-Open Range Operators: 

  • a..
  • It defines a range starting from a to b. 
  • But it does not include b
  • It is very useful, when working with the arrays. Reason it starts from 0 to count
   Usage: for index in 0..

One Sided Range operators 

Usage
   for name in namesArray[2...] {} it returns index 2 from till the end of array.
   for name in namesArray[...2] {} it returns index 0 from index 2. 
 
Example
let myRange = ...5 
range.contains(4) ==> true 
range.contains(11) ==> false 
range.contains(-4) ==> true

Logical Operators: check my previous blog post 

Swift Opertors - Basic Part 2

Comparision Operator

  • Equal To (==)
  • Not Equal (!=)
  • Less than (<)
  • Greater than (>)
  • Less than or Equal to (<=)
  • Greater than or Equal to (>=)
It reruns either true or false, it is used in if conditional statements.

Tubles comparision:  

                 Left to right comparision, if first element same as second then only it goes for second element comparision.

Ternary Conditional Operator:

  • Question ? answer1: answer 2
  • Example answer = 2 < 5 ? true: false

Nil Coalescing Operator: (??)

  • a ?? b
  • It unwraps an optional a if it contains a value, or returns a default value bif a is nil.
  • a is an optional type here
  • b must  match with the type that is stored inside a.





Swift Operators - Basic Part 1

Assignment Operators

  • It initialize or updates the value of a variable with the value of b (a=b)
  • It also supports tuples ((x,y) = (1,2) x -1 and y-2)
  • If x= y {} this is invalid, reason it does not return anything, it just assigns. 

Arithmatic Operators

  • Addition (+)
  • Subtraction (-)
  • Multipication (*)
  • Divisions(/)

Reminder (Modulas) Operator (%) 

  • 7 % 3 = 1  (3*2)+1 = 7 
  • a % b means (b * multipier) + reminder = a 

Unary Minus and Unary Plus:

  •   - a or + a
     Example: a = 3, then -a = -3 and +a = -3
                    +a does not change anything

Compound Assignment opertors

  • It combines assignment operator with another operations.
          Example a += 2 => a = a+2

Swift Operators - Terminology

Terminology

  • Unary Operators: 

    • It operates on a single target.
    • It appears immediately before their target or post their target
                  Example: -a , !a, a!

  • Binary Operators:

    • It operates on two targets
    • It appears in between two targets.
               Example: 2+4, 9*5

  • Ternary Operators

    • It operates on three targets
    • In Swift, it has only one ternary operator.
                   Example:  a ? b: c







Tuesday, July 02, 2019

Bitwise operators - simple explonation

Bitwise operators

1. AND (&)

2. OR (|)

3. X-OR (^)

4. Compliment (~)

5. Shift Left (<<)

6. Shift Right (>>)


AND &:

If both binary digit is 1, then output of "bitwise and" (&) will be 1

Example 1

Bit Operation of 10 and 15

Decimal       Binary

10                 0000 1010

25                 0001 1001
------------------------------
8                  0000 1000

********************************

Example 2:

Bit Operation of 20 and 21

20                 0001 0100

21                 0001 0101
------------------------------
16                 0001 0100

*********************************

OR | :

If either one of binary digit is 1, then output of "bitwise OR" (|) will be 1

Example 1

Bit Operation of 10 OR 15

Decimal       Binary

10                 0000 1010

25                 0001 1001
------------------------------
27                 0001 1011

********************************

Example 2:

Bit Operation of 20 OR 21

20                 0001 0100

21                 0001 0101
------------------------------
21                 0001 0101

*********************************

XOR ^ :

If the digit or opposite, then output of "bitwise XOR" (^) will be 1

Example 1

Bit Operation of 10 OR 15

Decimal       Binary

10                 0000 1010

25                 0001 1001
------------------------------
19                 0001 0011

********************************

Example 2:

Bit Operation of 20 OR 21

20                 0001 0100

21                 0001 0101
------------------------------
1                  0000 0001

*********************************

Wednesday, March 30, 2016

Frame and Bounds in IOS


The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0). 

The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

Now, imagine a view that has a size of 100x100 (width x height) positioned at 25,25 (x,y) of its superview. The following code prints out this view's bounds and frame:

// This method is in the view controller of the superview
- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"bounds.origin.x: %f", label.bounds.origin.x);
    NSLog(@"bounds.origin.y: %f", label.bounds.origin.y);
    NSLog(@"bounds.size.width: %f", label.bounds.size.width);
    NSLog(@"bounds.size.height: %f", label.bounds.size.height);

    NSLog(@"frame.origin.x: %f", label.frame.origin.x);
    NSLog(@"frame.origin.y: %f", label.frame.origin.y);
    NSLog(@"frame.size.width: %f", label.frame.size.width);
    NSLog(@"frame.size.height: %f", label.frame.size.height);
}


And the output of this code is:
bounds.origin.x: 0
bounds.origin.y: 0
bounds.size.width: 100
bounds.size.height: 100

frame.origin.x: 25
frame.origin.y: 25
frame.size.width: 100
frame.size.height: 100

Reference:
http://stackoverflow.com/questions/1210047/cocoa-whats-the-difference-between-the-frame-and-the-bounds




Friday, June 12, 2015

A open source tool to detect bugs in Android and iOS apps before they ship - infer

A open source tool to detect bugs in Android and iOS apps before they ship - infer


What is Infer?

Infer is a static analysis tool - if you give Infer some Objective-C, Java, or C code, it produces a list of potential bugs.
Anyone can use Infer to intercept critical bugs before they have shipped to people's phones, and help prevent crashes or poor performance.

Features

Android and Java

Infer reports null pointer exceptions and resource leaks in Android and Java code.

iOS

In addition to this, it reports memory leak problems in iOS and C code.

Using Infer

Start with the Getting Started guide and our other docs to download and try Infer yourself.

If you are mistakenly took engineering course, then watch and enjoy this shortfilm :) he he he

Loading the player...

Testiku padikalla - Tamil comedy short film by engineering students. - Shortfundly

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...