Skip to main content
main-content

Über dieses Buch

Swift OS X Programming for Absolute Beginners is your step-by-step guide to learning how to code using Swift, Apple's hottest new programming language. This book will not only teach complete programming novices how to write OS X programs, but it can also help experienced programmers moving to the Macintosh for the first time. You will learn to understand the principles of programming, how to use Swift and Xcode, and how to combine your knowledge into writing OS X programs.

If you've always wanted to learn coding but felt stymied by the limitation of simplistic programming languages or intimidated by professional but complicated programming languages, then you'll want to learn Swift. Swift is your gateway to both Macintosh and iOS app development while being powerful and easy to learn at the same time, and Swift OS X Programming for Absolute Beginners is the perfect place to start - add it to your library today.

Inhaltsverzeichnis

Frontmatter

Chapter 1. Understanding Programming

Abstract
Programming is nothing more than writing step-by-step instructions for a computer to follow. If you’ve ever written down the steps for a recipe or scribbled directions for taking care of your pets while you’re on vacation, you’ve already gone through the basic steps of writing a program. The key is simply knowing what you want to accomplish and then making sure you write the correct instructions that will tell someone how to achieve that goal.
Wallace Wang

Chapter 2. Getting to Know Xcode

Abstract
To write programs in Swift for the Macintosh, you need to use Xcode. Apple developed Xcode as a professional programming tool that they give away free to encourage everyone to write software for OS X and iOS. Despite being a free program, Xcode is a powerful program used by major companies including Microsoft, Adobe, Google, and even Apple. With Xcode on a Macintosh, you have one of the most powerful programming tools for creating OS X programs and iOS apps.
Wallace Wang

Chapter 3. The Basics of Creating a Mac Program

Abstract
Whatever type of OS X program you want to create, such as a video game or a custom program for lawyers or stock brokers, you’ll always go through the same basic steps. First, you need to create an OS X project. This creates a bare-bones OS X program that includes a generic user interface.
Wallace Wang

Chapter 4. Getting Help

Abstract
The best way to learn any new skill is to have someone show you what you need to learn. Since that’s not always possible, you’ll be happy to know that Xcode comes with plenty of built-in help features to make using Xcode less stressful and more enjoyable.
Wallace Wang

Chapter 5. Learning Swift

Abstract
To write any program, you need to choose a programming language. A programming language lets you define commands for the computer to follow. There’s no one “best” programming language because every programming language is meant to solve a specific problem. That means that a programming language may be great at solving certain types of problems, but horrible at solving other types of programs.
Wallace Wang

Chapter 6. Manipulating Numbers and Strings

Abstract
Every program needs to store data temporarily in variables. However, for a program to be useful, it must also manipulate that data somehow to calculate a useful result. A spreadsheet lets you add, subtract, multiply, and divide numbers. A word processor manipulates text to correct your spelling and format text. Even a video game responds to joystick movements to calculate a new position for the player’s object such as a cartoon person, airplane, or car. Using data to calculate a new result is the whole purpose of every program.
Wallace Wang

Chapter 7. Making Decisions with Branches

Abstract
After a program receives data, it needs to manipulate that data somehow to return a useful result. Simple programs manipulate data the same way, but more complicated programs need to make decisions on how to manipulate that data.
Wallace Wang

Chapter 8. Repeating Code with Loops

Abstract
The basic goal of programming is to write as little code as possible that does as much as possible. The less code you write, the easier the program will be to understand and modify later. The more your code does, the more powerful your program will be.
Wallace Wang

Chapter 9. Arrays and Dictionaries

Abstract
Almost every program needs to accept data so it can manipulate that data and calculate a useful result. The simplest way to store data temporarily is through variables that can store numbers or text strings. However, what if you need to store multiple chunks of data such as a list of names or a list of product numbers? You could create multiple variables like this:
Wallace Wang

Chapter 10. Tuples, Sets, and Structures

Abstract
Variables are good for storing individual chunks of data while arrays and dictionaries are good for storing lists of the same data type. For greater flexibility, Swift also offers additional data structures called tuples and sets.
Wallace Wang

Chapter 11. Creating Classes and Objects

Abstract
The heart of programming in Swift using Xcode is object-oriented programming. The main idea is to divide a large program into separate objects where each object ideally represents a physical entity. For example, if you were creating a program to control a car, one object might represent the car’s engine, a second object might represent the car’s entertainment system, and a third object might represent the car’s heating and cooling system.
Wallace Wang

Chapter 12. Inheritance, Polymorphism, and Extending Classes

Abstract
In Chapter 11 you learned how objects were created from classes and how classes define properties and methods. To protect its data and methods from other parts of a program, an object isolates or encapsulates its code. Encapsulation is one prime advantage of object-oriented programming because it creates self-contained code that you can easily modify or replace without affecting any other part of a program.
Wallace Wang

Chapter 13. Creating a User Interface

Abstract
While it’s possible to create programs that don’t need to interact with a user at all (such as a program that controls a traffic light), it’s far more common to create programs that display a user interface of some kind. Typically that means showing a window filled with different items such as labels to display text, text fields to allow the user to type something in, and buttons or pull-down menus to give the user control over the program.
Wallace Wang

Chapter 14. Working with Views and Storyboards

Abstract
The most common part of every program’s user interface is a window that displays items such as buttons and text fields. In Xcode, windows are called views. In all but the simplest programs, a user interface will likely consist of two or more windows or views. That means your program needs to know how to open additional windows and close them again.
Wallace Wang

Chapter 15. Choosing Commands with Buttons

Abstract
Every program needs to give the user a way to control the computer. In the old days, that meant knowing how to type the proper commands to make a program work, but with today’s graphical user interfaces, the easier way to control a program is to choose from a list of available commands. The simplest way to give a command to a program is through a button.
Wallace Wang

Chapter 16. Making Choices with Radio Buttons, Check Boxes, Date Pickers, and Sliders

Abstract
Rather than let the user choose a specific command through a button, user interfaces often give choices to pick. Such choices let the user pick one or more options, such as customizing the way a program works. When a user interface needs to offer multiple choices, the two most common ways to offer options are through radio buttons and check boxes.
Wallace Wang

Chapter 17. Using Text with Labels, Text Fields, and Combo Boxes

Abstract
When a program can offer a limited range of valid options to the user, that’s when you want to use check boxes, radio buttons, date pickers, or sliders. However, sometimes a program needs to allow the user to type in data that can never be predicted ahead of time, such as a person’s name. When a program needs to allow the user to type in data, that’s when you need to use a text field or a combo box.
Wallace Wang

Chapter 18. Using Alerts and Panels

Abstract
With every program, you’ll need to design the unique features of your program while letting the Cocoa framework worry about making your program look and behave like a standard OS X program. Two common features of nearly every OS X program are alerts and panels.
Wallace Wang

Chapter 19. Creating Pull-Down Menus

Abstract
Pull-down menus represent the standard way to interact with an OS X program. While your program may display buttons to represent commands, too many buttons can clutter the screen. To avoid trying to cram multiple buttons on the screen, you can group related commands in multiple pull-down menus. By default, Xcode creates every OS X project with the following pull-down menu titles:
Wallace Wang

Chapter 20. Protocol-Oriented Programming

Abstract
When Apple introduced Swift during their Worldwide Developer’s conference in 2014, they promoted it as an easier, safer, and faster programming language for iOS, OS X, and watchOS development than Objective-C. While both Swift and Objective-C allow object-oriented programming, Swift goes one step further and offers protocol-oriented programming as well.
Wallace Wang

Chapter 21. Defensive Programming

Abstract
Programmers tend to be optimistic because when they write code, they assume that it will work correctly. However, it’s often better to be more pessimistic when it comes to programming. Instead of assuming your code will work the first time, it’s safer to assume your code won’t work at all. This forces you to be extra careful when writing Swift code to make sure it does exactly what you want and doesn’t do anything unexpected.
Wallace Wang

Chapter 22. Simplifying User Interface Design

Abstract
Designing a user interface can be challenging. Not only do you need to design a user interface that’s easy to use, but you also need to design an adaptive user interface that can respond to any changes the user might make to a window’s size. If the user shrinks a window, your user interface must shrink accordingly without cutting any items off. If the user enlarges a window, your user interface must expand accordingly to maintain a consistent appearance.
Wallace Wang

Chapter 23. Debugging Your Programs

Abstract
In the professional world of software, you’ll actually spend more time modifying existing programs than you ever will creating new ones. When writing new programs or editing existing ones, it doesn’t matter how much experience or education you might have because even the best programmers can make mistakes. In fact, you can expect that you will make mistakes no matter how careful you may be. Once you accept this inevitable fact of programming, you can learn how to find and fix your mistakes.
Wallace Wang

Chapter 24. Planning a Program Before and After Coding

Abstract
Before you invest days, weeks, months, or years working on a program, make sure the world even wants your program in the first place. If you’re writing a program for yourself, then you can ignore what the rest of the world thinks. However, if you plan on selling your programs to others, make sure your program has a future before you even begin.
Wallace Wang

Backmatter

Weitere Informationen

Premium Partner

    Bildnachweise