1. Trang chủ
  2. » Công Nghệ Thông Tin

Core data storage management icloud 866 pdf

246 35 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 246
Dung lượng 14,49 MB

Nội dung

Early Praise for Core Data, Second Edition I learned Core Data reading the first edition of this book It has long been my go-to reference, but a lot has changed since the first edition hit the shelves The coverage of iOS and iCloud is a welcome addition, and the updated chapters on versioning and threading are a must-read Those getting started with Core Data and those already using it owe it to themselves to read this fantastic book ➤ Kirby Turner, Chief Code Monkey, White Peak Software, Inc If you need to know Core Data inside and out, you need this book Marcus not only communicates what you need to know but has deep experience in making Core Data applications That experience shines through in every chapter and example ➤ Bill Dudney, Gala Factory Software, LLC This book has information for beginners and experts alike, particularly around new features such as iCloud syncing It’s a must-have if you’re going to be doing anything with Core Data ➤ Patrick Burleson, Owner, BitBQ, LLC If you’re using Core Data and haven’t read this book, you’re doing yourself and your customers a disservice Marcus Zarra explains the fundamental components of the Core Data framework and shows how the framework is used in real-world programming This book is a must-read for anyone new to Core Data, but there’s plenty of great information even for seasoned veterans ➤ Jeff LaMarche, Author and Co-Founder of MartianCraft, LLC Core Data, 2nd Edition Data Storage and Management for iOS, OS X, and iCloud Marcus S Zarra The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trademarks of The Pragmatic Programmers, LLC Every precaution was taken in the preparation of this book However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com The team that produced this book includes: Colleen Toporek (editor) Potomac Indexing, LLC (indexer) Kim Wimpsett (copyeditor) David J Kelly (typesetter) Janet Furlow (producer) Juliet Benda (rights) Ellie Callahan (support) Copyright © 2013 The Pragmatic Programmers, LLC All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher Printed in the United States of America ISBN-13: 978-1-937785-08-6 Encoded using the finest acid-free high-entropy binary digits Book version: P1.0—January 2013 Contents Introduction ix 1 10 17 20 21 21 Under the Hood of Core Data 1.1 NSManagedObjectModel 1.2 NSPersistentStoreCoordinator 1.3 NSManagedObjectContext 1.4 NSManagedObject 1.5 NSFetchRequest 1.6 NSSortDescriptor 1.7 Fetched Properties 1.8 Wrapping Up iOS: 2.1 2.2 2.3 2.4 NSFetchedResultsController How to Use the NSFetchedResultsController Under the Hood of the NSFetchedResultsController Building Our Own: ZSContextWatcher Wrapping Up 23 23 31 32 36 Versioning and Migration 3.1 Some Maintenance Before We Migrate 3.2 A Simple Migration 3.3 The Difference Between Light and Heavy Migrations 3.4 A Heavy/Manual Migration 3.5 Fundamentals of Core Data Versioning 3.6 Progressive Data Migration (An Academic Exercise) 3.7 Wrapping Up 37 38 39 42 44 51 54 59 Performance Tuning 4.1 Persistent Store Types 4.2 Optimizing Your Data Model 4.3 Fetching 4.4 Faulting 61 61 63 67 71 Contents 4.5 4.6 Access Patterns Wrapping Up • vi 75 76 Threading 5.1 Why Isn’t Core Data Thread-Safe? 5.2 Creating Multiple Contexts 5.3 Exporting Recipes 5.4 Importing Recipes 5.5 Parent-Child NSManagedObjectContext Instances 5.6 Wrapping Up 77 77 78 81 87 92 98 Using iCloud 6.1 Introducing the UIManagedDocument 6.2 Direct NSManagedObjectContext to iCloud 6.3 Consuming Changes from iCloud 6.4 Under the Hood 6.5 Migrating an Existing Application 6.6 Desktop iCloud Integration 6.7 Data Quantities 6.8 Sharing Data Between iOS and OS X 6.9 Wrapping Up 99 100 106 109 110 113 116 118 119 120 Adding a Desktop Foundation 7.1 Our Application 7.2 Our Application Design 7.3 Sharing the Data Model 7.4 Building the Controller Layer 7.5 Building the User Interface 7.6 Adding a Splash of Code 7.7 Wrapping Up 121 121 122 122 123 126 132 135 OS X: Bindings, KVC, and KVO 8.1 Key Value Coding 8.2 Key Value Observing 8.3 Cocoa Bindings and Core Data 8.4 Other Interface Elements That Use KVO, KVC, and Core Data 8.5 Wrapping Up 137 137 142 143 Spotlight, Quick Look, and Core Data 9.1 Integrating with Spotlight 9.2 Integrating with Quick Look 153 154 168 147 151 Contents 9.3 9.4 Putting It All Together Wrapping Up • vii 176 176 10 Dynamic Parameters 10.1 Building the Xcode Example Project 10.2 The DocumentPreferences Object 10.3 Wrapping Up 179 181 181 186 11 Distributed Core Data 11.1 Building the Server 11.2 Building the Client 11.3 Testing the Networking Code 11.4 Wrapping Up 189 190 199 202 206 A1 Building a Foundation A1.1 The Storyboard A1.2 The Recipe List A1.3 The Recipe Detail A1.4 The Edit Workflow A1.5 Ready for Core Data 209 209 211 213 214 219 A2 Macros in the Precompiled Header A2.1 Where Are the Macros? A2.2 What Do They Do? 221 221 222 Bibliography 225 Index 227 Introduction It is truly amazing how much has changed since the last time I sat down to write an introductory chapter for Core Data The last time, in 2009, the iPhone had just been released, and Core Data was not available for it yet; in fact, the SDK had been released only that year Of course, by the time we were finished with the production of the book, we did have Core Data on the iPhone, but it was in its infancy When I began putting together this second edition of the book, Core Data had just received a major update to its API, the first major update to its core API since its initial release for Mac OS X 10.4 Tiger Now, that update has been out for more than a year, and we are settling into those changes and how they impact our development of applications Is This Book for You? If you plan on writing an application that saves data to disk, then you should take a very long look at Core Data Whether you are focusing on the desktop or the iPhone, Core Data is the most efficient solution to data persistence A good way to confirm that you know enough Cocoa to benefit from this book is to take a look at Appendix 1, Building a Foundation, on page 209 You should find it dense, but every step should be familiar to you What Is Core Data? In the simplest terms, Core Data is an object graph that can be persisted to disk But just like describing a man as a “bag of mostly water,” that description hardly does Core Data justice If you have worked with Interface Builder (specifically on OS X), you know that it effectively removes a third of the coding from the Model View Controller (MVC) design pattern With Interface Builder, developers not need to spend countless hours writing and rewriting their user interface to make sure that it is pixel perfect Instead, they simply drag and drop the elements in the IDE, bind them together, and call it done report erratum • discuss Introduction •x Of course, the problem with Interface Builder is that we still need to code the other two parts! Both the controller and the model need to be developed in code and made to work with the interface we just designed That is where Core Data comes in In a nutshell, Core Data deals with a third of that MVC design: Core Data is the model It is a common misconception that Core Data is a database API for Cocoa that allows a Cocoa application to store its data in a database Although that description is factually accurate, Core Data does a lot more It serves as the entire model layer It is not just the persistence on disk; it is also all the objects in memory that we normally consider to be data objects If you have experience working with Java, C#, or some other object-oriented language, the data objects take a lot of time to write, and they are generally very repetitive in nature Core Data eliminates most, if not all, of that boilerplate code for us and lets us focus on the business logic, or the controller layer, of our application It does this with an interface that is as easy to use as Interface Builder In addition to ease of use, Core Data is also highly flexible If we need to step in and change the functionality of some portion of the data model, we can From how a value is handled when it is being accessed to how data is migrated from one persistent store to another, we can choose how little or how much we want to code ourselves and how much we want Core Data to for us When you start to learn Core Data, it is best to think in terms of objects Core Data is a framework designed to manage your data and data object graph As a secondary function, it will persist that data to disk However, its primary function is to manage the objects Core Data and iOS 5.0 If you have started to flip through this book, you probably noticed that I refer to iOS 6.0 and OS X 10.8 frequently, and I rarely mention iOS 5.0 or OS X 10.7, although the API changes that impacted Core Data the most were introduced in iOS 5.0 and OS X 10.7 There is a reason for this There are significant, unavoidable issues with these new APIs in their first release These issues are so significant that I cannot recommend using the new APIs in their first release It took me a long time to come to this conclusion, and even now I truly wish I had a better answer I kept hoping that a new point release would come out for iOS that would address some of these issues; unfortunately, it never report erratum • discuss ... designed That is where Core Data comes in In a nutshell, Core Data deals with a third of that MVC design: Core Data is the model It is a common misconception that Core Data is a database API for Cocoa... and how much we want Core Data to for us When you start to learn Core Data, it is best to think in terms of objects Core Data is a framework designed to manage your data and data object graph As... elevator pitch for Core Data goes like this: Core Data is an object graph that can persist to a database.” The primary function of Core Data is to manage the object graph Persisting the data to disk

Ngày đăng: 21/03/2019, 09:04

TỪ KHÓA LIÊN QUAN