When enumerating an NSArray:
Use for (id object in array) if enumerating forwards.
Use for (id object in [array reverseObjectEnumerator]) if enumerating backwards.
Use for (NSInteger i = 0; i < count; i++) if you need to know the index value, or need to modify the array.
Try [array enumerateObjectsWithOptions:usingBlock:] if your code might benefit from parallel execution.
When enumerating an NSSet:
Use for (id object in set) most of the time.
Use for (id object in [set copy]) if you need to modify the set (but it will be slow).
Try [set enumerateObjectsWithOptions:usingBlock:] if your code might benefit from parallel execution.
When enumerating an NSDictionary
Use [dictionary enumerateKeysAndObjectsUsingBlock:] most of the time.
Use for (id key in [dictionary allKeys]) if you need to modify the dictionary.
Try [dictionary enumerateKeysAndObjectWithOptions:usingBlock:] if your code might benefit from parallel execution.
Not only are these methods the fastest available, but they’re also all very clear and readable. So remember, sometimes it’s not a choice between writing clean code and fast code; you may find that you can get the best of both worlds.
from:Nick Lockwood
http://iosdevelopertips.com/objective-c/high-performance-collection-looping-objective-c.html
分享到:
相关推荐
资源名称:iOS开发系列视频教程:Objective-C 资源目录: 【】无限互联iOS开发视频教程-Objective-C部分(第一部分) 【】无限互联iOS开发视频教程-Objective-C部分(第七部分) 【】无限...
苹果iOS开发中文电子书推荐:3--Objective-C基础中文教程PART1
苹果iOS开发中文电子书推荐:3--Objective-C基础中文教程PART2
苹果iOS开发中文电子书推荐:3--Objective-C基础中文教程PART3
iOS和macOS性能优化:Cocoa、Cocoa Touch、Objective-C和Swift(英文版)
iOS 7 Programming Fundamentals: Objective-C, Xcode, and Cocoa Basics by Matt Neuburg (Author) Publisher: O’Reilly Media (October 2013) Language: English ISBN-10: 1491945575 ISBN-13: 978-...
iOS 和 macOS 性能优化书。iOS and macOS Performance Tuning Cocoa, Cocoa Touch, Objective-C, and Swift
Objective-C高级编程 iOS与OS X多线程和内存管理.pdf
希望这个简单的Objective-C语言教程能够为你提供一个入门的起点。Objective-C是一种面向对象的编程语言,广泛应用于Mac OS和iOS开发。通过学习Objective-C的基本语法、类和...祝你在学习Objective-C的过程中取得成功!
人民邮电出版社《Objective-C基础教程》(含源代码) 影印版的PDF文件+原书附带的代码,特别适合学习iPhone,iPad入门开发学习~
《Objective-C编程之道ios设计模式解析》电子书讲述了ios设计中常用的设计模式,希望可以帮助大家!
《Objective-C 程序设计(第4版)》已经为iOS 5和Xcode4.2中的重大变更做了全面更新,最大的改动是引入了自动引用计数(ARC),并详细说明了如何在Objective-C编程过程中使用ARC提升和简化内存管理。
最全最新版 Objective-C编程之道IOS设计模式解析.pdf
Objective-C 是一种通用、面向对象的编程语言,广泛应用于 macOS 和 iOS 等苹果平台的开发中。它是 C 语言的超集,结合了 Smalltalk 式的消息传递机制和 C++ 的特性。Objective-C 是苹果公司采用的主要编程语言之一...
Objective-C iOS StoreKit 原生内购订阅代码封装,语言是Objective-C,内含demo,可以二次封装给其他开发工具使用. 支持Unity3D,cocos,xamarin...等开发工具进行二次封装使用.
Objective-C 2.0之前需要了解的:关于Obj-C内存管理的规则。
Objective-C Programming: The Big Nerd Ranch Guide (2nd Edition).epub (epub 格式) Want to write iOS apps or desktop Mac applications? This introduction to programming and the Objective-C language is ...
Objective-C高级编程 iOS与OS X多线程和内存管理.
Programming in Objective-C, 第四版,ePub格式方便在iPad看。 第四版主要更新了 iOS5 与 ARC 的内容,与最新的 Xcode 4.5 匹配。 目录: Table of Contents 1 Introduction Part I: The Objective-C Language 2...