iOS 6 By Tutorials ---第二章--【第一彈】--【翻譯】

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   os   使用   

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,這裡的代碼與之前的相似。

 

-----》》》》》》》》》》》》》明天繼續》》》》》————

 

iOS 6 By Tutorials ---第二章--【第一彈】--【翻譯】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.