Lesson 1: Programming in Xcode using Swift

Topic A Set up and use the development environment

  • Topic B Write and test swift code in playground
  • Topic C Process number and string
  • Topic D Create custom data types
  • Topic E Work with optionals
  • Topic F Control the flow of execution

Essential Tools

  • An Intel-based Mac® OS X computer
    • Best to have the latest version of Mac OS X installed
  • The latest version of Xcode® on your Mac
    • Free download from developer.apple.com or App Store
    • Includes code editing tools, storyboard authoring (user interface), and testing and debugging tools
  • The Simulator application
    • Installed with Xcode
    • Located in Applications folder
    • Enables you to test on iOS devices simulated on your Mac OS development computer
    • Very helpful for development and testing
    • Not a substitute for testing on real devices
  • The iOS software development kits (SDKs)
  • One or more real iOS devices (iPhone®, iPad®, iPod®) — optional, but recommended
  • Apple Developer Program account is required to distribute apps in the App Store

Developer Program Account

Program

Description

Apple Developer Program (Individual)

Allows the individual developer to distribute apps on the App Store.

Apple Developer Program (Organization)

Allows a development team to distribute apps on the App Store. Companies and educational institutions must provide their D-U-N-S. Number during the enrollment process.

iOS Developer Enterprise Program

Allows an organization to develop proprietary apps for internal distribution within a company, organization, government entity, or educational institution.

iOS Developer University Program

Provides benefits that support a degree-granting, higher education institution looking to deliver courses on iOS development.

Activity: Setting Up and Configuring Xcode

Screen Shot 2018-04-28 at 6.15.56 AM

Xcode Screen Areas

Screen Shot 2018-04-26 at 10.19.42 PM

Tips for Developers New to Mac OS X

  • Home and End keys to move to beginning or end of line
    Use command+Left Arrow and command+Right Arrow instead
  • Tab and Shift+Tab to change indentation
    Use command+left bracket and command+right bracket instead
  • Right-click on a single-button mouseUse control-click instead
  • Key shortcuts you have a hard time withChange key bindings under XcodePreferences

Activity: Navigating within the Development Environment

Screen Shot 2018-04-28 at 6.18.09 AM

  • The first app you will develop in this course is a custom Calculator app.
  • To become familiar with the development environment and the general construction of iOS apps, you will explore a completed example of this project.

Hide or show buttons

Screen Shot 2018-05-03 at 8.53.54 PM

Navigators

Screen Shot 2018-05-03 at 8.54.06 PM

The Swift Programming Language

Swift Standard Library

https://developer.apple.com/library/ios/documentation/General/Reference/SwiftStandardLibraryReference

Screen Shot 2018-05-03 at 8.59.56 PM

Provides base functionality you can use when you write Swift programs, including:

  • Basic data types, such as Bool, String, Int, and Double
  • Ordered data types, such as Array, Dictionary, and Set
  • Common functions and operators for manipulating these data types

iOS Frameworks

Layer Description
Core OS What it provides: Low-level features that most other technologies are built upon 
Examples: Accelerate, Core Bluetooth, External Accessory, Generic Security Services, Local Authentication, Network Extension, Security, System 
Core Services What it provides: Foundational classes used by all apps, such as support for location, iCloud, and networking 
Examples: Accounts, Address Book, Ad Support, CFNetwork, CloudKit, Core Data, Core Foundation, Core Location, Core Media, Core Motion, Core Telephony, EventKit, Foundation, HealthKit, HomeKit, JavaScript Core, Mobile Core Services, Multipeer Connectivity, NewsstandKit, PassKit, Quick Look, Safari Services, Social, StoreKit, System Configuration, WebKit 
Cocoa Touch What it provides: Key frameworks that define the appearance and general behavior of an app 
Examples: Address Book UI, EventKit UI, GameKit, iAd, MapKit, Message UI, Notification Center, PushKit, Twitter, UIKit 
Media What it provides: Graphics, audio, and video technologies to support multimedia in apps 
Examples: AirPlay, AV Foundation, AVKit, Core Animation, Core Audio, Core Video, Core Graphics, Core Image, Core Media, Core Text, Image I/O, Media Accessibility, Media Player, Metal, OpenAL, OpenGL, Photos Library, Quartz Core, SceneKit, SpriteKit, TextKit, UIImagePickerController, UIKit Graphics 

Activity: Writing and Testing Swift Code in a Playground

  • You are going to develop the custom calculator application, which will include specialized features to be used by your organization.
  • Playground provides a good environment for developing and testing your programming logic.
  • You will focus on the data model, free from the added complexity of manipulating a user interface.
Constants
  • Values that cannot be changed once they are assigned
  • Declared like variables, except that you use let instead of var.

let Pi = 3.14159 // This is a constant
let maximumNumberOfProducts = 1000 // This is a constant

var numberOfProducts = 32 // This is a variable
Pi = 3.14159265358979 // This assignment causes an error

numberOfProducts = 33 // This assignment succeeds

 

Data Types

Data Type Inference

  • Variables and constants must be declared with a data type
  • However, explicit declaration is not mandatory
  • Swift can infer the type by examining values you provide in the declaration

// Explicit declaration results in a Double

let pi:Double = 3.14159

// Assigning a floating point literal results in a Double

let anotherPi = 3.14159

// Assigning a Double results in a Double

let xFactor = Double(3)

// Implicit declaration results in a Double

let anotherPi = 3.14159

// Expression with all integer literals results in an Int

let mySum = 2 + 3 + 4

// Expression with integers and floating point literals results in a Double

let secondSum = 2 + 1 + 0.14

 

Operators

// Assignment ( = )

var a = 5 // a is 5

var b = 2 // b is 2

// Arithmetic ( +, -, *, /, %, ++, — )

a= a + 3 // a is now 8

a= a – 2 // a is now 6

a= a * 4 // a is now 24

a= a / 2 // a is now 12

a= a % 5 // a is now 2

a = a++ // a is still 2

a = b++ // a is now 2, b is now 3
a = ++b // a is now 4, b is now 4
b = --b // b is now 3

// Compound Assignment ( +=, -=, *=, /= )

varx=5 //x  is5

vary=2 //y  is2

x += y //x is now 7
x -= 1 //x is now 6

x *= 4 //x is now 24

x /= 3 //x is now 8

 

// Unary Minus ( – )

x = -5 //x is now -5

y= x + 7 //y is now 2

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.