Powered by
Powered by
HuntMyIdeas-Inspire You To Make It Happen
Follow
   Me
  • Blogs
  • About Me
  • Home

Top Swift interview Questions And Answers for Freshers

5/30/2016

1 Comment

 
Picture
1.How we declare variables in Swift ?
 
Answer:

Before using constants and variables,we must declare them .

Declare constants with the 'let' keyword and variables with the 'var' keyword.
1.What is difference between 'let' and 'var' declaration ?
​Answer:

let:
We use let keyword to define a constant.It can not be changed afterwards.

 Example:

let Cvalue = 42


A constant value doesn’t need to be known at compile time, but we must assign it a value once.

If you change a constant ,it will give an error as you cannot change the value of a constant.

 Cvalue=58 (It will not compile).

var:

We use  var keyword to define a variable whose value we can easily change.
Example:

var  number1=45
     number1=100;

Now, number1 value is changed to 100.


2.Why we use Type Annotations in Swift ?
Answer:

We provide a type annotation when we declare a constant or variable to identify the kind of values the constant or variable can store.

How to use ?

We write a type annotation by placing a colon after the constant or variable name followed by a space and followed by the type to use

Example:
var Message: String


The Message variable can now be set to any string value without error:
welcomeMessage = "Hello world"

Example of Character Annotation:
let exclamationMark: Character = "!"


3.How to Print Constants and Variables in Swift ?
Answer:


var Stringvalue="india!"
 print(Stringvalue)
 Prints "india!"

Swift uses string interpolation to include the name of a constant or variable as a placeholder in a longer string.

print("The name of my country is \(Stringvalue)")
 Prints "The name of my country is India!"



4.How to use Comments in Swift ?
Answer:
Swift compiler ignores comments  while compiling your code.
Comments in Swift are very similar to comments in C.
Single Line Comment:

// example  of Swift's  single line comment

Multiline comments ( It starts with  (/*) and ends with (*/))

/* this is a multiline comment,
and it's used for multiline texts or codes */

Nested Multiline Comments:

/* starting a  first multiline comment
/* Starting a second nested multiline comment */

 Ending the first multiline comment */


​5.Can you use Semicolon in Swift ?
Answer:
Yes, you can use semicolon in Swift.You don't need to write a semicolon (;) after the end of each statement in Swift.However,it's required if you write multiple separate statements on a single line.
Example:
let myName= "Morgan"; print(myName)

6.How to initialise an empty string in Swift ?
Answer:
var myEmptyString = "" 
How to initialise an empty string using Initialisers?

var MyNewEmptyString = String()


How to find out whether the string is empty ?
if myEmptyString.isEmpty {
    print("Yes ,String is empty")
}
prints "Yes ,String is empty"

7.How to use Mutable String in Swift ?
Answer:
String can be modified (or mutated) by assigning it to a variable.
var myString = "He is a"
newString += " good developer"

newString is now "He is a good developer"'


8.How to get individual characters from a string in Swift ?
Answer:
for char in "iPhone".characters {
print(char)
}

prints
// i
// P
// h
// o
// n

//e

9.What are the value of count1 and count 2 ? 

var iOSArray1 = ["iOS","Xcode","Objective C", "Swift","Cocoa touch"]
var iOSArray2 = iOSArray1
iOSArray2.append("Storyboard")

var count1 = iOSArray1.count
var count2 = iOSArray2.count
Answer: 5,6 

Read:

Top iOS Interview Questions And Answers for Beginners
Top 5 Simple iOS Interview Questions And Answers
Most Important iPhone interview Questions and Answers 
Top iOS interview Questions And Answers Collection


1 Comment
jeffiepriya link
12/19/2016 09:53:58 pm

Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. keep on updating...!!

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Enter your email address:

    Delivered by FeedBurner

    RSS Feed

    Archives

    December 2019
    August 2018
    January 2018
    December 2017
    November 2017
    October 2017
    August 2017
    April 2017
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014


    ​​Categories

    All
    Affiliate Marketing
    Alexa Rank
    Apple's Latest Updates
    Blog Tips
    Cocos2d X
    Cocos2d-x
    Google AdSense Tips
    Grab-some-ultimate-ideas
    How-to-create-a-twinkling-star-background-effect-in-ios
    In-App Purchase Tutorial In Cocos2d-x (C++) Using SDKBOX
    Ios Interview Questions And Answers
    IOS Multiple Choice Questions And Answers
    Objective C
    Online Business
    Python
    Secrets To Effective IPhone App Marketing
    SEO Tips
    Swift Interview Questions
    Swift Tutorials
    Top 10 Articles Objective C
    Top 10 Articles-Objective-C
    Top 10 Popular Movies Ever
    Top 10 Popular Things To Know
    Top 10 Ultimate Issues Xcode
    Top 400 IOS Interview Questions
    Top IOS Sample Projects To Learn From
    Top Secrets To App Marketing
    UICollectionView
    Unity 3D
    Xcode

WELCOME TO HUNTMYIDEAS

Picture
I am Jitendra Gochhayat,an iOS Developer,Designer,blogger,
​from Odisha,India.
I write about ​​​blog tips and,
Make money online Tips,
​Objective C tutorials
SUSCRIBE TO NEWSLETTER

    Subscribe to this blog and receive notifications of new posts by email

Suscribe
Picture
Picture
Picture
Picture
Picture
HuntMyIdeas-2016 Powered By Weebly
Picture
Powered by Create your own unique website with customizable templates.
Powered by
Powered by