• Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • #Deals
  • #News
  • #WiKi
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
IOS, Swift

How Swift Programming language is similar and different from Objective-C

Similarities to Objective-C

  • Basic numeric types (Int, UInt, Float, Double)
  • Most C operators are carried over to Swift, but there are some new operators
  • Curly braces are used to group statements.
  • Variables are assigned using an equals sign, but compared using two consecutive equals signs. A new identity operator, ===, is provided to check if two data elements refer to the same object.
  • Square brackets are used with arrays, both to declare them and to get a value at a given index in one of them.
  • Control statements, for, while, if, switch are similar, but have extended functionality, e.g. a for in that iterates over any collection type, a switch that takes non-integer cases, etc.
  • Class methods are inherited, just like instance methods; self in class methods is the class the method was called on.

Differences from Objective-C

  • Statements do not need to end with a semicolon (‘;’), though they may be used to allow more than one statement on a line
  • Header files are not required
  • Comments of the form /* … */ can be nested, allowing blocks of code to be easily commented out.
  • Strong typing
  • Type inference
  • Generic programming
  • Functions are first-class objects.
  • Operators can be redefined for classes (operator overloading), and new operators can be created.
  • Strings fully support Unicode. Most, but not all, Unicode characters can be used in Swift language names.
  • Several notoriously error-prone behaviors of C-family languages have been changed:
  • No pointers exist. There is no need for the programmer to keep track of and mark names for referencing or de-referencing.
  • Assignments do not return a value. Thus the common mistake of writing if (i=0) when if (i==0) is meant will cause a compile-time error.
  • No need to use break statements in switch blocks. Individual cases do not fall through to the next case unless the fallthrough statement is used.
  • Variables and constants are always initialized and array bounds are always checked.
  • Overflows, which are undefined behaviors for signed integers in C, are trapped as a run-time error, but programmers can choose to allow overflows by using the special arithmetical operators &+, &-, &*, &/ and &%. Properties min and max are defined in Swift for all integer types and can be used to safely check for potential overflows, as contrasted with relying on constants defined for each type in external libraries.
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 1229 Views
AUTHOR
Ranjan

I m Ranjan and Sharing my years of experience in Software Development. Love to code in Mobile apps (IOS, Android, Power Apps, Xamarin, Flutter), Machine Learning ( Beginner ), Dot Net, Databases ( SQL Server, MySql, SQLite), WordPress, Cloud Computing ( AWS, Azure, Google, MongoDB) and many more as required on project-specific. Besides this love to travel and cook.

Next Post
Previous Post

Subscribe for updates

Join 6,873 other subscribers

whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

Latest Posts

  • Frameworks of IOS
    Frameworks of IOS – Part ( I )
  • NSFileManager or NSPathUtilities
    NSFileManager or NSPathUtilities in Objective-C
  • Passing data between view controllers in Objective-C
    Passing data between view controllers in Objective-C
  • structures-classes-enum
    Structures and Classes in swift !
  • control-system-swift
    Control Flow in Swift
  • swift-concurrency-await
    Concurrency in Swift
  • time-complexity-dsa
    The Term Time Complexity in DSA
  • objective-c-datatypes1
    Objective-C Data Types
  • Convert-jpeg-word
    Convert JPG to Word – Tips You Should Try!
  • objective-c-control-statements2
    Objective-C control statements and loops !

Quick Links

  • #about
  • #myapps
  • #contact
  • #privacy

Other Websites

  • #myQuestions
  • #myBhojanalaya
  • #gadgetFacts
  • #ifscCodesDB

Tag Cloud

Android Android Studio API APP Programming Apps AS400 blogging Browser C# Code Config CSS DATABASE error Features HTML HTML5 IDE installation Interview Questions IOS IOS Features iPhone JAVA javascript Mac objective-c OneDrive OS Programming quicktips SDK SEO Settings SMO SQL swift swiftUI Teams Tips & Tricks Tools UI Web Wordpress Xcode

©mycodetips.com