logo资料库

Objective C Memory Management Essentials 无水印pdf.pdf

第1页 / 共200页
第2页 / 共200页
第3页 / 共200页
第4页 / 共200页
第5页 / 共200页
第6页 / 共200页
第7页 / 共200页
第8页 / 共200页
资料共200页,剩余部分请下载后查看
Cover
Copyright
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
1: Introduction to Objective-C Memory Management
Why do we need memory management in Objective-C?
An object's ownership and life cycle
Ownership of object and reference counting
What's a memory leak and why pay attention to it?
What is an Object within Objective-C?
Summary
2: Automatic Reference Counting
What is ARC and how does it work?
How ARC looks
Project settings for ARC
A memory model in Objective-C
What you need to know about ARC and weak references
Summary
3: Using Autorelease Pools
Understanding the autorelease pool mechanism
Autorelease pool mechanism
Reducing peak memory footprint with autorelease pool blocks
Overview of Apple autoreleased classes
NSRunLoop
NSException
ARC and autorelease
Autorelease pool blocks and threads
Summary
4: Object Creation and Storage
Creation and initialization of objects
What is a class?
Classes
Object immutability
Object mutability
Inheritance
Convenience initializers
An Objective-C programmer's responsibility
The singleton pattern
Creating @property
Creating custom methods
String formatting
Summary
5: Managing Your Application Data
Device memory
Image optimization
Lazy loading
Control creation
Caching
SDWebImage
Object serialization
SQLite
SQLite versus Core Data
Summary
6: Using Core Data for Persistence
Why use Core Data?
Understanding Core Data concepts
Putting it into practice
Getting into the code
Saving data into the persistent store
Deleting data from the persistent store
Updating data
Summary
7: Key-value Programming Approaches
What is key-value coding or KVC?
The NSKeyValueCoding protocol
Compliance of attributes and one-to-one relationships
Compliance of indexed one-to-many relationships
Compliance of unordered many-to-many relationships
Advantages of key-value coding
Disadvantages of key-value coding
Manual subsets of NSKeyValueCoding behavior
Advantages of creating your own lookup path
Disadvantages of creating your own lookup path
Associated objects
Advantages of using associated objects
Disadvantages of using associated objects
Selectors as keys
Advantages of using selectors as keys
Disadvantages of using selectors as keys
Maximum flexibility and handling unusual keys/values
Advantages of doing your own implementation
Disadvantages of doing your own implementation
Key-value observing
Implementing key-value observing
Performance considerations
Summary
8: Introduction to Swift
Welcome to Swift
Basics of Swift
Variable declaration
Iterating statements
Conditional statements
Functions
Classes and structures in Swift
Closures
Memory management in Swift
Summary
9: Memory Management and Debugging
Memory leaks
Strong/weak references
Retain cycles
Memory overuse
Using the debugger and breakpoints
Collecting data on your app
Plumbing memory leaks
Using the LLVM / Clang Static Analyzer
Using NSZombie
Summary
10: Tips and Tricks for Memory Management
Objective-C, C, and memory management
Getters and setters
The property attribute in Objective-C
Performance guidelines
Don't overthink about memory management
When to avoid KVC and KVO
Summary
11: Features of Xcode 6
Introducing Xcode 6
What's new in storyboard
Allowing storyboard or the NIB file to replace launch images
Launching images from your app
Universal storyboards
Debugging in Xcode 6
Debug Gauges
What's new in Interface Builder
Playground for Swift
Summary
Index
www.it-ebooks.info
Objective-C Memory Management Essentials Learn and put into practice various memory management techniques in Objective-C to create robust iOS applications Gibson Tang Maxim Vasilkov BIRMINGHAM - MUMBAI
Objective-C Memory Management Essentials Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: March 2015 Production reference: 1190315 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-712-5 www.packtpub.com www.it-ebooks.info
Credits Project Coordinator Leena Purkait Proofreaders Simran Bhogal Maria Gould Indexer Hemangini Bari Graphics Sheetal Aute Production Coordinator Melwyn D'sa Cover Work Melwyn D'sa Authors Gibson Tang Maxim Vasilkov Reviewers Emil Atanasov Christine M. Gerpheide Commissioning Editor James Jones Acquisition Editor James Jones Content Development Editor Amey Varangaonkar Technical Editor Vijin Boricha Copy Editor Janbal Dharmaraj www.it-ebooks.info
About the Authors Gibson Tang grew up loving technology after getting his hands on an old Apple II when he was still a young kid. Since then, he has never stopped keeping pace with technology, and after he coded his first "Hello World" program, he has been hooked on programming ever since. Following his studies at Nanyang Polytechnic and Singapore Institute of Management and serving a 6-year stint in the Republic of Singapore Navy (RSN), he honed his development skills creating software and games for Yahoo! and other Fortune 500 companies. In 2010, he founded Azukisoft Pte Ltd in Singapore to focus on mobile application development. Since then, he has developed countless mobile applications and games for start-ups and big companies both in USA and Singapore. Apart from programming, he indulges in various hobbies such as soccer, computer games, and jogging in order to get his regular dose of Vitamin D and to see the sun once in a while. Occasionally, he would be on Steam or Battle.net blowing off some steam by slaying monsters and killer robots after a day of programming. I would like to thank the many people who have contributed to my knowledge of programming over the years. Some honorable mentions go out to the geeks and nerds of Hackerspace.sg as they have kept me in stitches with their geek jokes and anime. Next, a great thank you goes to Mugunth Kumar, who is an overflowing fountain of knowledge of all things related to Objective-C. Also, thanks to Subhransu Behera, the organizer of the iOS Dev Scout meetup group in Singapore and finally, to my colleagues at Azukisoft Pte Ltd, namely Igor and Dimitry, who have never failed to amaze me with all their new knowledge and things they have learned over the course of their work with me. www.it-ebooks.info
Maxim Vasilkov is a mobile software developer in Azukisoft Pte Ltd. He started programming over 10 years ago. He started with iOS when the SDK was made publicly available, and from that time onwards, he developed a passion for making mobile apps. He is also experienced with other programming languages and has expertise working with various team sizes, which gave him the opportunity to look at different approaches to programming. Outside of work, he is a proud father of beautiful triplets, Anna, Maria, and Victoria, who are now 4 years old. This has helped him try out mobile games for kids and enables him to be an expert in mobile games for kids. I would like to dedicate this chapter to my lovely wife, Irina, and my three princesses, Anna, Maria, and Victoria. Last but not least, I'd like to thank my colleagues at Azukisoft Pte Ltd and Gibson Tang for giving me an opportunity to work on a lot of challenging projects. www.it-ebooks.info
About the Reviewers Emil Atanasov is an IT consultant who has strong experience with mobile technologies. He is doing his MSc at RWTH Aachen University, Germany. He has worked for several huge USA companies and has been a freelancer for years. He has experience in software design and development, and personally, he has worked on the improvement of many mobile apps. At the moment, he is focused on the rapidly developing mobile sector. As an Android team leader and senior developer, Emil was leading a team that was developing a part of the Nook Color firmware. This was an e-magazine/e-book reader, which supports the proprietary Barnes & Nobel and many other e-book formats. Many of the apps that Emil has designed are using Flurry API to track different users' statistics. Based on this experience, he is one of the people behind the Getting Started with Flurry Analytics book. I want to thank my family and friends for being so cool. Thank you for supporting me even though I'm such a bizarre person, who is investing so much of his time in the computer world. Thank you, guys! Christine M. Gerpheide is a software development engineer at Amazon Web Services. She completed her master's in computer science and engineering with honors from Eindhoven University of Technology in the Netherlands, before which she worked in Greece as a web developer. During her career, Christine has worked on a wide range of software, including service-oriented architectures, model-driven engineering, and mobile development. During her free time, she hikes, runs, and plays violin. Other books reviewed by Christine include TYPO3 Templates by Packt Publishing, and she has presented at a number of scientific and open source conferences. www.it-ebooks.info
www.PacktPub.com Support files, eBooks, discount offers, and more For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM https://www2.packtpub.com/books/subscription/packtlib Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access. www.it-ebooks.info
分享到:
收藏