Mobile Application Laboratory pdf copy1
Mobile Application Laboratory pdf copy1
IOS is the operating system that runs on iPad, IPhone and iPod touch devices.The
operating system manages the device hardware and provides the technologies required
to implement native apps. The operating system also ships with various system apps,
such as Phone, Mail, and Safari that provide standard system services to the user.
The iOS Software Development Kit(SDK) contains the tool and interfaces needed to
develop, install, run and test native apps that appear on an iOS device‟s Home screen.
Native apps are built using the iOS system frameworks and Objective-C language and
run directly on iOS. „ Unlike web apps, native apps are installed physically on a
device and are therefore always available to the user, even when the device is in
Airplane mode. They reside next to other system apps, and both the app and any user
data is synced to the user‟s computer through iTunes.
Apple delivers most of its system interfaces in special packages called frameworks. A
framework
is a directory that contains a dynamic shared library and the resources (such as header
files, image and helper apps) needed to support that. library. To use frameworks, you
add them to your app project from Xcode.
These frameworks provide the interfaces you need to write software for the platform.
Where, applicable, the tables in this appendix list any key/prefixes used by the classes,
methods, types, or constants of the framework. Avoid using any of the specified
prefixes in your own code.
The iOS Developer Library is an important resource for you to use during
development. The library contains API reference, programming guides ,release notes,
tech notes, sample code, and many other resources offering tips and guidance about
the best way to create your apps. One can access the iOS Developer Library from the
Apple Developer website or from Xcode. On Xcode, choose Help-> Documentation
and API Reference to display the Xcode documentation window, which is the central
resource for accessing information about iOS development. Use the documentation
window to browse, search, and bookmark documents.
61
1. Get a Mac: yes, one needs a Mac. It is the basic requirement for iOS
development. To develop an iPhone app, one needs to first get a Mac with
Intel-based processor running on Mac OS X version 10.8(or up).
2. Register an Apple Developer Account: By registering the developer account,
one is allowed to download Xcode, access documentation of the iOS SDK and
other technical resources such as development videos. One can go to Apple‟s
developer website for registration. The registration process is very straight
forward. Simply create an Apple ID and fill in your personal profile.
3. Install Xcode: To start developing iPhone and iPad apps, Xcode is the only
tool that one needs to download. Xcode is an IDE provided by Apple. Xcode
provides everything which is required to start the app development. It already
bundles the latest version of iOS SDK, a built-in source code editor, graphic
user interface editor, debugging tools and many more. Most importantly Xcode
come with an iPhone simulator so one can test the app even without the
physical devices.
62
Create an Xcode Project
1. Open Xcode.
2. Choose File > New > Project, or click “Create a new Xcode project” in the
Welcome to Xcode window.
3. Under the operating system you want to target, select Application, select a
template from the list of template, and click Next.
For example, to create an app with a single empty window, for iOS apps select
Single View Application, and for Mac apps, select Cocoa Application.
4. In the Dialog that appears, fill in the Product name and Company Identifier text
fields.
The company identifier should be in reverse DNS format. If you don‟t have a
company identifier, use com.example. followed by your name, and replace it
later. The other default values in the dialog should suffice for now. The
following screenshot shows options for creating an iOS app. For tvOS,
watchOS, and Mac apps, options are similar, but not identical.
63
5. From the Language pop-up menu, choose a programming language.
6. Click Next.
7. Specify the location for your project, optionally deselect “Create git repository
on” and click Create.
64
8. Enroll in iOS Developer Program:A common question about
developing iOS app is whether one needs to enroll in the iOS
Developer program. The short answer is “optional”. Xcode already
includes a built-in iPhone and iPad simulator so one can develop and
test the app right on the Mac.
65
Program 20: Working with Swift.
Swift is a new Programming language developed by Apple Inc for iOS and OS X
development. Swift adopts the best of C and Objective-C, without the constraints of C
compatibility.
Swift uses the same runtime as the existing Obj-C system on Mac OS and iOS, which
enables Swift programs to run on many existing iOS and OS X 10.8 platforms.
• Swift does not need a separate library import to support functionalities like
input/output or string handling.
Swift uses the same runtime as the existing Obj-C system on Mac OS and iOS, which
enables Swift programs to run on many existing iOS 6 and OS X 10 8 platforms.
Swift comes with playground feature where Swift programmers can write their code
and execute it to see the results immediately.
The first public release of Swift was released in 2010.It took Chris Lattner almost 14
years to come up with the first official version, and later, it was supported by many
other contributors.
Swift has been included in Xcode 6 beta.
Swift designers took ideas from various other popular languages such as Objective-C,
Rust, Haskell, Ruby, Python, C#, and CLU.
Swift provides a Playground platform for learning purpose and we are going to setup
the same. You need Xcode software to start your Swift coding in Playground. Once
you are comfortable with the concept of Swift, you can use Xcode IDE for iOS/OS x
application development.
66
To start with, we consider you already have an account at Apple Developer website.
Once you are logged in, go to the following link- Download for Apple Developers
Now select Xcode and download it by clicking on the given link near to disc image.
After downloading the dmg file, you can install it by simply double-clicking on it and
following the given instruction. Finally, follow the given instruction and drop Xcode
icon into the Application folder.
67
Now you can have Xcode installed on your machine. Next open Xcode from the
Application folder and proceed after accepting the terms and conditions. If everything
is fine you will get the following screen:-
Select Get started with a playground option and enter a name for playground and
select iOS as platform. Finally you will get the playground window as follow:-
68
Following is the code taken from the default Swift playground window.
Import UIKit
If you create the same program for OS X program, then it will include import Cocoa
and program will look like as follow:-
When the above program gets loaded, it should display the following result in
Playground result area.
Import in Swift
you can use the import statement to import nay objective-c framework directly into
your Swift program. For example the above import cocoa statement makes all Cocoa
libraries. APIs and runtimes that form the development layer for all of OS X available
in Swift.
69