Interview Questions and Answers in iOS — Part 6

Interview questions and answers in iOS in very simple language.

Naveen Sharma
8 min readJun 2, 2020
Interview Questions and Answers in iOS

Q. Primary Key?
A. Unique and Not Null

Q. Foreign/Relational Key?
A. Duplicate and Null

Q. Unique Key?
A. Unique and Null

Q. What is Parser?
A. A Parser is a compiler or interpreter component that break data into smaller element for easy translation into another language.
A parser takes input in the form of a sequence of tokens or program instruction and usually builds a data structure in the form of a parse tree or an abstract syntax tree.
Top-Down Parsing
Bottom-Up Parsing

Q. What is Parsing?
A. Breaking data blocks into smaller chunks by following a set of rules so that it can be more easily interpreted, managed or transmitted by a computer.

Q. Which class we use for parsing of XML in iOS?
A. By NSXMLParser/XMLParser class. NSXMLParser/XMLParser is a event driven SAX parser.

Q. Difference between DOM and SAX Parser?
A. Both are used to parse the XML document.
SAX
-
It is an event driven parser.
- Parse node by node.
- It doesn’t store XML in memory.
- We can’t insert or delete a node.
- Top to bottom traversing.
- Faster than DOM.

DOM
-
Document based parser.
- Store the entire XML document into memory.
- We can insert or delete a node.
- Traverse in any direction.

Q. NSXMLParser/XMLParser Delegate?
A.
-
didStartElement
- didEndElement
- foundCharacter
- parserDidStartDocument
- parserDidEndDocument

Q. Web Services?
A. A web service is a collection of open protocols and standards used for exchanging data between applications or systems.
Web services are self-contained, modular, distributed, dynamic applications that can be described, published, located, or invoked over the network to create products, processes, and supply chains. These applications can be local, distributed, or web-based. Web services are built on top of open standards such as TCP/IP, HTTP, Java, HTML, and XML.
Two types of web services:
1. SOAP (Simple Object Access Protocol) Web Services
2. REST (REpresentational State Transfer) Web Services

Q. Components of Web Services?
A. The basic web services platform is XML + HTTP. All the standard web services work using the following components:
- SOAP (Simple Object Access Protocol)
- UDDI (Universal Description, Discovery, and Integration)
- WSDL (Web Services Description Language)

More About Web Services

Q. What is SOAP?
A. SOAP stands for Simple Object Access Protocol. SOAP is an open-standard, XML-based messaging protocol for exchanging information between two systems or applications.
SOAP is platform and language independent.

Q. SOAP Elements?
A. SOAP has four elements.
Envelope − Defines the start and the end of the message. It is a mandatory element.
Header − Contains any optional attributes of the message used in processing the message, either at an intermediary point or at the ultimate end-point. It is an optional element.
Body − Contains the XML data comprising the message being sent. It is a mandatory element.
Fault − An optional Fault element that provides information about errors that occur while processing the message.
More About SOAP

Q. SOAP advantages?
A. WS Security SOAP defines its own security known as WS Security.
Platforma and Language Independent SOAP web services can be written in any language and executed in any platform.
Simplicity SOAP messages are in a very simple XML format.
Scalability SOAP uses HTTP protocol for transport due to which it becomes scalable.

Q. SOAP disadvantages?
A. Slow SOAP uses the XML format which needs to be parsed to used or read. It defines many standards that must be followed while developing the SOAP application. So it is slow.
WSDL Dependent It depends on WSDL and does not have any standardized mechanism for the dynamic discovery of the services.
It consumes max bandwidth and resources.
Permits XML data format only.
Can’t use Rest.

Q. Explain WSDL?
A. WSDL stands for Web Services Description Language.
WSDL is an XML based protocol for information exchange in decentralized and distributed environments.
WSDL is an XML-based language for describing web services and how to access them. It contains information about web services such as method name, method parameters, etc.
WSDL is the language that UDDI uses.
More About WSDL

Q. Explain UDDI?
A. UDDI stands for Universal Description, Discovery, and Integration.
UDDI is an XML-based standard for describing, publishing, and finding web services.
More About UDDI

Q. REST Web Services?
A. REST stands for REpresentational State Transfer. It is an architectural style, not a protocol.

Q. REST advantages?
A.
-
Fast
- Consume less bandwidth and resource
- Can use SOAP.
- Permits different data formats like plain text, HTML, XML, and JSON.

Q. Difference REST and SOAP?
A. 1. REST is an architecture style.
SOAP is a protocol.

2. REST –> REpresentational State Transfer
SOAP –> Simple Object Access Protocol

3. In REST, JAX-RS (Java API for RESTful Web Services) is the specification for building/developing REST web services.
In SOAP, JAX-WS (Java API for XML Web Services) is the specification for building/developing SOAP web services.

4. In REST, For different CRUD operations like insert/select/update/delete, different HTTP 1.1 methods are available i.e. POST, GET, PUT, DELETE.
In SOAP, There are no such methods available for SOAP web services.

5. REST permits Plain text, HTML, XML, JSON.
SOAP permits only XML data format.

6. REST requires less bandwidth and resource compared with SOAP, as most of the time request /response exchanges in JSON format.
SOAP requires more bandwidth and resource, as request/response exchanged only in XML format.

7. REST depends on underlying transport for security purposes.
SOAP defines its own security, as it is standardized through WS-Security.

8. REST uses a web caching mechanism, as REST is URL based.
SOAP Ignores web caching mechanism.

9. REST doesn’t define any such standards like SOAP but it defines conventions like HTTP PUT for the update, HTTP POST for insert, etc
SOAP defines a standard set of protocols which needs be followed strictly, otherwise raising exception (i.e.; soap faults)

10. REST is used for light-weight applications like mobile applications or where processing required at a very high speed.
SOAP is used in large enterprise applications like Telecom, finance, etc where request/response pattern is complex.

11. REST is very easy to implement and it is highly preferred among developers community.
SOAP isn’t that easy to implement when compared with REST.

Q. HTTP Methods?
A. GET retrieve operation
PUT update operation
POST insert operation
DELETE delete operation

Q. Difference between HTTP and HTTPS?
A.
1.
HTTP: Hyper Text Transfer Protocol (Fast and Cheap)
HTTPS: Hyper Text Transfer Protocol Secure (Slow and Expensive)

2. HTTP transmits everything as a plain text while HTTPS provides encrypted communication so that only the recipient can decrypt and read the information.

3. As HTTPS is safe, It is widely used during payment transaction or any sensitive transaction over the internet.

Q. Difference between HTTP GET and HTTP POST?
A.
-
Using HTTP GET all the information we need to pass to the web services can be sent through the query string. The query string length is limited(less then 256 characters), hence not suitable if we need to post a lot of data to the web services.
- Using HTTP POST all the information we need to pass to the web services can be sent through the HTTP header. It allows more data to be sent.
- In HTTP POST the data must be formatted as key/value pairs but each key-value pair is limited in size to 1024 characters.
- HTTP POST is a little secure than GET because it is more difficult to modify the value sent in the header than the query string.

Q. NSURLConnection V/S NSURLSession?
A.
Advantages of NSURLSession:
-
Fetching of data via a network is easy
- Upload and download of data in the background
- Rich delegate methods
- Option to Cancel, Pause, Resume, Restart the download/upload network operations.
- Multiple session configurations to suit the application requirement
- Can provide different settings for different sessions.
- Private sessions, Cookies, Storage
- Support for HTTP1.1 and HTTP 2.0 automatically. No source code changes required.
- Uses best available connectivity (iPhone or WiFi)
- Switching to NSURLSession is easy
- Watch OS 2 only supports NSURLSession, It encourages reusability code in between iOS and Watches OS apps.
- Three different methods are there for different tasks: Download task, Upload task, Data task.

NSURLSessionTask

Disadvantages of NSURLConnection:
-
Watch OS2 does not support NSURLConnection
- A lot of coding is required
- Less control over the thread
- For a new thread, a Current thread must need to finish.

For Detail Study:
https://www.objc.io/issues/5-ios7/from-nsurlconnection-to-nsurlsession/

Q. Which JSON framework is supported by iOS?
A. SBJson

Q. What is Alamofire doing?
A. Alamofire uses URL Loading System in the background, so it does integrate well with the Apple-provided mechanisms for all the network development. This means It provides chainable request/response methods, JSON parameter and response serialization, authentication, and many other features. It has thread mechanics and executes requests on a background thread and call completion blocks on the main thread.

Q. Explain AlamoFire Benefits?
A.

  • AlamoFire creates a route. This means we can create the request and execute it to the server by one static function.
  • AlamoFire provides method chaining for the requests that are returned, which makes it easy for adding headers and handling responses.
  • AlamoFire has multiple response handlers that’s returned in binary form, text, parse JSON, and we can even use multiple of these for a given request.
  • AlamoFire has the method chaining that allows for response validation. We can call validation to check for the status code of the HTTP response, the content type, or any custom validation you might need to do for our app.
  • AlamoFire gives us that use a couple of protocols, URLConvertible, and URLRequestConvertible. These protocols can be passed in when creating a request.
  • AlamoFire provides extensions that can be passed in to create the request.

Q. Explain ObjectMapper for parsing JSON data?
A.
ObjectMapper converts JSON data to strongly typed model objects. It has a two-way binding between JSON and deals with the generic objects and nested objects. Also, we can manage subclasses.

Q. What kind of JSONSerialization have ReadingOptions?
A.
- mutableContainers
Specifies that arrays and dictionaries are created as variables objects, not constants.
- mutableLeaves Specifies that leaf strings in the JSON object graph are created as instances of variable String.
- allowFragments Specifies that the parser should allow top-level objects that are not an instance of Array or Dictionary.

  • Assert that the expected results have occurred.

Thank you for reading! If you liked this article, please clap to get this article seen by more people.
Please follow me on Medium by clicking Follow.
I’m also active on LinkedIn, Twitter, and GitHub.

--

--