iOS 6 By Tutorials ---第二章--【第一弹】--【翻译】

Chapter 2 :Programming in Modern Objective-C    

By Matthijs Hollemans 

第二章:最新的OC编程

Old habits die hard, but if you’re still writing Objective-C in the style that was practiced when iPhone OS 2.0 first came out (mid-2008), then you’re missing out on some really useful advancements that were made to the language recently.

Languages are living things, and computer languages like Objective-C are no exception. As far as programming languages go, Objective-C is already quite the elder – about 30 years old! For a while it was left to wither and die... until the success of the iPhone breathed new life into it. Amazingly, Objective-C is now one of the most popular languages in the world.

Ever since Apple took charge of the compiler tools used to create iOS apps (GCC in the past, now LLVM and Clang), the company has invested heavily in making the Objective-C faster, simpler and better. With every recent new version of Xcode, the language has seen refinements that make it easier for us to write our apps.

Because you may have missed some of these changes – a lot of books and code samples still cling to the old style of doing things due to habit or lack of updates – this chapter will show you how to make the most of these new techniques.

You will review the improvements that were made to Objective-C over the years – including the hot new stuff in Xcode 4.5 – and learn to take advantage of these features to make your code shorter (less typing!), simpler, and easier to debug.

After reading this chapter, you will have an elegant and modern Objective-C coding style you can be proud of. Read along – don’t let your programming style get rusty! 

旧习难改,如果你还在使用iPhone OS 2.0(2008年中)刚出现的时候的OC习惯,那你将会错过最新语言的一些有用的改进。

语言是活动的东西,OC语言也不例外。至于编程语言,OC已经是比较老的语言了,它已经30岁了!曾有一段时间它比较萧条直到直到iPhone的成功为它注入了新的活力,现在OC是世界上最流行的编程语言之一。

自从苹果负责编译器工具用于创建iOS应用程序(GCC在过去,现在LLVM和叮当声),公司已经投入巨资使objective - c更快,更简单,更好。

与每一个Xcode的最新版本,语言已经细化,方便我们编写应用程序。

很多书或是代码因为还是习惯或是对新知识的缺乏还在使用老的代码风格,这可能会让你错过一个变化。这个章节将会告诉你如何使用这些新技术。

你将会回顾多年来OC发生的改变--包括最新最热的Xcode4.5,然后利用这些新特性使你的代码更短,更简洁,更便于调试!

学习本章节后,你会有值得你骄傲的良好的最新的OC编码风格。保持阅读,不要让你的编码风格生锈!

The Numberpedia app

In this chapter you are going to take an app that is written in old-fashioned Objective-C style from the time of iPhone OS 2.0 (also known as the “Stone Age”) and modernize it to take advantage of the exciting new features in Xcode 4.5 and the Clang 4.0 compiler. 

The app itself is very simple. It’s called “Numberpedia,” and it consists of two screens. The first screen contains a table view that lists interesting numbers (that is, if you like numbers). Tap on a row and a “detail” screen opens that lets you edit the number, just in case you know better than Pythagoras. 

在这一章你将会把一个在iPhone OS2.0时期的旧的OC语言编写的一个应用,通过xcode4.5的新特性对它进行改进。

这个应用本身非常简单。名字是“Numberpedia”,它包括两个页面。第一个页面是一个由有趣的数字(或者说,你喜欢的数字)构成的tableview。点击某一行就会跳转到一个可以让你编辑数字(只有你的勾股定理比较好的时候)‘详情’页面。

                                  

You can find the source code for this app with this chapter’s resources – open it up and take a quick look around before continuing.

You’ll notice there are essentially two classes: MasterViewController for the main list and DetailViewController for the screen that lets you edit the numbers. The view controllers are designed in the Storyboard Editor and segue from one to the other.

The MasterViewController contains a UITableView, and most of what it does happens in the table view data source methods. If you have ever worked with a table view before, then this code will look very familiar. 

在这张的资源中找到这个应用的代码-打开这个应用,在运行之间大概看一下。

你会发现本质上这有两个类:主列表的MasterViewController类和让你编辑数字的DetailViewController类。这些控制器是在Storyboard中设计并通过segue进行跳转的。

MasterViewController类包括一个UITableView,并且要实现他的代理方法。如果你之前用过Table,这里的代码与之前的相似。

 

-----》》》》》》》》》》》》》明天继续》》》》》————

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。