
Swift iOS 24-Hour Trainer
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
More details
Other editions
Additional editions

Person
Content
SECTION I: HELLO iOS!
LESSON 1: HELLO iOS! 3
iOS Developer Essentials 3
A Suitable Mac 3
A Device for Testing 4
An iOS Developer Account 4
The Offi cial iOS SDK 6
The Typical App Development Process 6
Wireframes and Design 8
Coding 8
Testing 8
Home Screen Icon 9
Application Launch Image 10
Try It 11
Lesson Requirements 11
Hints 11
Step-by-Step 11
LESSON 2: A TOUR OF XCODE AND THE iOS SIMULATOR 19
The Welcome Screen 19
Creating a New Project 20
An Overview of the Xcode IDE 22
The Navigator Area 22
The Editor Area 26
The Utilities Area 28
The Debugger Area 30
The Toolbar 30
Features of the iOS Simulator 31
Installing and Uninstalling Applications 32
Limitations of the iOS Simulator 33
Try It 33
Lesson Requirements 33
Hints 33
Step-by-Step 33
LESSON 3: INTRODUCING SWIFT 35
Introducing Xcode Playgrounds 35
Constants and Variables 37
Data Types 38
Comments 39
Strings 39
Tuples 40
Optionals 41
Control Flow Statements 42
if-else 42
switch-case 44
Loops 45
Control Transfer Statements 49
Try It 50
Lesson Requirements 50
Hints 50
Step-by-Step 50
LESSON 4: FUNCTIONS 53
Declaring Functions 53
Parameters and Return Values 53
Try It 55
Lesson Requirements 55
Hints 55
Step-by-Step 55
LESSON 5: CLOSURES 57
Function Types 57
Closure Types 58
Global Closures 58
Nested Closures 58
Closure Expressions 59
Try It 60
Lesson Requirements 60
Hints 60
Step-by-Step 60
LESSON 6: ERROR HANDLING 63
The ErrorType Protocol 63
Throwing and Catching Errors 64
Suppressing Error Handling 65
The defer Statement 66
Try It 66
Lesson Requirements 66
Hints 67
Step by Step 67
LESSON 7: OBJECT-ORIENTED PROGRAMMING WITH SWIFT 69
Creating Classes with Swift 70
Properties 70
Methods 71
Instantiating Objects 74
Inheritance 74
Computed Properties 76
Enumerations 77
Protocols 77
Try It 81
Lesson Requirements 81
Hints 81
Step-by-Step 81
LESSON 8: SUPPORTING MULTIPLE DEVICE TYPES 85
Device Differences 86
Screen Size 86
Icon Size 87
Device Orientation 89
The Universal XCode Template 90
Try It 91
Lesson Requirements 91
Hints 91
Step-by-Step 91
LESSON 9: INTRODUCTION TO UIKIT AND ADAPTIVE LAYOUT 95
Introducing the UIKit Framework 95
The UIButton Class 97
The UILabel Class 98
Basic Constraints 99
Previewing Your Layout 106
Creating Outlets 108
Creating Actions 110
Try It 110
Lesson Requirements 110
Hints 111
Step-by-Step 111
LESSON 10: INTRODUCTION TO STORYBOARDS 117
Try It 124
Lesson Requirements 124
Hints 125
Step-by-Step 125
SECTION II: MORE iOS DEVELOPMENT
LESSON 11: HANDLING USER INPUT 143
Text Fields 143
Text Views 146
Try It 147
Lesson Requirements 147
Hints 148
Step-by-Step 148
LESSON 12: ALERT VIEWS AND ACTION SHEETS 155
Alert Views 155
Action Sheets 159
Try It 161
Lesson Requirements 161
Hints 161
Step-by-Step 161
LESSON 13: ADDING IMAGES TO YOUR VIEW 167
The UIImage Class 167
The UIImageView Class 170
Try It 172
Lesson Requirements 172
Hints 172
Step-by-Step 172
LESSON 14: PICKERS 177
Date Pickers 181
Custom Pickers 184
Try It 185
Lesson Requirements 185
Hints 185
Step-by-Step 186
LESSON 15: NAVIGATION CONTROLLERS 193
Adding a Navigation Controller to a Storyboard 193
The Navigation Controller Interface 196
Try It 197
Lesson Requirements 198
Hints 198
Step-by-Step 198
LESSON 16: TABLE VIEWS 203
Table View Appearance 203
Creating a Table View with Interface Builder 205
Static Table Views 206
Dynamic Table Views 207
Try It 211
Lesson Requirements 211
Hints 211
Step-by-Step 211
LESSON 17: COLLECTION VIEWS 217
Creating a Collection View with Interface Builder 218
Collection View Cells 219
Collection View Delegate and Data Source 220
Try It 222
Lesson Requirements 222
Hints 223
Step-by-Step 223
LESSON 18: TAB BARS AND TOOLBARS 229
Creating a Tab Bar Controller 231
Toolbars 235
Try It 238
Lesson Requirements 239
Hints 239
Step-by-Step 239
LESSON 19: CREATING VIEWS THAT SCROLL 245
The UIScrollView Class 245
Scroll Views and Text Fields 248
Try It 249
Lesson Requirements 249
Hints 250
Step-by-Step 250
LESSON 20: POPOVERS AND MODAL VIEWS 257
Popovers 257
Modal Views 260
Try It 262
Lesson Requirements 262
Hints 263
Step-by-Step 263
LESSON 21: TOUCHES AND GESTURES 269
Touch Events 269
Gesture Recognizers 270
Try It 271
Lesson Requirements 271
Hints 272
Step-by-Step 272
SECTION III: STORING DATA AND NETWORK PROGRAMMING
LESSON 22: PROPERTY LISTS 277
Creating Property Lists 277
Reading Property Lists 279
Try It 280
Lesson Requirements 280
Hints 280
Step-by-Step 280
LESSON 23: APPLICATION SETTINGS 285
Adding a Settings Bundle 285
Reading Preferences with Code 289
Try It 290
Lesson Requirements 290
Hints 290
Step-by-Step 291
LESSON 24: INTRODUCTION TO iCLOUD STORAGE 295
Basic Concepts 295
Preparing to Use the iCloud Storage APIs 297
Creating an iCloud-Enabled App ID 297
Creating an Appropriate Provisioning Profi le 302
Enabling Appropriate Entitlements in Your Xcode Project 308
Checking for Service Availability 309
Using iCloud Document Storage 310
Creating a New iCloud Document 311
Opening an Existing Document 312
Saving a Document 312
Searching for Documents on iCloud 313
Try It 315
Lesson Requirements 315
Hints 316
Step-by-Step 316
LESSON 25: INTRODUCTION TO CLOUDKIT 327
Containers, Databases, and Records 327
Development and Production Environments 330
The CloudKit Dashboard 331
Creating a Record Type 331
Deleting a Record Type 333
Creating Relationships Between Record Types 333
Adding Records 334
Modifying and Deleting Records 336
Resetting the Development Schema 337
Deploying to Production 337
Preparing to Use CloudKit 338
Create an iCloud-Enabled App ID 338
Create an Appropriate Provisioning Profi le 344
Enable Appropriate Entitlements in Your Xcode Project 350
Common Operations 350
Checking for Service Availability 351
Creating Records Programmatically 351
Retrieving Records 352
Try It 352
Lesson Requirements 353
Hints 353
Step-by-Step 353
LESSON 26: INTRODUCTION TO CORE DATA 381
Basic Concepts 381
Managed Object 381
Managed Object Context 381
Persistent Store Coordinator 382
Entity Description 383
Managed Object Model 383
Adding Core Data to a Project 384
Instantiating Core Data Objects 389
Writing Managed Objects 390
Reading Managed Objects 391
Try It 391
Lesson Requirements 391
Hints 392
Step-by-Step 392
LESSON 27: CONSUMING RESTful JSON WEB SERVICES 399
Types of Web Services 400
RESTful Web Services 400
SOAP Web Services 401
JSON and NSJSONSerialization 401
NSURLSession and Application Transport Security 403
Creating an NSURLSession 404
Creating a Data Task 405
Application Transport Security 406
Try It 408
Lesson Requirements 408
Hints 409
Step-by-Step 409
SECTION IV: BEYOND THE BASICS
LESSON 28: SOCIAL MEDIA INTEGRATION 417
The Share Sheet 418
Try It 421
Lesson Requirements 421
Hints 421
Step-by-Step 422
LESSON 29: WHERE Am I? INTRODUCING CORE LOCATION 427
Permissions 428
Accuracy 430
Receiving Location Updates 431
Handling Errors and Checking Hardware Availability 433
Geocoding and Reverse Geocoding 434
Obtaining Compass Headings 435
Try It 436
Lesson Requirements 436
Hints 437
Step-by-Step 437
LESSON 30: INTRODUCTION TO MAP KIT 443
Adding Annotations 444
Accessory Views 447
Try It 447
Lesson Requirements 448
Hints 448
Step-by-Step 449
LESSON 31: USING THE CAMERA AND PHOTO LIBRARY 455
Selecting the Image Source 456
Presenting the Image Picker 456
Try It 459
Lesson Requirements 459
Hints 459
Step-by-Step 459
LESSON 32: INTRODUCTION TO USER INTERFACE TESTING 465
Adding Support for UI Testing to Your Project 465
Anatomy of a Test Case 468
New Classes for UI Testing 469
XCUIApplication 469
XCUIDevice 470
XCUIElementQuery 471
XCUIElement 472
XCUIElementAttributes 475
XCUIElementTypeQueryProvider 476
Test Assertions 477
UI Recording 478
Waiting for Elements in a UI Test 479
Try It 480
Lesson Requirements 480
Hints 480
Step-by-Step 481
LESSON 33: INTRODUCTION TO TEST DRIVEN DEVELOPMENT 485
Adding Support for Unit Testing to Your Project 486
TDD Techniques 488
Test First 488
Red-Green-Refactor 488
Don't Write Code You Do Not Yet Need 489
Anatomy of a Test Case 489
Test Assertions 491
Try It 493
Lesson Requirements 493
Hints 493
Step-by-Step 494
SECTION V: REFERENCE
APPENDIX A: TESTING YOUR APP ON A DEVICE 507
APPENDIX B: BETA TESTING WITH TESTFLIGHT 527
APPENDIX C: APP STORE DISTRIBUTION 553
INDEX 569
Lesson 1
Hello iOS!
Hello and welcome to the exciting world of iOS application development. iOS is Apple's operating system for mobile devices; the current version at the time of this writing is 8.0. It was originally developed for the iPhone (simply known as iPhone OS back then), and was subsequently extended and renamed in June 2010 to iOS to support the iPad, iPhone, and iPod Touch.
At its core, iOS is Unix-based and has its foundations in MacOS X, which is Apple's desktop operating system. In fact, both iOS and MacOS X share a common code base. As new versions of mobile operating systems have appeared, Apple has brought over more functionality from MacOS X. This is part of Apple's strategy to bridge the difference between desktop and mobile computing.
With the launch of version 8.0, Apple has not only pushed the boundaries on what is achievable on smart phones and tablet computers, but has also given us a brand new programming language called Swift. This book covers iOS development with Swift only, but at the time of this writing, it is possible to create iOS applications with both the older language Objective-C as well as Swift.
This lesson introduces you to the arena of iOS development.
iOS Developer Essentials
Before you get started on your journey to becoming an iOS developer, you will need some essential resources. This section covers these basic requirements.
A Suitable Mac
To develop apps for the iPhone and the iPad using the official set of tools provided by Apple, you will first need an Intel-based Mac running Mac OS X Yosemite (10.10) with a minimum 4GB of RAM and at least 11GB of free space on your hard disk. You do not need a top-spec model to get started. In fact a Mac Mini or a low-end MacBook will work just fine.
Processor speed is not going to make much difference to you as a developer. You will be better off investing your money in more RAM and hard disk space instead. These are things you can never get enough of. A large screen does help, but it is not essential.
A Device for Testing
If you are reading this book, chances are that you have used an iPhone, iPad, or iPod Touch and probably even own one or more of these nifty devices.
As far as development is concerned, there aren't many differences between developing for any of these devices. The obvious differences are screen size and the fact that only iPhones can make phone calls. When you are starting out as an iOS developer, you will test your creations on the iOS Simulator. The iOS Simulator is an application that runs on your Mac and simulates several functions of a real iOS device (more on this later).
At some point, however, you will want to test your apps on a physical device. As good as the iOS Simulator may be, you must test on a physical device before submitting your app to the App Store.
Another good reason to test on a physical device is that the processor on your Mac is much faster than that on the iPhone/iPad. Your app may appear to execute much faster on your Mac (in the iOS Simulator) than it does on the real thing.
If the app you are going to make is targeted at iPhone users, you can also use an iPod Touch as the test device. These are significantly cheaper than iPhones and for the most part offer the same functionality as their phone counterparts.
Most of Apple's devices support iOS 8; however, iOS 8 is not supported for the following:
- iPhones prior to the iPhone 4S
- iPads prior to the iPad 2
- iPod Touch devices prior to the iPod Touch 5th generation
An iOS Developer Account
To develop your apps you will need to download the latest version of Xcode and the iOS SDK (Software Development Kit). To do this, you must sign up to the Apple Developer Program to become a registered developer.
The signup process is free and you can immediately begin to develop your first apps. Limitations exist as to what you can do for free. To submit your apps to the App Store, get access to beta versions of the iOS/SDK, or test your apps on a physical device, you need to become a paying member.
Most of the concepts and apps presented in this book will work just fine with the free membership. The only exceptions would be examples that require the camera, accelerometer, and GPS for which you would need to try the app on a physical device.
You can choose from two forms of paid membership as a registered Apple Developer: Individual and Enterprise.
Individual
The Individual iOS Developer Program costs $99 a year and is for individuals or companies that want to develop apps that will be distributed through the App Store. You can also test/distribute your apps on up to 100 devices without having to go through the App Store. This form of deployment (without having to submit them to the App Store) is called ad-hoc distribution and is a great way to submit a preview of the app to a client. This form of distribution is covered in detail in Appendix C.
Enterprise
The Enterprise iOS Developer Program costs $299 a year and is for large companies that want to develop apps for internal use and will not distribute these apps through the App Store. With the Enterprise iOS Developer Program there is no restriction to the number of devices on which your in-house application can be installed.
To start the registration process, visit the iOS Dev Center (see Figure 1.1) at .https://developer.apple.com/programs/enroll/
The Official iOS SDK
The Apple iOS SDK (Software Development Kit) is a collection of tools and documentation that you can use to develop iOS apps. The main tools that make up the SDK are:
- Xcode: Apple's integrated development environment (IDE) that enables you to manage your products, type your code, trace and fix bugs (debugging), and lots more.
- Interface Builder: A tool fully integrated into the Xcode IDE that enables you to build your application's user interface visually.
- iOS Simulator: A software simulator to simulate the functions of an iPhone or an iPad on your Mac.
- Instruments: A tool that will help you find memory leaks and optimize the performance of your apps. Instruments are not covered in this book.
In addition to these tools, the iOS SDK also includes extensive documentation, sample code, How-To's, and access to the Apple Developer Forums.
The iOS SDK is available as a free download to registered members (registration is free). However, there are benefits to paid membership, including the ability to debug your code on an iOS device, distribution of your applications, and two technical support incidents a year where Apple engineers will provide you code-level assistance.
Downloading and Installing
You can download and install Xcode 7 for Mac OS X El Capitan and the iOS SDK from the Mac App Store (see Figure 1.2).
If you have a paid membership, you can download the latest version of Xcode as well as prior versions by logging in to the iOS developer portal at .https://developer.apple.com/devcenter/ios/index.action
The Typical App Development Process
Whether you intend to develop iOS apps yourself or manage the development of one, you need to be familiar with the basic steps in the development process (see Figure 1.3). This section introduces these steps briefly.
Writing a Specification
The development of an app begins with a concept. It is good practice to formally put this concept on paper and create a specification. You do not necessarily need to type this specification, although it's a good idea to do so.
At the end of the project you should come back to the specification document to see how the final product that was created compares with the original specification.
As you build your experience developing iOS applications, this difference will become smaller. The specification must address the following points:
- A short description in 200 words or less
- The target audience/demographic of the users
- How will it be distributed (App Store, or direct to a small number of devices)
- A list of similar competing apps
- A list of apps that best illustrate the look-and-feel your app is after
- The pricing model of competing apps and potential pricing for your app
Wireframes and Design
A wireframe is a large drawing that contains mockups of each screen of your app as well as lines connecting different screens that indicate the user's journey through your application.
Wireframes are important because they can help identify flaws in your design early on (before any coding has been done). They can also be used to show potential clients how a particular app is likely to look when it's completed.
There is no right or wrong way to make a wireframe. If it is for your personal use, you can just use a few sheets of paper and a pen. If it is for a client, you might want to consider using an illustration package.
Coding
The actual process of creating an iOS app involves using the Xcode IDE to type your code. iOS apps can be written in either Swift or Objective-C. This book covers iOS development with Swift only.
An iOS app typically consists of...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.