• 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
Swift

Swift Programming Language Interview Questions And Answers

1. What is Swift Programming Language?

Swift is an innovative new programming language for Cocoa and Cocoa Touch. Writing code is interactive and fun, the syntax is concise yet expressive, and apps run lightning-fast. Swift is ready for your next iOS and OS X project — or for addition into your current app — because Swift code works side-by-side with Objective-C.

2. How to define Variables in Swift Language?

Constants and variables must be declared before they are used. You declare constants with the let keyword and variables with the var keyword.

let maximumNumberOfLoginAttempts = 10
var currentLoginAttempt = 0

3. How to define kSomeConstant as an integer?

In this case kSomeConstant is implicitly defined as an integer. If you want to be more specific you can specify which type it is like so:

let kSomeConstant: Int = 40
4. What is best way to add a Table View?

Open storyboard file in Xcode and lets drag in a “Table View” object from the Object Library (don’t use a table view controller.) Position this full screen in your app window and make sure it lines up with the edges. Then resize the height by dragging down the top edge and giving a little bit of space (this gives room for the status bar at the top of the phone.) If you run the app at this point, you should see an empty table view in the simulator.

5. How to connect UI in Swift Language?

Same as like c-objective. There is no change in binding process only core level has been changed. You can choose button/label on xib file and binding as is it.

6. What is difference between ‘let’ and ‘var’ declaration ?

constants are expressed with the ‘let’ keyword. So once assigned value can not be change, but assigned values using ‘var’ keyword can be change.

In terms of objective -c or compare with objective -c, ‘var’ is Mutable and ‘let’ is NonMutable.

let kMyConstant = 40
Or
let kMyConstant: Int = 40

var myString = “This is my string.”
7. What is Initialization ?

Initialization is the process of preparing an instance of a class, structure, or enumeration for use. This process involves setting an initial value for each stored property on that instance and performing any other setup or initialization that is required before the new instance is ready for use.
You implement this initialization process by defining initializers, which are like special methods that can be called to create a new instance of a particular type. Unlike Objective-C initializers, Swift initializers do not return a value. Their primary role is to ensure that new instances of a type are correctly initialized before they are used for the first time.

Initializers
Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method with no parameters, written using the init keyword:
init() {
// perform some initialization here
}

In Swift How to connect UI under Swift Environment ?

UI connectivity has no change, its similar to objective-c. Xib/Storyboard under Interface builder.
8. How to make an API (Web service) Call?

To make API (Web Service ) call in Swift you can do,

var params = [“MIN”:”f8d16d98ad12acdbbe1de647414495ec”, “MobileType”:”IOS”,”format”:”json”,”OperatorID”:”500200000000010025″] as Dictionary // Its the parameters required in the webservice.

var request = NSMutableURLRequest(URL: NSURL(string: kDataURL)) // Here kDataURL is the marco for URL.
var session = NSURLSession.sharedSession()
request.HTTPMethod = “POST”

var err: NSError?
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err)
request.addValue(“application/json”, forHTTPHeaderField: “Content-Type”)
request.addValue(“application/json”, forHTTPHeaderField: “Accept”)

var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
// println(“Response: \(response)”)
var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
println(“Body: \(strData)”)

var err: NSError?
var json2 = NSJSONSerialization.JSONObjectWithData(strData.dataUsingEncoding(NSUTF8StringEncoding), options: .MutableLeaves, error:&err1 ) as NSDictionary

println(“json1\(json2)”)

  • 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 - 9561 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 5,849 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 ARC asp.net blogging Browser Config CSS DATABASE DFD error Features GUI HTML HTML5 IDE IIS installation Interview Questions IOS iPhone 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