Comments (2)
方法命名
replaceObjectAtIndex:... withObject:...
运行[mArray replaceObjectAtIndex:1 withObject:@"Hello"]; 数组mArray索引1中的对象已经变成了字符串@"Hello". (这个方法只能援引那些有效的索引,原来索引中应当有对象,我们才可以用这个方法置换进新的对象)。
你可能已经发现了,Objective-C语言的方法名字好似句子填空。当你要使用一个方法,只要你填上你需要的值构成一个有意义的『句子』即可。
这种给方法命名的方法来源于Smalltalk(一种由Xerox公司开发的面向对象的系统),也是Objective-C语言的一大特色,它可以大大增强代码的描述性。当创建自己的方法时,你也应当尽量按照这种方法命名,不仅可以提高代码的可读性,而且使你的程序便于维护。
from technotes.
内存管理
你的程序并非你的设备上唯一运行的程序,而RAM又是珍贵的资源。当你的程序不再需要占用内存的时候,你需要把内存还给系统。即使设备上只运行了你的一个程序,拥挤的内存也会把你的程序挤到角落,设备的相应速度也会变得很慢。
当你的程序创建出一个对象,对象会占用内存,你要在对象不被使用后释放出内存空间。尽管并不是那么好确定一个对象是否不再被使用了。比如在程序执行过程中你的对象会被多个其它对象引用,当被其它对象应用的可能性还存在时就不能销毁这个对象(可能导致程序崩溃或出现不可预见的结果)。
引用计数 (reference counting)
为了处理那些不在被使用的对象,Cocoa给每个对象关联了一个计数器,被称为『引用计数器』。要使对象的引用计数器增加数值,发送一条「retain message」;减少引用计数则发送「release message」。
Cocoa还提供了一个『autorelease pool』的机制,可以发送延迟的释放信息。使用该机制发送自动释放信息需要将对象注册到autorelease pool中。
from technotes.
Related Issues (20)
- Groovy in Gradle
- HTTP API自动化测试
- HTTPS安全在哪里? HOT 1
- FlatBuffers
- Android里面的Deep linking HOT 1
- Android原理篇
- 跨平台方案
- 如何提高Android代码的可测试性?
- 如何提高Android代码的可测试性?
- Android应用架构选型(MVC MVVM MVP Flux Clean) HOT 6
- Android任务列表中滑动删除应用后都发生了什么?
- Android Patch方案比较
- 基于AOP的方法级自动埋点
- Android tricks
- Android Router HOT 1
- 爬虫环境搭建
- React & Redux
- JavaScript引擎 HOT 3
- 浏览器内核 HOT 7
- 移动web tips
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from technotes.