The beginning iOS8 Programming with Swift 中文翻译 - 7

周末两天没有更新,今天继续!

1  Build Your First App  创建你的第一个App

  “The way to get started is to quit talking and begin doing.”     开始就是放弃高谈阔论,开始脚踏实地!

                        – Walt Disney                   - 沃尔特·迪斯尼(迪士尼创始人)

Hello World! Build Your First App Using Swift    你好,世界!用swift创建你的第一个App

By now you should have installed Xcode 6 and some understandings of Swift language. If you haven’t done so, check out the previous chapter about what you need to begin iOS programming. We’ll use Xcode 6.1 (or up) to work on all exercises in this book.

现在你应该已经安装好了Xcode6并且对swift语言有了一定的了解.如果你还没有做到,那么请回顾之前的关于你需要做什么才能开始iOS开发的章节.在这本书中,我们将使用Xcode6.1或以上版本来做所有的练习.

You may have heard of “Hello World” program if you have read any programming book before. Hello World is a program for first-time programmer to create. It’s a very simple program that outputs “Hello, World” on the screen of a device.

如果你之前有读过一些关于开发的书籍,那么你应该知道他们很多都是以"hello worod"来开篇的.Hello world是对于编程初学者来创建的一个程序,那是一个非常简单的只是输出一个"Hello world"在设备的屏幕上.

It’s a tradition in the programming world. So, let’s follow the programming tradition and create a “Hello World” app using Xcode. Despite its simplicity, the “Hello World” program serves a few purposes:

在程序的世界里这是一个传统.所以,让我们跟随着程序的传统,在xcode中创建一个"Hello world" app.尽管他是非常非常的简单的基础的,不过"Hello World"也要为这几个目的而存在.

 

    • It gives you an overview about the syntax and structure of Swift, the new programming language of iOS.      他会让你对swfit的语法和结构有一个大致的了解,一个iOS的新编程语言.

    • It also gives you a basic introduction to the Xcode 6       他同样可以让你对Xcode6环境有一个入门.(基础的介绍)
      environment. You’ll learn how to create a Xcode project and   你将学到如何去创建一个Xcode项目
      lay out your user interface using Storyboard. Even if you’ve    如何使用storyboard定制你的用户界面.
      used Xcode 5 before, you’ll learn what’s new in the latest version of Xcode.  即使你之前使用过Xcode5,你也可以学习到最新版本的Xcode有哪些更新.

    • You’ll learn how to compile a program, build the app and test it using the Simulator.    你将学习到如何编译一个程序,创建一个app以及 如何使用模拟器进行测试.

    • Lastly, it makes you think programming is not difficult. I don’t want to scare you away   最后,它会让你意识到编程不是那么的困难.我不想把你从学习编程的路上给吓跑.

      from learning programming. It’ll be fun.  他是充满乐趣的.

 

Your First App  你的第一个APP                                                                                                                                                                                                   Your first app, as displayed in figure 1-1, is very simple and just shows a “Hello World” button. When user taps the button, the app shows a welcome message. That’s it. Extremely simple but it helps you kick off your iOS programming journey. 

你的第一个app,就像用数字表现1-1一样,是非常简单的,只是展示一个“hello world”按钮。当用户点击这个按钮,app将显示欢迎信息,仅仅如此。极其简单,但是它将帮助你开启你的iOS编程之旅。

It’s normal if you do not understand the source code. Just relax and focus on building your first app. Familiarize yourself with the Xcode environment and Storyboard. I will explain the language as we go along and you will learn how the HelloWorld app works in the next chapter. 

如果你不理解代码的原理是非常正常的。你只需要放轻松,把注意力放在创建你的第一个app上。去让自己熟悉Xcode环境和storyboard,我将在我们进行的过程中解释这个语言并且在下一章节你会学习怎么使hello world运行。

 

Let's Jump Right Into Create a Project   让我们转去创建一个项目吧

First, launch Xcode. If you’ve installed Xcode via Mac App Store, you should be able to locate Xcode in the LaunchPad. Just click on the Xcode icon to start it up.

Once launched, Xcode displays a welcome dialog. From here, choose “Create a new Xcode project” to start a new project: 

第一步,运行Xcode.如果你之前已经在Mac苹果商店安装过Xcode,你应该可以在LaunchPad里找到Xcode,你只需要点击Xcode图标即可启动它。

第一个运行,Xcode将展现一个欢迎界面。从这里,选择“Create a new Xcode project”开始程序:

 

Xcode shows various project template for selection. For your first app, choose “Single View Application” and click “Next”. 

Xcode显示了各种各样的项目模板供你选择,对于你的第一个app,选择“Single View Application” 并且点击“Next”

This brings you to the next screen to fill in all the necessary options for your project. 

这将跳转到一个你的项目中必须设置的界面。

You can simply fill in the options as follows:   你可以遵循下面的介绍来简单的填写设置
Product Name: HelloWorld – This is the name of your app. Organization Name: AppCoda – It’s the name of your organization.  

项目名称:HelloWorld-这是你的APP的名字    组织名称:AppCoda-这是你公司(组织)的名字

Organization Identifier: com.appcoda – It’s actually the domain name written the other way round. If you have a domain, you can use your own domain name. Otherwise, you may use “com.appcoda” or just fill in “edu.self”.

组织的标示符:com.appcoda-这实际上是你的组织的域名反过来写。如果你有一个域名,你可以使用你的域名名字,如果没有,你可以写com.appcoda来填写

 

Bundle Identifier: com.appcoda.HelloWorld - It’s a unique identifier of your app which is used during app submission. You do not need to fill in this option. Xcode automatically generates it for you.

捆绑的标示符:com.appcoda.HelloWorld-这是在你的app提交的时候使用的独一无二的标示符。你不用自己手动填写。Xcode会问你自动生成。

 

Language: Swift – Xcode 6 supports both Objective-C and Swift for app development. As this book is about Swift, we’ll use Swift to develop the project. 

语言:swift : swfit-Xcode6支持Objective-C和swift对app进行开发.这本书是关于swift,我们将使用swift来开发项目.

Devices: iPhone – Select “iPhone” for this project. 

设备:iPhone- 这个项目选择"iPhone"

Use Core Data: [unchecked] – Do not select this option. You do not need Core Data for this simple project. We’ll explain Core Data in later chapters.

使用Core Data: 不要选择这个选项.这个简单的项目是不需要使用Core Data的.我们将在以后的章节解释他.

Click “Next” to continue. Xcode then asks you where to save the “HelloWorld” project. Pick any folder (e.g. Desktop) on your
Mac. You may notice there is an option for source control. Just deselect it. We do not need to use the option in this book. Click “Create” to continue.

点击"Next"继续.Xcode会询问你在哪里保存"Hello World"项目.选择你Mac电脑任意的一个位置去存储.你或许对于版本控制会有一些疑问,你只需不选择他啊,我们在这本书都不会使用到这个选项,点击"Create"继续.

As you confirm, Xcode automatically creates the “Hello World” project. The screen will look like the screenshot shown in figure 1-6. You can ignore the “No matching signing identity found” error. 

得到你的确认后,Xcode自动的创建了"Hello world"项目,在屏幕中可能会看到像下图的屏幕截图.你可以忽略"No matching signing indentity found"错误.

 

posted @ 2015-12-11 09:12  CJDanger  阅读(528)  评论(0编辑  收藏  举报