[文章原地址]
http://funwithobjc.tumblr.com/
个人翻译,难免会有错误,请各位看官海涵,翻译在末尾
本人将在文章的部分地方添加注释,并根据需求增减文章内容,在此对原作者辛勤劳作表示感谢

How to learn Cocoa

This is something any experienced Cocoa developer has been asked at least half a dozen times:

"What’s the best way to learn Objective-C/Cocoa?"

I have two answers to this question:

  1. Be curious
  2. Don’t be satisfied

Be Curious

Curiosity is the heart of learning anything. If you can cultivate a deep curiosity about the Objective-C language and the Cocoa frameworks, then I guarantee that you will have absolutely no problem learning them. I’m not talking about the “oh, wouldn’t it be nice to know how to write iOS apps” kind of curiosity. I’m talking about the “why does the @ sign go there? What’s up with these asterisks all over the place? Why are things done in this order instead of that order” kind of curiosity. Gaining this level of curiosity can be very difficult, especially at first. But without it, you’ll never really understand how everything is working together.

If you’re familiar with an sort of object-oriented programming language, then Objective-C, as a language, shouldn’t be that hard to pick up. Just use get used to the square brackets, and things will look pretty familiar. Learning the frameworks, on the other hand, will take a lifetime. The Cocoa Frameworks (Foundation, AppKit/UIKit, CoreData, CoreFoundation, MapKit, QuickLook, MediaAccess, CoreLocation, etc) are enormously broad. The Foundation framework itself is composed of 173 public classes and 31 protocols. That’s a lot of pre-built code, and that’s just one framework out of a couple dozen! There are some classes you will come to know very intimately (NSStringNSArray,NSDictionary), but even they will surprise you every now and then. Plus, Apple actively develops these frameworks; they’re being improved and optimized and expanded all the time. There will always be more to learn.

Along with the capabilities of the classes, there are patterns to learn. Design patterns describe how classes interact with each other. Some of the first ones you’ll encounter are Model View ControllerDelegation, and Class Clusters. There are many others, and they’re in there for a very good reason. As you come across them, take the time to understand why they’re there.

Do the same with the classes in the frameworks. Explore them. Play with them. Abuse them. Ask yourself:

  • What problem does this solve?
  • How does it solve the problem?
  • Can you use these abilities for anything else?
  • How would you implement this class if you had to? (And then go do it!)

Be curious.

Don’t Be Satisfied

As you learn Cocoa, the code you write will be terrible. Understand that. But don’t accept it. There is always a different way you could do something, and quite often one of those different ways is a better way. Always seek out opportunities to improve your code and to find different and better ways to organize it. Sometimes this will mean rewriting things half a dozen times. But you know what? That’s OK! All developers experience this. If you can learn to not be satisfied with your code, you’ll quickly learn how to iterate over it and make improvements here, tweak some stuff there, maybe rip out some layer of control and totally reorganize it… This is what programming is all about. Don’t be satisfied with how your code looks. Strive to make it a work of art and a thing of beauty.

Final Thoughts

So there you have it! These are my recommendations for how to learn Cocoa. They have served me well, and I think they pretty much summarize what I’ve observed about experienced developers.

Oh, and by the way…

  1. Know what a pointer is.
  2. Memorize the memory management rules.
  3. Never invoke -retainCount.

Welcome to Cocoa.

如何学习Cocoa

这是任何一个牛逼的Cocoa开发者被问了无数次的一个问题:

"有什么最好的方法来学习Object-C/Cocoa?"

对于这个问题,我有两项建议

1.保持好奇

2.不要轻易满足

保持好奇

学习任何事物好奇心都是最好使的.如果你能对Objective-C和Cocoa的框架有着浓厚的兴趣,我敢肯定,你学习它绝对没有一点问题.我不会说"这么编写IOS的程序是不是很酷?"之类,我会说"为什么标示符@放在这里?为什么星号放在那里?为什么事情必须这样做而不能那么做"之类的,达到如此程度的好奇心非常难,尤其是刚开始.但是,如果没有好奇心,你不会真正的懂得那些玩意是怎么运作的.

如果你熟悉一种面向对象的编程语言,那么,Objective-C,作为一种新的语言,学习它不会很难.仅仅需要熟悉方括号的调用函数的方法,那么,他们看起来就会非常类似.学习这些框架,从某种角度上来说,将会耗费很长时间.这个Cocoa的一些框架(Foundation,AppKit/UIKit,CoreData,CoreFoundation,MapKit,QuickLook,MediaAccess,CoreLocation,之类的)内容是非常多的.Foundation框架本身就包含了173个类和31个协议.那些还是预先编译过的代码,仅仅是那一打鸡蛋中的一枚-_-!还有一些类(NSString,NSArray,NSDictionary),现在你可能会感到惊奇,但在将来你将会非常之熟悉.进一步讲,苹果一直活跃于开发这些框架,这些框架一直都在完善.扩展以及优化,所以,需要一直的学习他们.

面对这无数的类,是存在着一种学习模式的.设计模式描述了类与类之间是如何产生联系的.你第一次会遇到的一些设计模式有MVC.代理和类集群(我不知道怎么翻译,没接触过).实际上还有很多其他的设计模式,存在即合理,当你遇到它的时候,多花些时间与它熟悉熟悉吧.

也请你对框架中的类做着同样的事情,探索它们,试着用它们,虐它们,问下你自己:

这个类能解决什么问题?

它如何解决了这个问题?

你能用它们干些别的吗?

在不得不重写类的情况下,怎样去实现这个类?(想好了就去做吧)

保持好奇心.

不要轻易满足

当你学习Cocoa时,开始时你的代码将会很烂,要懂得这个道理,但不要满足于它.你经常可以尝试些别的,且常常能够找到更好的方法.找机会优化你的代码,找不同的和更好的方式来重写它们.有时候,这意味着重写无数遍,但是你知道吗?就应该这样啊.所有的开发人员都会经历这个过程.如果你学会了不轻易满足,你将很快的认识到一遍又一遍的去重写它而得到进步,在这里用尽全力,也许就能一层一层的撕开秘密并最终完全弄懂它...编程就是这档子事.不要满足于你自己写的代码,尽力把他当做一门艺术来做,去体会它的美感.

最后的思考

就这些了!就是我关于学习Cocoa的建议.它们对我很受用,我想,这就是我总结出的牛逼开发者的经验了吧.

哦,顺便提提...

1.要知道什么叫指针

2.记住内存管理规则

3.永远也不要尝试判断retainCount值(来确定一个对象有没有释放掉)

欢迎来到Cocoa的世界

[翻译] 如何学习Cocoa的更多相关文章

  1. Oracle User Management FAQ翻译及学习笔记

    转载 最近了解到AME 的东西,很迫切,先转载一篇 [@more@] Oracle User Management FAQ翻译及学习笔记 写在前面 本文主要是翻译的英文版的Oracle User Ma ...

  2. [翻译]深度学习的机器(The learning machines)

    学习的机器 用大量的数据识别图像和语音,深度学习的计算机(deep-learning computers) 向真正意义上的人工智能迈出了一大步. Nicola Jones Computer Scien ...

  3. Key Technologies Primer 读书笔记,翻译 --- Struct 学习 1

    原文链接:https://struts.apache.org/primer.html 本来想写成读书笔记的,结果还是变成翻译,谨作记录,学习.   1.HTML -- 见我前面文章 2.Interne ...

  4. StarGAN: Unified Generative Adversarial Networks for Multi-Domain Image-to-Image Translation - 1 - 多个域间的图像翻译论文学习

    Abstract 最近在两个领域上的图像翻译研究取得了显著的成果.但是在处理多于两个领域的问题上,现存的方法在尺度和鲁棒性上还是有所欠缺,因为需要为每个图像域对单独训练不同的模型.为了解决该问题,我们 ...

  5. 《Swift程序设计语言》中国翻译和学习笔记page23

    ·<The Swift Programming Language>中文翻译及读书笔记,附件中为英文原版教程 因21页之前内容和技术关系不大,不做翻译整理,从第21页開始 · 页 1 本页主 ...

  6. face recognition[翻译][深度学习理解人脸]

    本文译自<Deep learning for understanding faces: Machines may be just as good, or better, than humans& ...

  7. 【原创】Odoo开发文档学习之:构建接口扩展(Building Interface Extensions)(边Google翻译边学习)

    构建接口扩展(Building Interface Extensions) 本指南是关于为Odoo的web客户创建模块. 要创建有Odoo的网站,请参见建立网站;要添加业务功能或扩展Odoo的现有业务 ...

  8. React 编程思想翻译及学习笔记

    第一步:把UI图按组件层次结构拆分开 FilterableProductTable (橙色): 包含整个例子 SearchBar (蓝色): 接收所有用户输入 ProductTable (绿色): 基 ...

  9. 【原创】Odoo开发文档学习之:ORM API接口(ORM API)(边Google翻译边学习)

    官方ORM API开发文档:https://www.odoo.com/documentation/10.0/reference/orm.html Recordsets(记录集) New in vers ...

随机推荐

  1. php中直接执行mysqli_init()也是报Property access is not allowed yet的错误。

    xdebug.auto_trace = On 和 xdebug.profiler_enable = On注释掉就OK了,不知道这两个配置项是干嘛的

  2. Phoenix的安装使用与SQL查询HBase

    一. Phoenix的简介 1. 什么是phoenix 现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要说Phoenix.phoen ...

  3. 【LOJ】#2070. 「SDOI2016」平凡的骰子

    题解 用了一堆迷之复杂的结论结果迷之好写的计算几何???? 好吧,要写立体几何了 如果有名词不懂自己搜吧 首先我们求重心,我们可以求带权重心,也就是x坐标的话是所有分割的小四面体的x坐标 * 四面体体 ...

  4. LoadRunner FAQ2

    LR中参数的定义和赋值 1.参数的赋值和取值 lr_save_string("hello world","param"); lr_eval_string(&qu ...

  5. Bootstrap进阶七:LESS语法详解

    1.变量 2.混合 3.带参数混合 4.模式匹配和导引表达式 5.嵌套规则 6.运算 7.Color函数 8.Math函数 9.命名空间 10.作用域 11.注释 12.Importing 13.字符 ...

  6. poj-2253-poj-1797_最短路练习

    title: poj-2253-poj-1797_最短路练习 date: 2018-11-17 11:48:51 tags: acm 刷题 categories: ACM-最短路 概述 一道最短路的变 ...

  7. C#中的特性 (Attribute) 入门 (一)

    C#中的特性 (Attribute) 入门 (一) 饮水思源 http://www.cnblogs.com/Wind-Eagle/archive/2008/12/10/1351746.html htt ...

  8. iOS 9应用开发教程之ios9中实现按钮的响应

    iOS 9应用开发教程之ios9中实现按钮的响应 IOS9实现按钮的响应 按钮主要是实现用户交互的,即实现响应.按钮实现响应的方式可以根据添加按钮的不同分为两种:一种是编辑界面添加按钮实现的响应:另一 ...

  9. ELK收集openstack日志

    1.安装jdk 每个openstack服务器需要安装jdk,我安装的版本jdk-7u71-linux-x64.rpm 2.安装.配置Elastic Search install https://dow ...

  10. [ 原创 ]Centos 7.0下启动 Tomcat8.5.15

    1.打开8080端口  firewall-cmd --zone=public --add-port=8080/tcp --permanent 2.重启防火墙   firewall-cmd --relo ...