[文章原地址]
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. entityframework导航属性筛选

    ); //会在sql代码中生成Street = "上海"代码 var address1 = db.Entry(user).Collection(b => b.Address) ...

  2. Java 内存模型基础

    一.并发编程模型的两个关键问题 1. 线程之间如何通信 通信是指线程之间以何种机制来交换信息. 在命令式编程中,线程之间的通信机制有两种:共享内存和消息传递. 在共享内存的并发模型里,线程之间共享程序 ...

  3. 【基础知识】Asp.Net基础三

    服务器端控件一般用于访问量不高的网站,要做到物尽其用. 服务器端控件: FIleUpload控件:向服务器上传文件 if (this.FileUpload1.HasFile) { // Path.Ge ...

  4. 特殊字符导致jquery-mobile 挂起(firefox控制台报错 malformed URI sequence)

    同事遇到一个问题,刷新页面导致页面挂起,浏览器控制台报错 malformed URI sequence, 经排查发现是引用jquery-mobile js引起的问题, 有一些中文参数在url中,当页面 ...

  5. BZOJ1878: [SDOI2009]HH的项链[树状数组+离线 | 主席树]

    题意: 询问区间不同种类颜色数 [2016-11-15] 离线好厉害 对于每一个区间询问,一个数只考虑一次,那么考虑他最后出现的一次 将询问按r排序 从1到n扫描,用树状数组维护一个位置应不应该考虑( ...

  6. java设计模式(三)模板模式

    抽象类中公开定义了执行它的方法的方式,子类可以按需求重写方法实现,但调用将以抽象类中定义的方式进行,典型应用如银行办理业务流程.冲泡饮料流程.下面给出简单例子,用沸水冲泡饮料,分为四步:将水煮沸.泡制 ...

  7. 鸟哥的私房菜:Bash shell(三)-命令别名与历史指令

    一  命令别名设定: alias, unalias 命令别名是一个很有趣的东西,特别是你的惯用指令特别长的时候!还有, 增设预设的属性在一些惯用的指令上面,可以预防一些不小心误杀档案的情况发生的时候! ...

  8. Redis Cluster笔记

    Redis Cluster .0搭建与使用 介绍: 特性:使用数据分片(sharding)而非一致性哈希(consistency hashing)来实现: 一个 Redis 集群包含 个哈希槽(has ...

  9. Codeforces Round #354 (Div. 2) A. Nicholas and Permutation 水题

    A. Nicholas and Permutation 题目连接: http://www.codeforces.com/contest/676/problem/A Description Nichol ...

  10. hdu 1394 Minimum Inversion Number 逆序数/树状数组

    Minimum Inversion Number Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showprob ...