ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iosdevelopment.pdf · the inheritance is a basic behavior,...

36
1 . . By: Arij Alfaidi Professor: Edward Chow University of Colorado at Colorado Springs.

Upload: others

Post on 14-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  1  

𝑇𝑒𝑠𝑡𝑖𝑛𝑔  𝑖𝑛  𝑢𝑠𝑖𝑛𝑔  𝑡ℎ𝑒  𝑊𝑎𝑡𝑐ℎ𝑘𝑖𝑡. .                            

By: Arij Alfaidi Professor: Edward Chow University of Colorado at Colorado Springs.  

Page 2: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 2  

 1: Introduction:

Of essence in the Network area is the field of mobile operating system. The smart

phone utility has become a daily activity for most people as it has made easy human lives

in many ways. Many large corporations have come up offering numerous mobile

operating systems. These firms include Samsung, Windows, Google, Apple, and many

others. This paper is a study that focuses on testing and discovering the iPhone operating

system (iOS) using the WatchKit. IPhone operating system can be described as a mobile

operating system, developed by Apple Inc. The design of the system if custom made to

suit only the Apple hardware. This operating system can support the iPod, iPhone, and

iPad, which are all under the Apple mobile portfolio. iOS development is the process of

creation of applications that run on the iOS powered devices.

2: iOS Development:

In the mobile platform, a large market share is held by the iPhone; this being the

reason behind interest in learning about iPhone development. The process of

development entails an outline of how to establish the hardware for the applications.

Setting of the software requirements and the final system requirements is also part of the

process. Apple Inc. has made it easier for people who want to become developers with

them. All a person needs is an account charged $99 annually, a mac computer, Xcode

Page 3: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  3  

platform and a coding experience, such as the Swift and Objective-C coding languages.

A developer page is availed that allows for download of the latest software and

SDKs. The page also enables a certification for creation of profiles and groups and one

has is free to manage the account and report any difficulty or bugs faced.

3: Swift:

The apple Inc. created a modern programming language called swift. It is

specifically developed to be more precise and flexible than the Objective-C. Swift has

LLVM (Low Level Virtual Machine) compiler framework that utilizes the objective-C

runtime allowing C, C++, Swift code and Objective-C to run in a single program. The

flexibility of Swift is attributed to its capacity to support widespread late binding,

dynamic dispatch and extensible programming. It is also considered safe and can

effectively manage the common programming errors, for example, the syntactic and the

null pointers to prevent occurrence of unwanted results.

Apple announces that Swift 2 will be an open source that will be released later in

this month August 2015.

Page 4: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 4  

4: Features:

The Swift programming language has several features that indicate some

similarities to the Objective-C, though are easier and more flexible.

4.1: Types:

Many types of variables are supported by Swift, and are constant just like in

the other languages.

o . Any variable can be declared from any type by utilizing colon (:) after

the name. The colon implies of type, for instance,

Var name: String

o . Declaration of a constant with a non-changeable constant value is also

possible, for example:

Let name: String

• The following types of declaration are supported by Swift

String: for string values.

Int: for integer values.

Double: for double values which represents a 64-bit

floating-point number.

Float: for float values which represents a 32-bit floating-

point number.

Bool: for Boolean values.

o You can print a variable and a constant using the method:

Println(”Hello World”)

o You can insert a value to print like:

Println(“Hello World by: \(name)”)

Page 5: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  5  

o To add a comment in the code which is a useful way to make you code readable

and to remind your self we use: //

// Write your comment here.

o Swift does not entail the use of semicolon like the other languages after each

statement in the code.

o The semicolons are only required when there is the need of writing several

separate statements in one line.

let name: String = “Areej”; println(name)

o An optional variable is set to a valueless state by assigning to it the special

value nil

o The conditional statements such as if-in, if, if-else are used just like in any

other languages.  

4.2: Basic Operators:

We use the operators to give a value, change a value or combine values.

o Assignment operators (=) used in updating or initializing values.

o The fundamental arithmetic operators are supported by Swift for all numbers

types such as:

- Addition (+)

- Subtraction (-)

- Multiplication (*)

- Division (/)

Page 6: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 6  

o The remainder operator (x% y) works out the number of multiples of y that can

fit inside x and give back the left over value.

o Increment operator i++, ++I used to increase the value of i by 1.

o Decrement operator i--, --i use to decrease the value of i by 1.

o All the standard C comparison operators are supported by Swift; they include

Equal to (a == b)

ü Not equal to (a != b)

ü Greater than (a > b)

ü Less than (a < b)

ü Greater than or equal to (a >= b)

ü Less than or equal to (a <= b)

o The true or false Boolean values are changed or combined by the Logical

operators. These three standard logical operators are supported by Swift:

v Logical NOT (!a)

v Logical AND (a && b)

v Logical OR (a || b)

o Array, Dictionary and Sets types of collection are supported in Swift. Sets refer

to the unordered collections of distinct values; Arrays are the ordered collections

of the distinct values and Dictionary refer to the ordered collections of the key

associational values.

Page 7: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  7  

o Looping of for and while enables the performance of tasks multiple times; the

switch and if statements are used in executing different parts of the code on the

basis of some factors. The Swift supports all these control factors.

4.3: Functions:

Functions are the self-contained piece of codes performing specific tasks, and are

like Methods in other languages. The function is named based on the task that it is

supposed to perform, and the name is usually used in “calling” the function to perform

the task if required. One or more names, typed values taken as inputs by the function also

known as parameters, and the types of values given back as outputs by the function (also

known as return type) can be defined:

func sayHello(Name: String) -> String {

let greeting = "Hello, " + Name + "!"

return greeting

}

• Similar to blocks in C and Objective-C are closures in Swift that can be used in

code and passed around. An enumeration is used in defining the common type for

a group of related values that enables the user to work with the values in a type-

safe way within the code. The introduction of the enumerations with enum

keyword then follows which places the whole definition within a braces pair:

Page 8: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 8  

enum CompassPoint {

case North

case South

case East

case West

}

4.4: Classes and structures:

o Classes and structures refer to the flexible constructs that create the blocks

of the code of the user’s program. It utilizes the same syntax as those of

the variables, constants and functions so that the user can define the

structures and classes. The classes and the structures have same definition

syntax. Class keywords are used in the introduction of classes and the

struct keywords used in introitducting the structures:

class SomeClass {

// class definition goes here

}

struct SomeStructure {

// structure definition goes here

}

• Methods refer to the functions that are related to a particular type. Instance

methods can be defined by structures, classes and enumerations that encapsulate

Page 9: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  9  

particular tasks and functionality in operating with a given type of instance. Type

methods can also be defined by the enumerations, structures and classes that are

associated with the type itself. In the Objective-C, the class methods are similar to

the type methods.

• A class has the capacity to inherit properties, methods as well as other

characteristics from other classes. In the instance that one class inherits from

another, the class that is inheriting is known as the subclass while the class that it

inherits characteristics from is referred to as the superclass. The inheritance is a

basic behavior, which distinguishes the classes from other types in the Swift.

• Subclassing, therefore, refers to the process of basing new classes on the existing

ones. The subclass will thus inherit the characteristics from the existing classes,

which can then be refined. New characteristics can be added to the subclass..

• Initialization would refer to the process that involves preparation of an instance of

class, enumeration and structure for utility. The process entails the setting of an

original value for each of the stored property on the instance and performing any

other appropriate initialization or set up that is needed before the new instance

becomes ready for use.

• Initializers are adopted to enable the creation of new instance of particular types.

An initialize can be compared to an instance method in its simplest form with no

parameters that are written using the init keywords:

init() {

// perform some initialization here

}

Page 10: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 10  

• Before the deallocation of a class instance, a deinitializer is immediately called.

The deinit keyword is used in writing the deinitializers, in a similar fashion to

how the initializers are written using the init keyword. The availability of the

deinitializers is limited only to class types.

• Only one deinitializer can be possessed by a class definition per class. The

deinitializers are written with no parenthesis and do not have any parameters.

deinit {

// perform the deinitialization

}

• Optional Chaining refers to the process of calling and querying methods,

properties and subscripts on an option that may be nil presently. The property,

subscript or method will succeed if the optional contains a value; however, the

property, subscript or method returns nil if the optional is nil. If any link in the

chain having multiple queries is nil, the whole chain will fail gracefully. These

form the foundation of the Swift language, even though there are other language

concepts.

Page 11: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  11  

5: Apple Watch:

The Apple watch, otherwise known as iWatch, is a smart watch presented by

Aplle Inc. in April 2015. The watch features health oriented and fitness tracking

capabilities as well as an integration with iOS and other services and products of Apple.

The device is in three collections, the Apple Watch, the Apple Watch Sport and the

Apple Watch Edition. The watch products depend on wirelessly connected iPhone for

them to perform many of their default functions such as texting and calling.

5.1:  Features:

o Apple Watch comes in three types and two case sizes: 38 mm (1.5 in) and

42 mm (1.7 in)

o The strap of the watch is interchangeable.

o The screen is a really sensitive touch-screen that can tell if it is a tap and a

press ("Force Touch").

Page 12: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 12  

o The digital crown, can be used, to scroll or zoom and pressed to return to

the home screen.

o The Button on the side can be used to display a list of contacts, or access

Apple Pay.

o The battery can stand for 18 hours of mixed usage.

o The watch is built-in with heart rate sensor that uses both infrared and

visible-light LEDs and photodiodes.

o The wrist is also used for collecting data about your physical activity, a

task Apple Watch is designed to perform throughout the day so that’s why

the watch is very beneficial for the people who exercise a lot.

o The sensor allows Apple Watch to give a clear picture of your workouts

and daily activity, suggest personal activity goals, and direct you to reach

your personal fitness goals.

o Apple Watch can present time in a more personal way since it's connected

to your iPhone. Notifications for new mail, messages, and calls can be

received on the watch to enable you to answer or dismiss them

immediately.

o When you receive a notification A gentle tap can be felt on your wrist to

lets you know the time and place of your next meeting, when you should

leave, and the best route to take.

o By swiping down on the watch you can see any notifications you may

have missed.

Page 13: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  13  

o Also, You can reach Siri closely and you can use the Map application on

you rest.

6: Xcode-Beta:

• Xcode is the platform that apple make it to the people to make an application for

the iPhone

• You can download the Xcode beta from apple developer website that allows you

to use the Watchkit extension.

• To start a new project with xcode you should click on the xcode- beta icon

Page 14: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 14  

Then choose create a new Xcode project.

Choose the type of the project that you want to build.

   

Write your project name and language and information the click Next.  

Page 15: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  15  

     Choose where do you want to save your project then click create.  I practiced to use xcode project after learning a Swift language basics by

creating different applications and using the play ground in the first to learn

the basics.

Page 16: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 16  

6.1: Facts Application: In this application I tried to use the arrays and the buttons so when the user click on the

button Show fact it show the fact and when he clicks again it show another fact and

change the background color.

I should say that there are a lot of examples online. I tried to follow and write to explore

more.

       

Page 17: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  17  

To change the background color I create a Swift file in the project that has a function that

can handle the colors I followed the TreeHose direction to this kind of apllication:

// Copyright to tree house

import Foundation import UIKit struct Colors { let colorsArray = [ UIColor(red: 90/255.0, green: 187/255.0, blue: 181/255.0, alpha: 1.0), //teal color UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0), //yellow color UIColor(red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0), //red color UIColor(red: 239/255.0, green: 130/255.0, blue: 100/255.0, alpha: 1.0), //orange color UIColor(red: 77/255.0, green: 75/255.0, blue: 82/255.0, alpha: 1.0), //dark color UIColor(red: 105/255.0, green: 94/255.0, blue: 133/255.0, alpha: 1.0), //purple color UIColor(red: 85/255.0, green: 176/255.0, blue: 112/255.0, alpha: 1.0), //green color ] func randomColor() -> UIColor { var unsignedArraycount = UInt32(colorsArray.count) var unsignedRandomNumber = arc4random_uniform(unsignedArraycount) var randomNumber = Int(unsignedRandomNumber) return colorsArray[randomNumber] // I used the Treehouse course to learn more about this App } }      

Page 18: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 18  

The ViewController of the Application is : // // ViewController.swift // FactsFun // // Created by Areej on 7/12/15. // //// Copyright to tree house

import UIKit class ViewController: UIViewController { @IBOutlet weak var funFactLabel: UILabel! @IBOutlet weak var funFactButton: UIButton! let factBook = FactBook() let colorwheel = Colors() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. funFactLabel.text = factBook.randomFacts() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func showFunFact() { var randomColor = colors.randomColor() view.backgroundColor = randomColor funFactButton.tintColor = randomColor funFactLabel.text = factBook.randomFacts() // I used the Treehouse course to learn more about this App

Page 19: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  19  

}  I tried a lot of applications in different part of Swift but I found it interesting to learn how

to create a Weather Application that can load the information from the internet so I create

the

6.2: application Weathery

     

Page 20: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 20  

 in this application I used a lot of classes and enumeration to control the design but what I

want to focus on is the Network Operation :

import Foundation class NetworkOperation { lazy var config: NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration() lazy var session: NSURLSession = NSURLSession(configuration: self.config) let queryURL: NSURL typealias JSONDictionaryCompletion = ([String: AnyObject]? -> Void) init(url: NSURL) { self.queryURL = url } func downloadJSONFromURL(completion: JSONDictionaryCompletion) { let request = NSURLRequest(URL: queryURL) let dataTask = session.dataTaskWithRequest(request) { (let data, let response, let error) in // 1. Check HTTP response for successful GET request if let httpResponse = response as? NSHTTPURLResponse { switch httpResponse.statusCode { case 200: // 2. Create JSON object with data let jsonDictionary = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as? [String: AnyObject] completion(jsonDictionary) default: println("GET request not successful. HTTP status code: \(httpResponse.statusCode)") } } else { println("Error: Not a valid HTTP response") } } dataTask.resume() }

Page 21: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  21  

// I used the Treehouse course to learn more about this App // Copyright to tree house

} I used a forecast service to load the information from the Internet the website called the

dark sky:

       This is the website it gives you the weather information about a specific location and

because I choose the free account I couldn’t change the location but I wanted to try it.

Also, it gives you the location information to use it in your code:

 import Foundation struct ForecastService { let forecastAPIKey: String let forecastBaseURL: NSURL? init(APIKey: String) { forecastAPIKey = APIKey

Page 22: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 22  

forecastBaseURL = NSURL(string: "https://api.forecast.io/forecast/\(forecastAPIKey)/") } func getForecast(lat: Double, lon: Double, completion: (Forecast? -> Void)) { if let forecastURL = NSURL(string: "\(lat),\(lon)", relativeToURL: forecastBaseURL) { let networkOperation = NetworkOperation(url: forecastURL) networkOperation.downloadJSONFromURL { (let JSONDictionary) in let forecast = Forecast(weatherDictionary: JSONDictionary) completion(forecast) } } else { println("Could not construct a valid URL") } // I followed the treehouse direction to write this code. // Copyright to tree house

} }  So, after practicing different application I want to focus my study on the watchKit and

how to use it.

 7: WatchKit:  

The Xcode framework has classes that any Watchkit extension will employ in

manipulating the user interface of the application. WatchKit.framework is inbuilt with

controllers for the interface that include buttons, sliders, visual elements and tables. The

extension will service the classes in the framework to design the interface as to be

responsive to interactions with the user. The Watchkit application functions to handle

communications between the user and the presentation of the UI. The extension on the

Page 23: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  23  

Apple watch runs on an iPhone that is paired and handles the business logic (Ni, Chen,

Ye & Wang, 2014). User interaction with the WatchKit forwards the events to the

extensions on the Paired iPhone.

The initial step starts with creating the project of interest to you then create

WatchKit targets. That is accessible from the File menu that is a submenu under Target

and New as the parent menu. WatchKit App is available for navigating to the iOS then

Apple Watch. XCode handles creating groups, targets, various files and a schema

responsible for running the WatchKit application as a simulation in the iOS.

Page 24: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 24  

The two targets created include the WatchKit application and WatchKit

extension. The extension runs on the iPhone that is paired to the Watch and services logic

of the business in the WatchKit application whereas the WatchKit application runs on the

Apple Watch. It handles user interface presentation. It also handles events.

After the Xcode completes building the iOS application, WatchKit application,

and WatchKit extension, it performs an installation of the trio in the iOS simulator. The

extension and implementation WatchKit are then run in the simulator or you can connect

your iPhone that is pared with the watch to your computer to run on it.

In the sequence is the creation of the user interface through the use of storyboards

and auto layout. Storyboards are used for building the WatchKit application despite the

lack of auto design. The scene on the Interface controller is the singular scene in the

Page 25: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  25  

storyboard. It has a controller for the Interface in the Scene Navigator showing its

primary entry from the WatchKit application. The interface controller handles managing

the user interface behavior. That is variant from a view controller that maintains a view

hierarchy. The previous configures the interface of the WatchKit application. It also

responds to events forwarded to the WatchKit extension by the WatchKit application.

The controller is thus an instance of WKInterfaceController class.

The creation of the layout follows and is indicative of CSS and HTML in creating

web pages. WKInterfaceGroup class is part of the building block for the WatchKit

layout. It forms a container holding the elements of the interface like the tables, and the

labels. It handles the structure and design components of the group. These are contained

in the Object Library. Groups can be nested to build complex Watchkit applications

designs. The groups also snap into place with the interface controller being a group.

Interface elements can then be added from the Object Library, for instance, the

label. By so adding, the group size shrinks to fit the label size. Elsewhere, a placeholder

is a formation of an empty group outline. The size of the contents forces the group size to

adjust to its fit. The label added earlier is WKInterfaceLabel type but not UILabel. There

are a lot of similarities between elements in iOS applications and WatchKit applications,

but they are different.

Continue adding the elements depending on your application as the date interface

element. The actions and outlets will allow access to elements in the interface from the

code and will facilitate handling of user actions like when a press occurs on a button. To

build the application, click the Run button or use the option Command-R. That builds and

runs the application in the iOS simulator.

Page 26: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 26  

8: Swifty:

I practice a lot of using the watchkit it is difficult because it is new and there is a

few references that you can learn from. My application idea is how to share data between

that watch and the iPhone. To share the data between the iPhone and the watch you

should create group for your application that will save the shared data between the watch

and the iPhone. From the application properties > Capabilities > Add group > On > create

your group

You should do the same for the watch-Kit extension of your application.

Page 27: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  27  

So my StoryBoard for the watch was as follows:

• Different buttons of Swift programming language concepts, that the user should

choose one of them.

• When the user choose the button the Button data stored in the group dictionary

that is shared between the iPhone and the watch.

Page 28: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 28  

The iPhone interface:

When the user clicks on show Concepts it shows the declaration of the topic that he

choose on the watch.

Page 29: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  29  

So, when the user presses on the Show Concept button it retrieved the data that is stored

on the shared group between the watch and the IPhone.

The retrieved data will appear on the label on the IPhone interface.

This is my watchkit interface implementation code:

// // InterfaceController.swift // Swifty WatchKit 1 Extension // // Created by Areej on 7/15/15. // Copyright © 2015 UCCS. All rights reserved. // import WatchKit import Foundation class InterfaceController: WKInterfaceController { override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) // Configure interface objects here. } override func willActivate() { // This method is called when watch view controller is about to be visible to user super.willActivate() } override func didDeactivate() { // This method is called when watch view controller is no longer visible super.didDeactivate() } @IBAction func DelarationButton() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! defaults.setValue("To declair a constant we use (let)

Page 30: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 30  

To declair a variable we use (var) ", forKey: "sharedData") } @IBAction func PrintingButton() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! defaults.setValue("To print a command we use: println(write what you want to print here )", forKey: "sharedData") } @IBAction func Comments() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! defaults.setValue("To add a comment to make the code more easy to read we use the sign //", forKey: "sharedData") } @IBAction func TypesButton() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! defaults.setValue("INT: for integers Double: for double values String: for string values Bool: for boolean values", forKey: "sharedData") } @IBAction func OptionalButton() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)!

Page 31: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  31  

defaults.setValue("To make the value optional in the declaration we use ? for example: An optional Int is written as Int? ", forKey: "sharedData") } @IBAction func EnumerationButton() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! defaults.setValue("An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code.for example: enum Color { case Red, Green, Yellow, Blue, Orange } ", forKey: "sharedData") } @IBAction func ClassStructures() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! defaults.setValue(" Classes and structures are general-purpose, flexible constructs that become the building blocks of your program’s code. You define properties and methods to add functionality to your classes and structures by using exactly the same syntax as for constants, variables, and functions.To declare a class we use the word(Class) and To declair a function we use (func)", forKey: "sharedData") } @IBAction func InitializersButton() { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! defaults.setValue(" 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", forKey: "sharedData") }

Page 32: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 32  

}

This is my iPhone interface controller implementation code: // // ViewController.swift // Swifty // // Created by Areej on 7/15/15. // Copyright © 2015 UCCS. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet weak var MyLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func ShowConcept(sender: AnyObject) { var container: String = "group.Shared.Swiftty" var defaults: NSUserDefaults = NSUserDefaults(suiteName: container)! var sharedData: String = defaults.valueForKey("sharedData")! as! String self.MyLabel.text = sharedData }}

Page 33: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  33  

9: Lesson Learned and Challenges:

In this study I challenged my self to learn about a lot of stuff in really short time like the

summer term. Before two months ago I had a general idea about Mobile Software but in

this study I dig to the deep of it. I learned about:

• Mobile software and how the Mobile software is important in Network field like

Security.

• IOS software that the Apple Inc uses and how to develop it.

• It is important to know about developing iOS since in the market area Apple is a big

name.

• Apple made it easy to develop by creating Xcode platform to use with Swift

language and with Objective-C language.

• Swift is really important programming language that gives you many capabilities to

work with.

• Learning Swift in small time was a challenge but the best way was is to practice

using it to create applications.

• Creating app with Xcode beta was a challenge also because it is new platform a lot

of time it stop responding and doesn’t work so you have restart it.

• Watchkit extension took a big amount of time from me because it is new thing there

is few resources to read from and the people experience about it is really new.

• You feel the achievement when you see your application runs without errors.

Page 34: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 34  

10: Future Work and Conclusion:

As a result IOS development is an extensive process that involves mastery of the tools

for the development that is the WatchKit framework. It is then coupled with WatchKit

extensions and WatchKit application. The developer then needs to build up an

understanding of the interface, positioning and formatting. Also, they need mastery of

the actions and outlets as well as the lifecycle for the interface. Further, they need to

know groups, the storyboard, interface objects, how to navigate and finally to perform a

test on the application. A lot of test needs to be performs on the WatchKit but it is

something really important to know and work with. In the future I am looking to improve

my application more by using the notification on the watch. Also, I am thinking about

studying how the apple watch read the movement of the body and how this technology

can be develop in the watch. The healthKit in the watch is an interesting parts to learn

about since it is the focus on the market now. In the end, IOS development is really an

interesting field to study about.

Page 35: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

  35  

11: References

Kelly, M. (2015). Build watchkit apps. [S.l.]: Peachpit Press.

Ni, Y., Chen, B., Ye, P., & Wang, C. (2014). A Framework for iOS Application

Development. JSW,9(2). doi:10.4304/jsw.9.2.398-403

Timmer,  John  (June  5,  2014).  "A  fast  look  at  Swift,  Apple's  new  programming  language".  Ars  Technica.  Condé  Nast.  Retrieved  June  6,  2014.  

Weathry and FcatsFun design tips and code tips from the Treehouse courses online:

http://www.teamtreehouse.com

The Swift Programming Language, Apple June 2, 2014. Retrieved June 2, 2014.

Weber, Harrison (June 2, 2014). “Apple announces 'Swift,' a new programming language

for OS X & iOS”

Apple : http://www.apple.com/watch/?afid=p238|ssGS4MjvL-

dc_mtid_20925qtb42335_pcrid_79417947013_&cid=wwa-us-kwg-watch-slid-

YouTube lessons:

Watchkit swift tutorial:

https://www.youtube.com/watch?v=Bx6WWOUHhs0

https://www.youtube.com/watch?v=0ts196U4xS4

Page 36: ℎ !#$ℎ!#gsc/pub/master/aalfaidi/doc/iOSDevelopment.pdf · The inheritance is a basic behavior, which distinguishes the classes from other types in the Swift. • Subclassing,

 36