<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5839038201833626823</id><updated>2024-10-06T22:23:44.717-07:00</updated><title type='text'>My little heaven</title><subtitle type='html'>Inspire your soul</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>80</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-7406309366747463689</id><published>2013-12-15T16:37:00.000-08:00</published><updated>2013-12-15T16:37:41.013-08:00</updated><title type='text'>Recovering a deleted App Name in Apple Store</title><content type='html'>&lt;br /&gt;
If you want to use a App Name in your new Apple Developer Account, which already used in your another apple account, even though the status is &quot;Developer Removed From Sale&quot;. iTunes Connect will disallow you, &amp;nbsp;the error message will be like &quot;&lt;b&gt;the app name you entered has already been used&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is a solution based on the following link:&amp;nbsp;http://hesh.am/2012/01/recovering-a-deleted-app-name-in-itunes-connect/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As long as you change your default language when you creating your new app, iTunes Connect will allow you to create a new app even they have the same name.&lt;br /&gt;
&lt;br /&gt;
For example , change the default language from Australian English to English.&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/7406309366747463689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/12/recovering-deleted-app-name-in-apple.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/7406309366747463689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/7406309366747463689'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/12/recovering-deleted-app-name-in-apple.html' title='Recovering a deleted App Name in Apple Store'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-1581128580674088927</id><published>2013-11-27T21:25:00.000-08:00</published><updated>2013-11-27T21:25:04.030-08:00</updated><title type='text'>iOS Interview Questions</title><content type='html'>From:&amp;nbsp;http://www.raywenderlich.com/53962/ios-interview-questions&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
1. Explain method swizzling. When you would use it?&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
2.Take three objects: a grandparent, parent and child. The grandparent retains the parent, the parent retains the child and the child retains the parent. The grandparent releases the parent. Explain what happens.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
3. What happens when you invoke a method on a nil pointer?&amp;nbsp;&lt;span style=&quot;color: #006837; font-family: Open Sans, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 25.859375px;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
4. Give two separate and independent reasons why retainCount should never be used in shipping code.&lt;br /&gt;
&lt;br /&gt;
5. Explain your process for tracing and fixing a memory leak.&lt;br /&gt;
&lt;br /&gt;
6. Explain how an autorelease pool works at the runtime level.&lt;br /&gt;
&lt;br /&gt;
7. When dealing with property declarations, what is the difference between atomic and non-atomic?&lt;br /&gt;
&lt;br /&gt;
8. In C, how would you reverse a string as quickly as possible?&lt;br /&gt;
&lt;br /&gt;
9. Which is faster: to iterate through an NSArray or an NSSet&lt;br /&gt;
&lt;br /&gt;
10. Explain how code signing works.&lt;br /&gt;
&lt;br /&gt;
11. What is posing in Objective-C?&lt;br /&gt;
&lt;br /&gt;
12. List six instruments that are part of the standard.&lt;br /&gt;
&lt;br /&gt;
13. What are the differences between copy and retain?&lt;br /&gt;
&lt;br /&gt;
14. What is the difference between frames and bounds?&lt;br /&gt;
&lt;br /&gt;
15. What happens when the following code executes? Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];&lt;br /&gt;
&lt;br /&gt;
16. List the five iOS app states.&lt;br /&gt;
&lt;br /&gt;
17. Do you think this interview was a good representation of your skills as a developer?&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/1581128580674088927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/11/ios-interview-questions.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1581128580674088927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1581128580674088927'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/11/ios-interview-questions.html' title='iOS Interview Questions'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-8228323964045325233</id><published>2013-10-03T03:03:00.000-07:00</published><updated>2013-10-03T03:03:08.292-07:00</updated><title type='text'>Learning Python -- Part two</title><content type='html'>1. Dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; dic = {&#39;lilei&#39;:90,&#39;lily&#39;:100,&#39;sam&#39;:57, &#39;&#39;tom&quot; :90}&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for key in dic&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print dic[key]&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print dic.keys(), &amp;nbsp;return all keys&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dic.values(), return all values&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dic.items(), &amp;nbsp;return all element&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dic.clear(), &amp;nbsp;clear dic, dic become {}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;del dic[&#39;tom&#39;] &amp;nbsp;, delete &#39;tom&#39; in dic, del is the keyword&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
2. file&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; f = open(filename, mode), &quot;r&quot; read, &quot;w&quot; write&lt;br /&gt;
&amp;nbsp; &amp;nbsp; content &amp;nbsp;= f.read(N) , read N bytes data&lt;br /&gt;
&amp;nbsp; &amp;nbsp; content &amp;nbsp;= f.readline(), read one line&lt;br /&gt;
&amp;nbsp; &amp;nbsp; content = f.readlines(), read all the lines&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; f.write(&#39;I like apple&#39;), write to file&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; f.close()&lt;br /&gt;
&lt;br /&gt;
3. range(), enumerate(), zip()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; S = &#39;abcdefghijk&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for i in range(0,len(S),2):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print S[i]&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; for (index,char) in enumerate(S):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print index&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print char &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; ta =[1,2,3]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; tb = [9,8,7]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; tc = [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for (a,b,c) in zip(ta,tb,tc)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(a,b,c)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; ta = [1,2,3]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; tb = [9,8,7]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; zipped = zip(ta,tb)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print(zipped)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; na,nb = zip(*zipped)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print(na,nb)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. lambda&lt;br /&gt;
&amp;nbsp; &amp;nbsp; func = lambda x,y: x+ y&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print func(3,4)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; def teset(f,a,b):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print &#39;test&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print f(a,b)&lt;br /&gt;
&amp;nbsp; &amp;nbsp;test(func,3,5)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;test((lambda x: x+3),[1,3,5,6])&lt;br /&gt;
&lt;br /&gt;
5. map&lt;br /&gt;
&amp;nbsp; &amp;nbsp; re = map((lambda x,y: x+y),[1,2,3],[6,7,9])&lt;br /&gt;
&lt;br /&gt;
6. filter&lt;br /&gt;
&amp;nbsp; &amp;nbsp; def func(a)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if a&amp;gt; 100:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return True&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return False&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;print filter(func,[10,56,101,500])&lt;br /&gt;
&lt;br /&gt;
7. reduce&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print reduce((lambda x,y: x+y),[1,2,5,7,9])&lt;br /&gt;
&lt;br /&gt;
8. &amp;nbsp;debug&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;re = iter(range(5))&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;try:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for i in range(100):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print re.next()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;except StopIteration:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print &#39;Here is end &#39;,i&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print &#39;HaHaHa&#39;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; try:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;
&amp;nbsp; &amp;nbsp; except error1:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;
&amp;nbsp; &amp;nbsp; except error2:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;
&amp;nbsp; &amp;nbsp; else:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;
&amp;nbsp; &amp;nbsp; finally:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/8228323964045325233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/10/learning-python-part-two.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8228323964045325233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8228323964045325233'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/10/learning-python-part-two.html' title='Learning Python -- Part two'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-5639779620959404502</id><published>2013-10-02T22:41:00.000-07:00</published><updated>2013-10-02T22:41:48.582-07:00</updated><title type='text'>Learning Python - part one</title><content type='html'>1. &amp;nbsp;print &#39;Hello World&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;a = 10&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;print a&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;print type(a)&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;a = 1.3&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;print a&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;print type(a)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;basic type:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;a = 10 &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; a =1.3 float &amp;nbsp; &amp;nbsp; &amp;nbsp; a = True &amp;nbsp;True/False &amp;nbsp; &amp;nbsp;a = &#39;Hello&#39; &amp;nbsp;string&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;type() - return data type&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp;2. &amp;nbsp;Sequence:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Tuple : s1 = (2, 1.3, &#39;love&#39;,9,12,false) &amp;nbsp;, element can not be change&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; List: s2 = [True, 5, &#39;smile&#39;] &amp;nbsp;, element can change&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s1[0]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s2[2]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; s2[1] = 3.0&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s2&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s1[:5] &amp;nbsp;-- from start to element 4&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s1[2:] &amp;nbsp;-- from&amp;nbsp;element&amp;nbsp;2 to last&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s1[0:5:2] &amp;nbsp;-- from index 0 to&amp;nbsp;element&amp;nbsp;4 , every 2 to get a element, such as element 0,2,4&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s1[2:0:-1] -- from element 2 to element 1&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s1[-1] -- last element&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; print s1[-3] -- the last third element&lt;br /&gt;
&lt;br /&gt;
3. If else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; i = 1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if i&amp;gt;0:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print &#39;positive i&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i = i+1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; elif i ==0:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print &#39;i is 0&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i = i *10&lt;br /&gt;
&amp;nbsp; &amp;nbsp; else:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print &#39;negative i&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i = i -1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print &#39;new i:&#39;,i&lt;br /&gt;
&lt;br /&gt;
4. &amp;nbsp;for, while, continue, break&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;for a in [3,4.4, &#39;lift&#39;]:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print a&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while i&amp;lt; 10:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print i&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i = i+1&lt;br /&gt;
&lt;br /&gt;
5. function&lt;br /&gt;
&amp;nbsp; &amp;nbsp; def square_sum(a,b)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c = a**2 + b ** 2&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return c&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print square_sum(3,4)&lt;br /&gt;
&lt;br /&gt;
6. class , object&lt;br /&gt;
&amp;nbsp; &amp;nbsp; class Bird(object)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; have_feather = True&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; way_of_reproduction = &#39;egg&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def move(self,dx,dy):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; position =[0,0]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; position[0] = position[0]+dx&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; position[1] = position[1] +dy&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return position&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;summer = Bird()&lt;br /&gt;
&amp;nbsp;print &#39;after move:&#39;, summer.move(5,8)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;class Chicken(Bird):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;way_of_move = &#39;walk&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;possible_in_KFC = True&lt;br /&gt;
&lt;br /&gt;
summer = Chicken()&lt;br /&gt;
print summer.have_feather&lt;br /&gt;
print summer.move(5,6)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. dir(), help()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print dir(list)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print help(list)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1 = [1,2,5,3,5]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1.count(5), &amp;nbsp; how many 5&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1.index(3), &amp;nbsp; index of the first 3&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1.append(6), add 6 to the list&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1.sort(), sort&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1.pop(), remove the last element and return it&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1.remove(2), remove the first 2&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n1.insert(0,9), insert 9 to position 0&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/5639779620959404502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/10/learning-python-part-one.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/5639779620959404502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/5639779620959404502'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/10/learning-python-part-one.html' title='Learning Python - part one'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-3305261009877866049</id><published>2013-09-16T23:22:00.003-07:00</published><updated>2013-09-16T23:22:35.138-07:00</updated><title type='text'>iOS -- Core Image</title><content type='html'>&lt;br /&gt;
&lt;ul style=&quot;background-color: white; border: 0px; font-family: &#39;Open Sans&#39;, sans-serif; font-size: 16.363636016845703px; line-height: 25.86647605895996px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 3px 30px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; font-family: inherit; font-size: 16.363636016845703px; font-style: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: #006837; font-family: inherit; font-size: 16.363636016845703px; font-style: inherit; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CIContext&lt;/span&gt;. All of the processing of a core image is done in a CIContext. This is somewhat similar to a Core Graphics or OpenGL context.&lt;/li&gt;
&lt;li style=&quot;border: 0px; font-family: inherit; font-size: 16.363636016845703px; font-style: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: #006837; font-family: inherit; font-size: 16.363636016845703px; font-style: inherit; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CIImage&lt;/span&gt;. This class hold the image data. It can be creating from a UIImage, from an image file, or from pixel data.&lt;/li&gt;
&lt;li style=&quot;border: 0px; font-family: inherit; font-size: 16.363636016845703px; font-style: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: #006837; font-family: inherit; font-size: 16.363636016845703px; font-style: inherit; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CIFilter&lt;/span&gt;. The filter class has a dictionary that defines the attributes of the particular filter that it represents. Examples of filters are vibrance filters, color inversion filters, cropping filters, and much more.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
1.declare&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;@implementation&lt;/span&gt; ViewController&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
{&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;CIContext&lt;/span&gt; *context;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;CIFilter&lt;/span&gt; *filter;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;CIImage&lt;/span&gt; *beginImage;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
}&lt;/div&gt;
&lt;br /&gt;
2. change&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;NSString&lt;span class=&quot;s1&quot;&gt; *filePath = [[&lt;/span&gt;NSBundle&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;mainBundle&lt;span class=&quot;s1&quot;&gt;]&lt;/span&gt;pathForResource&lt;span class=&quot;s1&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;@&quot;image&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;ofType&lt;span class=&quot;s1&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;@&quot;png&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s3&quot;&gt;NSURL&lt;/span&gt; *fileNameAndPath = [&lt;span class=&quot;s3&quot;&gt;NSURL&lt;/span&gt; &lt;span class=&quot;s3&quot;&gt;fileURLWithPath&lt;/span&gt;:filePath];&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;beginImage&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; = [&lt;/span&gt;CIImage&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;imageWithContentsOfURL&lt;span class=&quot;s1&quot;&gt;:fileNameAndPath];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; = [&lt;/span&gt;CIContext&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;contextWithOptions&lt;span class=&quot;s1&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; = [&lt;/span&gt;CIFilter&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;filterWithName&lt;span class=&quot;s1&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;@&quot;CISepiaTone&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;keysAndValues&lt;span class=&quot;s1&quot;&gt;:&lt;/span&gt;kCIInputImageKey&lt;span class=&quot;s1&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;beginImage&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;@&quot;inputIntensity&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;@0.8&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s3&quot;&gt;CIImage&lt;/span&gt; *outputImage = [&lt;span class=&quot;s4&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;s3&quot;&gt;outputImage&lt;/span&gt;];&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s3&quot;&gt;CGImageRef&lt;/span&gt; cgimg = [&lt;span class=&quot;s4&quot;&gt;context&lt;/span&gt; &lt;span class=&quot;s3&quot;&gt;createCGImage&lt;/span&gt;:outputImage &lt;span class=&quot;s3&quot;&gt;fromRect&lt;/span&gt;:[outputImage &lt;span class=&quot;s3&quot;&gt;extent&lt;/span&gt;]];&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;UIImage&lt;span class=&quot;s1&quot;&gt; *newImage = [&lt;/span&gt;UIImage&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;imageWithCGImage&lt;span class=&quot;s1&quot;&gt;:cgimg];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;s5&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s4&quot;&gt;imageView&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;image&lt;/span&gt; = newImage;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/3305261009877866049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/09/ios-core-image.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/3305261009877866049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/3305261009877866049'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/09/ios-core-image.html' title='iOS -- Core Image'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-8885543362492036283</id><published>2013-09-15T23:18:00.000-07:00</published><updated>2013-09-15T23:18:23.975-07:00</updated><title type='text'>iOS - URL SCHEME</title><content type='html'>&lt;br /&gt;
To configure URL SCHEME&lt;br /&gt;
&lt;br /&gt;
In Xcode project, info.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOC1EZXJuQmsFMyIndjAiZj9VKOAqGNpDbtpGX2G7p7Qkcs1QbQ_135MwByI9pH7Ebl8Nva4iL8bHj9p05eBHSvtWUMVzwtYZmE12P2tUwpSL-srHrbMot4rB7k8CyN_32rejD65mywpNE/s1600/url_scheme_config.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOC1EZXJuQmsFMyIndjAiZj9VKOAqGNpDbtpGX2G7p7Qkcs1QbQ_135MwByI9pH7Ebl8Nva4iL8bHj9p05eBHSvtWUMVzwtYZmE12P2tUwpSL-srHrbMot4rB7k8CyN_32rejD65mywpNE/s1600/url_scheme_config.png&quot; height=&quot;164&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh45g8L_iZ2qpf1uKZ5YK25KLg0V25MC1wi-94U2_y3Ocb0tRb5RQwAIY9orm-phdMtwpaukc4thGICVI7mdqE5Sgxw8N5OVF6ZN_7OREEJRc50FcSze1X5H5qpzNgZPEdztA7Na7Wy0Zpk/s1600/image02.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh45g8L_iZ2qpf1uKZ5YK25KLg0V25MC1wi-94U2_y3Ocb0tRb5RQwAIY9orm-phdMtwpaukc4thGICVI7mdqE5Sgxw8N5OVF6ZN_7OREEJRc50FcSze1X5H5qpzNgZPEdztA7Na7Wy0Zpk/s1600/image02.png&quot; height=&quot;320&quot; width=&quot;180&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Open the app in code:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif; font-size: 14px; line-height: 25px; padding: 0px;&quot;&gt;
&amp;nbsp; NSString *format = @&quot;birdland://&quot;;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif; font-size: 14px; line-height: 25px; padding: 0px;&quot;&gt;
&amp;nbsp; &amp;nbsp; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:format]];&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif; font-size: 14px; line-height: 25px; padding: 0px;&quot;&gt;
&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif; font-size: 14px; line-height: 25px; padding: 0px;&quot;&gt;
&amp;nbsp; &amp;nbsp; [[UIApplication sharedApplication] openURL:url];&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/8885543362492036283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/09/ios-url-scheme_15.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8885543362492036283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8885543362492036283'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/09/ios-url-scheme_15.html' title='iOS - URL SCHEME'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOC1EZXJuQmsFMyIndjAiZj9VKOAqGNpDbtpGX2G7p7Qkcs1QbQ_135MwByI9pH7Ebl8Nva4iL8bHj9p05eBHSvtWUMVzwtYZmE12P2tUwpSL-srHrbMot4rB7k8CyN_32rejD65mywpNE/s72-c/url_scheme_config.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-4635250740189894307</id><published>2013-08-28T23:13:00.002-07:00</published><updated>2013-09-03T00:31:31.070-07:00</updated><title type='text'>iOS - KVO programming</title><content type='html'>&lt;span style=&quot;background-color: #f8f8f8; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px;&quot;&gt;&lt;b&gt;declare object:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;interface StockData : NSObject {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp;NSString * stockName;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp;float price;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;@end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;@implementation StockData&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;@end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;cpp&quot; name=&quot;code&quot; style=&quot;background-color: white; color: #333333; font-size: 14px; line-height: 26px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: #f8f8f8; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px;&quot;&gt;&lt;b&gt;Add Observer:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px;&quot;&gt;[stockForKVO&amp;nbsp;addObserver:self&amp;nbsp;forKeyPath:@&lt;/span&gt;&lt;span class=&quot;string&quot; style=&quot;background-color: #f8f8f8; border: none; color: blue; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&quot;price&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld&amp;nbsp;context:NULL]; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;b&gt;Set Value:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;myLabel.text&amp;nbsp;=&amp;nbsp;[stockForKVO&amp;nbsp;valueForKey:@&lt;span class=&quot;string&quot; style=&quot;border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;&quot;price&quot;&lt;/span&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;]; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&lt;b&gt;Reset Value, trigger observer method:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;[stockForKVO&amp;nbsp;setValue:@&lt;/span&gt;&lt;span class=&quot;string&quot; style=&quot;background-color: white; border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;&quot;20.0&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; border: none; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;forKey:@&lt;/span&gt;&lt;span class=&quot;string&quot; style=&quot;background-color: white; border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;&quot;price&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; border: none; margin: 0px; padding: 0px;&quot;&gt;]; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: white; border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: white; border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: white; border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;b&gt;Call observer method:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; if([keyPath isEqualToString:@&quot;price&quot;])&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; myLabel.text = [stockForKVO valueForKey:@&quot;price&quot;];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;background-color: white; border: none; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;b&gt;Remove observer:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;- (void)dealloc&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; [super dealloc];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; [stockForKVO removeObserver:self forKeyPath:@&quot;price&quot;];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; [stockForKVO release];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas, Courier New, Courier, mono, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #f8f8f8; border: none; font-family: Consolas, &#39;Courier New&#39;, Courier, mono, serif; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;border: none; margin: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/4635250740189894307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/08/ios-kvo-programming.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/4635250740189894307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/4635250740189894307'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/08/ios-kvo-programming.html' title='iOS - KVO programming'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-6155442294580411351</id><published>2013-08-14T22:06:00.000-07:00</published><updated>2013-08-14T22:06:10.658-07:00</updated><title type='text'>iOS-  Notes for Predicates Programming Guide</title><content type='html'>This is my notes for reading Apple Predicates Programming Guide&lt;br /&gt;
&lt;br /&gt;
Reference: &lt;a href=&quot;http://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Conceptual/Predicates/Articles/pUsing.html&quot;&gt;http://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Conceptual/Predicates/Articles/pUsing.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Introduction to Predicates Programming Guide&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
A predicate is a logical operator that returns a Boolean value (true or false). There are two types of predicate;&lt;br /&gt;
&lt;br /&gt;
comparison predicates, and compound predicates:&lt;br /&gt;
A comparison predicate compares two expressions using an operator.&lt;br /&gt;
&lt;br /&gt;
A compound predicate compares the results of evaluating two or more other predicates, or negates&lt;br /&gt;
another predicate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Predicate Classes&lt;/b&gt;&lt;br /&gt;
Cocoa provides three predicate classes: NSPredicate, and two subclasses of NSPredicate,&lt;br /&gt;
&lt;br /&gt;
NSComparisonPredicate and NSCompoundPredicate.&lt;br /&gt;
&lt;br /&gt;
Predicate expressions in Cocoa are represented by instances of NSExpression.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creating Predicates&lt;/b&gt;&lt;br /&gt;
Creating a Predicate Using a Format String&lt;br /&gt;
&lt;br /&gt;
NSPredicate *predicate = [NSPredicate&lt;br /&gt;
predicateWithFormat:@&quot;(lastName like[cd] %@) AND (birthday &amp;gt; %@)&quot;,&lt;br /&gt;
lastNameSearchString, birthdaySearchDate];&lt;br /&gt;
&lt;b&gt;(In the example, like[cd] means“case- and diacritic-insensitive like.”)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;String Constants, Variables, and Wildcards&lt;/b&gt;&lt;br /&gt;
String constants must be quoted within the expression—single and double quotes are both acceptable, but must be paired appropriately&lt;br /&gt;
&lt;br /&gt;
NSPredicate *predicate = [NSPredicate&lt;br /&gt;
predicateWithFormat:@&quot;lastName like[c] \&quot;S*\&quot;&quot;];&lt;br /&gt;
&lt;br /&gt;
You must take automatic quotation into account when using wildcards—you must add wildcards to a variable prior to substitution, as shown in the following example.&lt;br /&gt;
&lt;br /&gt;
NSString *prefix = @&quot;prefix&quot;;&lt;br /&gt;
NSString *suffix = @&quot;suffix&quot;;&lt;br /&gt;
NSPredicate *predicate = [NSPredicate&lt;br /&gt;
predicateWithFormat:@&quot;SELF like[c] %@&quot;,&lt;br /&gt;
[[prefix stringByAppendingString:@&quot;*&quot;] stringByAppendingString:suffix]];&lt;br /&gt;
BOOL ok = [predicate evaluateWithObject:@&quot;prefixxxxxxsuffix&quot;];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Boolean Values&lt;/b&gt;&lt;br /&gt;
NSPredicate *newPredicate =&lt;br /&gt;
[NSPredicate predicateWithFormat:@&quot;anAttribute == %@&quot;, [NSNumber&lt;br /&gt;
numberWithBool:aBool]];&lt;br /&gt;
NSPredicate *testForTrue =&lt;br /&gt;
[NSPredicate predicateWithFormat:@&quot;anAttribute == YES&quot;];&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Dynamic Property Names&lt;/b&gt;&lt;br /&gt;
Because string variables are surrounded by quotation marks when they are substituted into a format string using %@, you cannot use %@ to specify a dynamic property name—as illustrated in the following example.&lt;br /&gt;
&lt;br /&gt;
NSString *attributeName = @&quot;firstName&quot;;&lt;br /&gt;
NSString *attributeValue = @&quot;Adam&quot;;&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;%@ like %@&quot;,&lt;br /&gt;
attributeName, attributeValue];&lt;br /&gt;
&lt;br /&gt;
The predicate format string in this case evaluates to &quot;firstName&quot; like &quot;Adam&quot;.&lt;br /&gt;
&lt;br /&gt;
If you want to specify a dynamic property name, you use %K in the format string, as shown in the following fragment.&lt;br /&gt;
&lt;br /&gt;
predicate = [NSPredicate predicateWithFormat:@&quot;%K like %@&quot;,&lt;br /&gt;
attributeName, attributeValue];&lt;br /&gt;
&lt;br /&gt;
The predicate format string in this case evaluates to firstName like &quot;Adam&quot; (note that there are no&lt;br /&gt;
quotation marks around firstName).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creating Predicates Directly in Code&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
NSComparisonPredicate and&lt;br /&gt;
NSCompoundPredicate provide convenience methods that allow you to easily create compound and&lt;br /&gt;
comparison predicates respectively. NSComparisonPredicate provides a number of operators ranging from simple equality tests to custom functions.&lt;br /&gt;
&lt;br /&gt;
The following example shows how to create a predicate to represent (revenue &amp;gt;= 1000000) and (revenue &amp;lt; 100000000). Note that the same left-hand side expression is used for both comparison predicates.&lt;br /&gt;
&lt;br /&gt;
NSExpression *lhs = [NSExpression expressionForKeyPath:@&quot;revenue&quot;];&lt;br /&gt;
&lt;br /&gt;
NSExpression *greaterThanRhs = [NSExpression expressionForConstantValue:[NSNumber&lt;br /&gt;
numberWithInt:1000000]];&lt;br /&gt;
NSPredicate *greaterThanPredicate = [NSComparisonPredicate&lt;br /&gt;
predicateWithLeftExpression:lhs&lt;br /&gt;
rightExpression:greaterThanRhs&lt;br /&gt;
modifier:NSDirectPredicateModifier&lt;br /&gt;
type:NSGreaterThanOrEqualToPredicateOperatorType&lt;br /&gt;
options:0];&lt;br /&gt;
&lt;br /&gt;
NSExpression *lessThanRhs = [NSExpression expressionForConstantValue:[NSNumber&lt;br /&gt;
numberWithInt:100000000]];&lt;br /&gt;
NSPredicate *lessThanPredicate = [NSComparisonPredicate&lt;br /&gt;
predicateWithLeftExpression:lhs&lt;br /&gt;
rightExpression:lessThanRhs&lt;br /&gt;
modifier:NSDirectPredicateModifier&lt;br /&gt;
type:NSLessThanPredicateOperatorType&lt;br /&gt;
options:0];&lt;br /&gt;
&lt;br /&gt;
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:&lt;br /&gt;
@[greaterThanPredicate, lessThanPredicate]];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creating Predicates Using Predicate Templates&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
NSPredicate *predicateTemplate = [NSPredicate&lt;br /&gt;
predicateWithFormat:@&quot;lastName like[c] $LAST_NAME&quot;];&lt;br /&gt;
&lt;br /&gt;
To create a valid predicate to evaluate against an object, you use the NSPredicate method&lt;br /&gt;
predicateWithSubstitutionVariables: to pass in a dictionary that contains the variables to be&lt;br /&gt;
substituted. (Note that the dictionary must contain key-value pairs for all the variables specified in the predicate.)&lt;br /&gt;
&lt;br /&gt;
NSPredicate *predicate = [predicateTemplate predicateWithSubstitutionVariables:&lt;br /&gt;
[NSDictionary dictionaryWithObject:@&quot;Turner&quot; forKey:@&quot;LAST_NAME&quot;]];&lt;br /&gt;
&lt;br /&gt;
The new predicate returned by this example is lastName LIKE[c] &quot;Turner&lt;br /&gt;
&lt;br /&gt;
Because the substitution dictionary must contain key-value pairs for all the variables specified in the predicate, if you want to match a null value, you must provide a null value in the dictionary, as illustrated in the following example.&lt;br /&gt;
&lt;br /&gt;
NSPredicate *predicate = [NSPredicate&lt;br /&gt;
predicateWithFormat:@&quot;date = $DATE&quot;];&lt;br /&gt;
predicate = [predicate predicateWithSubstitutionVariables:&lt;br /&gt;
[NSDictionary dictionaryWithObject:[NSNull null] forKey:@&quot;DATE&quot;]];&lt;br /&gt;
&lt;br /&gt;
The predicate formed by this example is date == &lt;null&gt;&lt;/null&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Format String Summary&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;@&quot;attributeName == %@&quot;&lt;/b&gt;&lt;br /&gt;
This predicate checks whether the value of the key attributeName isthe same asthe value of the object&lt;br /&gt;
%@ that is supplied at runtime as an argument to predicateWithFormat:. Note that %@ can be a&lt;br /&gt;
placeholder for any object whose description is valid in the predicate, such as an instance of NSDate,&lt;br /&gt;
NSNumber, NSDecimalNumber, or NSString.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;@&quot;%K == %@&quot;&lt;/b&gt;&lt;br /&gt;
This predicate checks whether the value of the key %K is the same as the value of the object %@. The&lt;br /&gt;
variables are supplied at runtime as arguments to predicateWithFormat:.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;@&quot;%K == &#39;%@&#39;&quot;&lt;/b&gt;&lt;br /&gt;
This predicate checks whether the value of the key %K is equal to the string literal “%@“ (note the single quotes around %@). The key name %K is supplied at runtime as an argument to predicateWithFormat:.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;@&quot;name IN $NAME_LIST&quot;&lt;/b&gt;&lt;br /&gt;
This is a template for a predicate that checks whether the value of the key name is in the variable&lt;br /&gt;
$NAME_LIST (no quotes) that is supplied at runtime using predicateWithSubstitutionVariables:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;@&quot;&#39;name&#39; IN $NAME_LIST&quot;&lt;/b&gt;&lt;br /&gt;
This is a template for a predicate that checks whether the constant value &#39;name&#39; (note the quotes around&lt;br /&gt;
the string) is in the variable $NAME_LIST that is supplied at runtime using&lt;br /&gt;
predicateWithSubstitutionVariables:.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;@&quot;$name IN $NAME_LIST&quot;&lt;/b&gt;&lt;br /&gt;
This is a template for a predicate that expects values to be substituted (using&lt;br /&gt;
predicateWithSubstitutionVariables:) for both $NAME and $NAME_LIST.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Using Predicates&lt;/b&gt;&lt;br /&gt;
Evaluating Predicates&lt;br /&gt;
To evaluate a predicate, you use the NSPredicate method evaluateWithObject: and pass in the object&lt;br /&gt;
against which the predicate will be evaluated. The method returns a Boolean value—in the following example,&lt;br /&gt;
the result is YES.&lt;br /&gt;
&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;SELF IN %@&quot;, @[@&quot;Stig&quot;,&lt;br /&gt;
@&quot;Shaffiq&quot;, @&quot;Chris&quot;]];&lt;br /&gt;
BOOL result = [predicate evaluateWithObject:@&quot;Shaffiq&quot;];&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Using Predicates with Arrays&lt;/b&gt;&lt;br /&gt;
NSArray and NSMutableArray provide methods to filter array contents. NSArray provides&lt;br /&gt;
filteredArrayUsingPredicate: which returns a new array containing objects in the receiver that match&lt;br /&gt;
the specified predicate. NSMutableArray provides filterUsingPredicate: which evaluates the receiver’s&lt;br /&gt;
content against the specified predicate and leaves only objects that match.&lt;br /&gt;
&lt;br /&gt;
NSMutableArray *array =&lt;br /&gt;
[NSMutableArray arrayWithObjects:@&quot;Nick&quot;, @&quot;Ben&quot;, @&quot;Adam&quot;, @&quot;Melissa&quot;, nil];&lt;br /&gt;
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@&quot;SELF beginswith[c]&lt;br /&gt;
&#39;a&#39;&quot;];&lt;br /&gt;
NSArray *beginWithB = [array filteredArrayUsingPredicate:bPredicate];&lt;br /&gt;
// beginWithB contains { @&quot;Adam&quot; }.&lt;br /&gt;
NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@&quot;SELF contains[c]&lt;br /&gt;
&#39;e&#39;&quot;];&lt;br /&gt;
[array filterUsingPredicate:sPredicate];&lt;br /&gt;
// array now contains {@&quot;Ben&quot;, @&quot;Melissa&quot; }&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Using Predicates with Key-Paths&lt;/b&gt;&lt;br /&gt;
NSString *departmentName = ... ;&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:&lt;br /&gt;
@&quot;department.name like %@&quot;, departmentName];&lt;br /&gt;
&lt;br /&gt;
If you use a to-many relationship, the construction of a predicate is slightly different. If you want to fetch Departments in which at least one of the employees has the first name &quot;Matthew,&quot; for instance, you use an ANY operator as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:&lt;br /&gt;
@&quot;ANY employees.firstName like &#39;Matthew&#39;&quot;];&lt;br /&gt;
&lt;br /&gt;
If you want to find Departments in which at least one of the employees is paid more than a certain amount, you use an ANY operator as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
float salary = ... ;&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;ANY employees.salary&lt;br /&gt;
&amp;gt; %f&quot;, salary];&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Null Values&lt;/b&gt;&lt;br /&gt;
A comparison predicate does not match any value with null except null (nil) or the NSNull null value (that is, ($value == nil) returns YES if $value is nil)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Testing for Null&lt;/b&gt;&lt;br /&gt;
If you want to match null values, you must include a specific test in addition to other comparisons, as illustrated in the following fragment.&lt;br /&gt;
&lt;br /&gt;
predicate = [NSPredicate predicateWithFormat:@&quot;(firstName == %@) || (firstName =&lt;br /&gt;
nil)&quot;, firstName];&lt;br /&gt;
filteredArray = [array filteredArrayUsingPredicate:predicate];&lt;br /&gt;
NSLog(@&quot;filteredArray: %@&quot;, filteredArray);&lt;br /&gt;
// Output:&lt;br /&gt;
// filteredArray: ( { lastName = Turner; }, { birthday = 1972-03-23 20:45:32 -0800;&lt;br /&gt;
firstName = Ben; lastName = Ballard; }&lt;br /&gt;
&lt;br /&gt;
By implication, a test for null that matches a null value returns true. In the following code fragment, ok is set to YES for both predicate evaluations.&lt;br /&gt;
&lt;br /&gt;
predicate = [NSPredicate predicateWithFormat:@&quot;firstName = nil&quot;];&lt;br /&gt;
BOOL ok = [predicate evaluateWithObject:[NSDictionary dictionary]];&lt;br /&gt;
ok = [predicate evaluateWithObject:&lt;br /&gt;
[NSDictionary dictionaryWithObject:[NSNull null] forKey:@&quot;firstName&quot;]];&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Using Predicates with Core Data&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Fetch Requests&lt;/b&gt;&lt;br /&gt;
NSFetchRequest *request = [[NSFetchRequest alloc] init];&lt;br /&gt;
NSEntityDescription *entity = [NSEntityDescription entityForName:@&quot;Employee&quot;&lt;br /&gt;
inManagedObjectContext:managedObjectContext];&lt;br /&gt;
[request setEntity:entity];&lt;br /&gt;
NSNumber *salaryLimit = &amp;lt;#A number representing the limit#&amp;gt;;&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;salary &amp;gt; %@&quot;,&lt;br /&gt;
salaryLimit];&lt;br /&gt;
[request setPredicate:predicate];&lt;br /&gt;
NSError *error;&lt;br /&gt;
&lt;br /&gt;
NSArray *array = [managedObjectContext executeFetchRequest:request error:&amp;amp;error];&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Regular Expressions&lt;/b&gt;&lt;br /&gt;
NSArray *array = @[@&quot;TATACCATGGGCCATCATCATCATCATCATCATCATCATCATCACAG&quot;,&lt;br /&gt;
@&quot;CGGGATCCCTATCAAGGCACCTCTTCG&quot;, @&quot;CATGCCATGGATACCAACGAGTCCGAAC&quot;,&lt;br /&gt;
@&quot;CAT&quot;, @&quot;CATCATCATGTCT&quot;, @&quot;DOG&quot;];&lt;br /&gt;
// find strings that contain a repetition of at least 3 &#39;CAT&#39; sequences,&lt;br /&gt;
// but not followed by a further &#39;CA&#39;&lt;br /&gt;
NSPredicate *catPredicate =&lt;br /&gt;
[NSPredicate predicateWithFormat:@&quot;SELF MATCHES &#39;.*(CAT){3,}(?!CA).*&#39;&quot;];&lt;br /&gt;
NSArray *filteredArray = [array filteredArrayUsingPredicate:catPredicate];&lt;br /&gt;
// filteredArray contains just &#39;CATCATCATGTCT&#39;&lt;br /&gt;
&lt;br /&gt;
According to the ICU specification, regular expression meta characters are not valid inside a pattern set. For example, the regular expression \d{9}[\dxX] does not match valid ISBN numbers (any ten digit number, or a string with nine digits and the letter &#39;X&#39;)since the pattern set ([\dxX]) contains a meta character (\d). Instead you could write an OR expression, as shown in the following code sample:&lt;br /&gt;
&lt;br /&gt;
NSArray *isbnTestArray = @[@&quot;123456789X&quot;, @&quot;987654321x&quot;, @&quot;1234567890&quot;, @&quot;12345X&quot;,&lt;br /&gt;
@&quot;1234567890X&quot;];&lt;br /&gt;
NSPredicate *isbnPredicate =&lt;br /&gt;
[NSPredicate predicateWithFormat:@&quot;SELF MATCHES &#39;\\\\d{10}|\\\\d{9}[Xx]&#39;&quot;];&lt;br /&gt;
NSArray *isbnArray = [isbnTestArray filteredArrayUsingPredicate:isbnPredicate];&lt;br /&gt;
// isbnArray contains (123456789X, 987654321x, 1234567890)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Performance&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:&lt;/div&gt;
&lt;div&gt;
@&quot;( title matches .*mar[1-10] ) OR ( type = 1 )&quot;];&lt;/div&gt;
&lt;/div&gt;
you should write&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:&lt;br /&gt;
@&quot;( type = 1 ) OR ( title matches .*mar[1-10] )&quot;];&lt;br /&gt;
&lt;br /&gt;
In the second example, the regular expression is evaluated only if the first clause is false.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Predicate Format String Syntax&lt;/b&gt;&lt;br /&gt;
Parser Basics&lt;br /&gt;
&lt;br /&gt;
Variables are denoted with a $ (for example $VARIABLE_NAME). ? is not a valid parser token.&lt;br /&gt;
&lt;br /&gt;
%@ is a var arg substitution for an object value—often a string, number, or date.&lt;br /&gt;
&lt;br /&gt;
%K is a var arg substitution for a key path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When string variables are substituted into a format string using %@ , they are surrounded by quotation marks. If you want to specify a dynamic property name, use %K in the format string, as shown in the following example.&lt;br /&gt;
&lt;br /&gt;
NSString *attributeName = @&quot;firstName&quot;;&lt;br /&gt;
NSString *attributeValue = @&quot;Adam&quot;;&lt;br /&gt;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;%K like %@&quot;,&lt;br /&gt;
attributeName, attributeValue];&lt;br /&gt;
&lt;br /&gt;
The predicate format string in this case evaluates to firstName like &quot;Adam“&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Basic Comparisons&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Boolean Value Predicates&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;TRUEPREDICATE&lt;/b&gt;&lt;br /&gt;
A predicate that always evaluates to TRUE.&lt;br /&gt;
&lt;b&gt;FALSEPREDICATE&lt;/b&gt;&lt;br /&gt;
A predicate that always evaluates to FALSE.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;String Comparisons&lt;/b&gt;&lt;br /&gt;
BEGINSWITH&lt;br /&gt;
The left-hand expression begins with the right-hand expression.&lt;br /&gt;
&lt;br /&gt;
CONTAINS&lt;br /&gt;
The left-hand expression contains the right-hand expression.&lt;br /&gt;
&lt;br /&gt;
ENDSWITH&lt;br /&gt;
The left-hand expression ends with the right-hand expression.&lt;br /&gt;
&lt;br /&gt;
LIKE&lt;br /&gt;
The left hand expression equals the right-hand expression: ? and * are allowed as wildcard characters,&lt;br /&gt;
where ? matches 1 character and * matches 0 or more characters&lt;br /&gt;
&lt;br /&gt;
MATCHES&lt;br /&gt;
The left hand expression equals the right hand expression using a regex-style comparison according to&lt;br /&gt;
ICU v3&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Aggregate Operations&lt;/b&gt;&lt;br /&gt;
ANY, SOME&lt;br /&gt;
&lt;br /&gt;
Specifies any of the elements in the following expression. For example ANY children.age &amp;lt; 18.&lt;br /&gt;
&lt;br /&gt;
ALL&lt;br /&gt;
&lt;br /&gt;
Specifies all of the elements in the following expression. For example ALL children.age &amp;lt; 18.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
NONE&lt;br /&gt;
Specifies none of the elements in the following expression. For example, NONE children.age &amp;lt; 18.&lt;br /&gt;
&lt;br /&gt;
This is logically equivalent to NOT (ANY ...).&lt;br /&gt;
&lt;br /&gt;
IN&lt;br /&gt;
Equivalent to an SQL IN operation, the left-hand side must appear in the collection specified by the&lt;br /&gt;
right-hand side.&lt;br /&gt;
For example, name IN { &#39;Ben&#39;, &#39;Melissa&#39;, &#39;Nick&#39; }. The collection may be an array, a set, or a&lt;br /&gt;
dictionary—in the case of a dictionary, its values are used.&lt;br /&gt;
In Objective-C, you could create a IN predicate as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
NSPredicate *inPredicate =&lt;br /&gt;
[NSPredicate predicateWithFormat: @&quot;attribute IN %@&quot;, aCollection];&lt;br /&gt;
&lt;br /&gt;
where aCollection may be an instance of NSArray, NSSet, NSDictionary, or of any of the&lt;br /&gt;
corresponding mutable classes.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Reserved Words&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;The following words are reserved:&lt;/b&gt;&lt;br /&gt;
AND, OR, IN, NOT, ALL, ANY, SOME, NONE, LIKE, CASEINSENSITIVE, CI, MATCHES, CONTAINS, BEGINSWITH,&lt;br /&gt;
ENDSWITH, BETWEEN, NULL, NIL, SELF, TRUE, YES, FALSE, NO, FIRST, LAST, SIZE, ANYKEY, SUBQUERY, CAST,&lt;br /&gt;
&lt;br /&gt;
TRUEPREDICATE, FALSEPREDICATE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/6155442294580411351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/08/ios-notes-for-predicates-programming.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/6155442294580411351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/6155442294580411351'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/08/ios-notes-for-predicates-programming.html' title='iOS-  Notes for Predicates Programming Guide'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-2358196202072626727</id><published>2013-08-06T23:38:00.000-07:00</published><updated>2013-08-06T23:38:51.879-07:00</updated><title type='text'>iOS- Create push notification private key by shell script</title><content type='html'>To use the push notification, you need to create a &amp;nbsp;p12 private key file to your server side. I would like to create a shell script for it. Then you can reuse it for some time.&lt;br /&gt;
&lt;br /&gt;
First of all, you need to three source file :1.certSigningRequest, 2.p12(private key for the certificate), 3.cer(provision profile)&lt;br /&gt;
&lt;br /&gt;
for example, using .Net to send push notification, you need to create a p12 file, you need to type 3 lines of command, which is&lt;br /&gt;
&lt;br /&gt;
then you need to type the followinig command as below:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
openssl x509 -&lt;span class=&quot;s1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;3.&lt;/span&gt;cer -inform der -out PushCert.pem&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
openssl pkcs12 -nocerts -out PushKey.pem -&lt;span class=&quot;s1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;2.&lt;/span&gt;p12&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
openssl pkcs12 -&lt;span class=&quot;s1&quot;&gt;export&lt;/span&gt; -&lt;span class=&quot;s1&quot;&gt;in&lt;/span&gt; PushCert.pem -inkey PushKey.pem -certfile &lt;span class=&quot;s2&quot;&gt;1.&lt;/span&gt;certSigningRequest -name &lt;span class=&quot;s3&quot;&gt;&quot;apn_production_identity&quot;&lt;/span&gt; -out apn_production_identity.p12&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;Step one:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
Open your terminal, type &lt;i&gt;&lt;b&gt;vim my_script&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;Step two:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
input the following words:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;#!/bin/bash&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;# Create push p12 file&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;b&gt;openssl x509 -&lt;span class=&quot;s1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;3.&lt;/span&gt;cer -inform der -out PushCert.pem&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;b&gt;openssl pkcs12 -nocerts -out PushKey.pem -&lt;span class=&quot;s1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;2.&lt;/span&gt;p12&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;b&gt;openssl pkcs12 -&lt;span class=&quot;s1&quot;&gt;export&lt;/span&gt; -&lt;span class=&quot;s1&quot;&gt;in&lt;/span&gt; PushCert.pem -inkey PushKey.pem -certfile &lt;span class=&quot;s2&quot;&gt;1.&lt;/span&gt;certSigningRequest -name &lt;span class=&quot;s3&quot;&gt;&quot;apn_production_identity&quot;&lt;/span&gt; -out apn_production_identity.p12&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;Step three:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
save the file and put the source files and my_script in the same folder&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;Step four:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Open terminal, cd to the folder, run&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;i&gt;bash my_script&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
After enter the password to verify, then you will get the p12 file, which is&amp;nbsp;&lt;b&gt;apn_production_identity.p12&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/2358196202072626727/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/08/ios-create-push-notification-private.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/2358196202072626727'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/2358196202072626727'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/08/ios-create-push-notification-private.html' title='iOS- Create push notification private key by shell script'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-5488118814898688164</id><published>2013-07-29T23:10:00.001-07:00</published><updated>2013-07-29T23:27:03.637-07:00</updated><title type='text'>iOS- NSString to NSDate and NSDate to NSString </title><content type='html'>Here is the code snippet to show NSString convert to NSDate and NSDate convert to NSString&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
Input Date string and date formate&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
for example [aa dateFromString:@&quot;your date&quot; and @&quot;dd/MM/yyyy hh:mm&quot;];&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
+(&lt;span class=&quot;s1&quot;&gt;NSDate&lt;/span&gt;*)dateFromString: (&lt;span class=&quot;s1&quot;&gt;NSString&lt;/span&gt;*)dateString and: (&lt;span class=&quot;s1&quot;&gt;NSString&lt;/span&gt;*)format&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
{&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;NSDateFormatter&lt;span class=&quot;s2&quot;&gt; *dateformatter = [[&lt;/span&gt;NSDateFormatter&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;alloc&lt;span class=&quot;s2&quot;&gt;]&lt;/span&gt;init&lt;span class=&quot;s2&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;// Server sends Sydney time&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;NSTimeZone&lt;span class=&quot;s2&quot;&gt; *zone = [&lt;/span&gt;NSTimeZone&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;timeZoneWithName&lt;span class=&quot;s2&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;@&quot;Australia/Sydney&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; [dateformatter &lt;span class=&quot;s1&quot;&gt;setTimeZone&lt;/span&gt;:zone];&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; // set locale, we use us date time style,&lt;br /&gt;
&amp;nbsp; &amp;nbsp;// if you want to force to display 12 hour style or 24 hour style, you can set &amp;nbsp;en_US_POSIX force to &amp;nbsp; &amp;nbsp; use 12 hour style&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;NSLocale&lt;span class=&quot;s2&quot;&gt; *locale = [[&lt;/span&gt;NSLocale&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;alloc&lt;span class=&quot;s2&quot;&gt;]&lt;/span&gt;initWithLocaleIdentifier&lt;span class=&quot;s2&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;@&quot;en_US&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp; &amp;nbsp; // date string to NSdate&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; [dateformatter &lt;span class=&quot;s1&quot;&gt;setLocale&lt;/span&gt;:locale];&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; [dateformatter &lt;span class=&quot;s1&quot;&gt;setDateFormat&lt;/span&gt;:format];&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;NSDate&lt;/span&gt; *date =[dateformatter &lt;span class=&quot;s1&quot;&gt;dateFromString&lt;/span&gt;:dateString];&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s4&quot;&gt;return&lt;/span&gt;&amp;nbsp; date;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
+(&lt;span class=&quot;s1&quot;&gt;NSString&lt;/span&gt;*)stringFromDate: (&lt;span class=&quot;s1&quot;&gt;NSDate&lt;/span&gt;*)date and: (&lt;span class=&quot;s1&quot;&gt;NSString&lt;/span&gt;*)format&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
{&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;NSDateFormatter&lt;span class=&quot;s2&quot;&gt; *dateFormat = [[&lt;/span&gt;NSDateFormatter&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;alloc&lt;span class=&quot;s2&quot;&gt;] &lt;/span&gt;init&lt;span class=&quot;s2&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; [dateFormat &lt;span class=&quot;s1&quot;&gt;setDateFormat&lt;/span&gt;:format];&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/span&gt;NSTimeZone&lt;span class=&quot;s2&quot;&gt; *zone = [&lt;/span&gt;NSTimeZone&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;localTimeZone&lt;span class=&quot;s2&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; [dateFormat &lt;span class=&quot;s1&quot;&gt;setTimeZone&lt;/span&gt;:zone];&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;NSLocale&lt;span class=&quot;s2&quot;&gt; *locale = [[&lt;/span&gt;NSLocale&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;alloc&lt;span class=&quot;s2&quot;&gt;]&lt;/span&gt;initWithLocaleIdentifier&lt;span class=&quot;s2&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;@&quot;en_US&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp; &amp;nbsp; [dateFormat &lt;span class=&quot;s1&quot;&gt;setLocale&lt;/span&gt;:locale];&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s4&quot;&gt;return&lt;/span&gt; [dateFormat &lt;span class=&quot;s1&quot;&gt;stringFromDate&lt;/span&gt;:date];&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p2&quot;&gt;
}&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/5488118814898688164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/ios-nsstring-to-nsdate-and-nsdate-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/5488118814898688164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/5488118814898688164'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/ios-nsstring-to-nsdate-and-nsdate-to.html' title='iOS- NSString to NSDate and NSDate to NSString '/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-1126576386863735398</id><published>2013-07-29T23:06:00.000-07:00</published><updated>2013-07-29T23:06:31.869-07:00</updated><title type='text'>Concurrency in iOS</title><content type='html'>First of all, let&#39;s understand some basic concept:&lt;br /&gt;
&lt;b&gt;Main queue&lt;/b&gt;&lt;br /&gt;
This queue performs all its tasks on the main thread, which is where Cocoa and Cocoa Touch require programmers to call all UI-related methods. Use the &lt;b&gt;&lt;i&gt;dispatch_get_main_queue&lt;/i&gt;&lt;/b&gt; function to retrieve the handle on the main queue.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Concurrent queues&lt;/b&gt;&lt;br /&gt;
These are queues that you can retrieve from GCD in order to execute asynchronous or synchronous tasks. Use the &lt;i&gt;&lt;b&gt;dispatch_get_global_queue &lt;/b&gt;&lt;/i&gt;function to retrieve the handle to a concurrent queue.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Serial queues&lt;/b&gt;&lt;br /&gt;
These are queues that, no matter whether you submit synchronous or asynchronous tasks to them, will always execute their tasks in the first-in-first-out(FIFO) fashion. Use the &lt;i&gt;&lt;b&gt;dispatch_queue_create&lt;/b&gt;&lt;/i&gt;&amp;nbsp;to create a serial queue. Once you are done with the queue, you must release it using &lt;b&gt;&lt;i&gt;dispath_release &lt;/i&gt;&lt;/b&gt;function.&lt;br /&gt;
&lt;br /&gt;
Only one main queue, but you can create as many serial dispatch queues as you want. Tasks can be handed to dispatch queues in two forms: block objects or C functions.&lt;br /&gt;
&lt;br /&gt;
Main subjects to handle concurrency, Grand Central Dispatch, Threads,Timers,Operation and Operation Queues.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Grand Central Dispatch&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Performing UI-Related Tasks with GCD&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
use &lt;b&gt;&lt;i&gt;dispatch_get_main_queue&lt;/i&gt;&lt;/b&gt;, UI-related tasks have to be performed on the main thread.&lt;br /&gt;
&lt;b&gt;Code&amp;nbsp;Snippet,&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 394&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_queue_t mainQueue &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;dispatch_get_main_queue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;();&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_async&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;mainQueue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #007788; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;) {
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[[[&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;UIAlertView alloc&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;initWithTitle:&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;GCD&quot;
&lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;message:&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;GCD is amazing!&quot;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;delegate:&lt;/span&gt;&lt;span style=&quot;color: #336666; font-family: TheSansMonoCd;&quot;&gt;nil
&lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;cancelButtonTitle:&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;OK&quot;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;otherButtonTitles:&lt;/span&gt;&lt;span style=&quot;color: #336666; font-family: TheSansMonoCd;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #336666; font-family: TheSansMonoCd;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;show&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;];&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;b&gt;Executing Non-UI Related Tasks Synchronously with GCD&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;use the &lt;b&gt;&lt;i&gt;dispatch_sync&lt;/i&gt;&lt;/b&gt; function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 398&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #007788; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;printFrom1To1000&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;)(&lt;/span&gt;&lt;span style=&quot;color: #007788; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= ^&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;{
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NSUInteger counter &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;for &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;counter &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; counter &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;&amp;lt;= &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;counter&lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;){
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NSLog&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;Counter = %lu - Thread = %@&quot;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;,
(&lt;/span&gt;&lt;span style=&quot;color: #007788; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;unsigned long&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;counter&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;,
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSThread currentThread&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;]);
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
};&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 398&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;dispatch_queue_t concurrentQueue &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;dispatch_get_global_queue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;DISPATCH_QUEUE_PRIORITY_DEFAULT&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

     &lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_sync&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;concurrentQueue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;printFrom1To1000&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_sync&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;concurrentQueue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;printFrom1To1000&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;The priority of the concurrent queue that GCD has to retrieve for the programmer.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;b&gt;DISPATCH_QUEUE_PRIORITY_LOW&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;Fewer timeslices will be applied to your task than normal tasks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;b&gt;DISPATCH_QUEUE_PRIORITY_DEFAULT&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;The default system priority for the code execution will be applied to your task.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;b&gt;DISPATCH_QUEUE_PRIORITY_HIGH&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;More timeslices will be applied to your task than normal tasks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;b&gt;Executing Non-UI Related Tasks Asychronously with GCD&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;Use &lt;b&gt;&lt;i&gt;dispatch_async&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 401&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dispatch_queue_t concurrentQueue &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;dispatch_get_global_queue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;DISPATCH_QUEUE_PRIORITY_DEFAULT&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

     &lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dispatch_async&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;concurrentQueue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;{
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; __block UIImage &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;image &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #336666; font-family: TheSansMonoCd;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_sync&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;concurrentQueue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;{
&lt;/span&gt;&lt;span style=&quot;color: #35586c; font-family: TheSansMonoCd; font-style: italic;&quot;&gt;/* Download the image here */
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;});
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dispatch_sync&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;dispatch_get_main_queue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;{&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #35586c; font-family: TheSansMonoCd; font-style: italic;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; /* Show the image to the user here on the main queue*/
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });
});&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;b&gt;Performing Tasks After a Delay with GCD&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;use the &lt;b&gt;&lt;i&gt;dispatch_after&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;dispatch_after_f&lt;/i&gt;&lt;/b&gt; functions&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 407&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #007788; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;delayInSeconds &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;2.0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_time_t delayInNanoSeconds &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;=
&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;dispatch_time&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;DISPATCH_TIME_NOW&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;delayInSeconds &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;* &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSEC_PER_SEC&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

     &lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_queue_t concurrentQueue &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;dispatch_get_global_queue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;DISPATCH_QUEUE_PRIORITY_DEFAULT&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 408&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dispatch_after&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;delayInNanoSeconds&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;concurrentQueue&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #007788; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;){
&lt;/span&gt;&lt;span style=&quot;color: #35586c; font-family: TheSansMonoCd; font-style: italic;&quot;&gt;/* Perform your operations here */
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;});&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;b&gt;Performing a Task Only Once with GCD&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;use the &lt;b&gt;&lt;i&gt;dispatch_once&lt;/i&gt;&lt;/b&gt; function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/1126576386863735398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/concurrency-in-ios.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1126576386863735398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1126576386863735398'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/concurrency-in-ios.html' title='Concurrency in iOS'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-8388389862814946344</id><published>2013-07-19T04:34:00.001-07:00</published><updated>2013-07-19T04:34:21.904-07:00</updated><title type='text'>Core Data Programming Guide Notes -- Part 6</title><content type='html'>This is the notes of Core Data Programing Guide from reading Apple&#39;s document&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; color: black; font-family: Times; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
reference:&amp;nbsp;&lt;a href=&quot;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&quot;&gt;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 165&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Core Data FAQ&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Where does a Managed Object Context Come From?&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 165&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Where a managed object context comes from is entirely application-dependent. In a Cocoa document-based
application using &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSPersistentDocument&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, the persistent document typically creates the context, and gives
you access to it through the &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;managedObjectContext &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;method.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 165&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;How do I initialize a store with default data?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 165&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are two issues here: creating the data, and ensuring the data is imported only once.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 165&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are several ways to create the data.
&lt;/span&gt;&lt;br /&gt;

     &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can create a separate persistent store that contains the default data and include the store as an
application resource. When you want to use it, you must either copy the whole store to a suitable location,
or copy the objects from the defaults store to an existing store.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;For small datasets, you can create the managed objects directly in code.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can create a property list—or some other file-based representation—of the data, and store it as an
application resource. When you want to use it, you must open the file and parse the representation to
create managed objects.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 166&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: rgb(2.745000%, 41.180000%, 68.240000%); font-family: &#39;MyriadSet&#39;; font-size: 18.000000pt; font-weight: 500;&quot;&gt;How do I use my existing SQLite database with Core Data?&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 166&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;You don’t. &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Although Core Data supports SQLite as one of its persistent store types, the database format is
private. You cannot create a SQLite database using native SQLite API and use it directly with Core Data (nor
should you manipulate an existing Core Data SQLite store using native SQLite API). If you have an existing
SQLite database, you need to import it into a Core Data store&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;How do I fetch objects in the same order I created them?&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 167&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Objects in a persistent store are unordered. Typically you should impose order at the controller or view layer,
based on an attribute such as creation date. If there is order inherent in your data, you need to explicitly model
that.&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 167&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: rgb(2.745000%, 41.180000%, 68.240000%); font-family: &#39;MyriadSet&#39;; font-size: 18.000000pt; font-weight: 500;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
  
 
 
  &lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: MyriadSet;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: MyriadSet;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;

     
     
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/8388389862814946344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8388389862814946344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8388389862814946344'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-6.html' title='Core Data Programming Guide Notes -- Part 6'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-156305081934021859</id><published>2013-07-19T00:17:00.001-07:00</published><updated>2013-07-19T00:17:16.255-07:00</updated><title type='text'>Core Data Programming Guide Notes -- Part 5</title><content type='html'>This is the notes of Core Data Programing Guide from reading Apple&#39;s document&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; color: black; font-family: Times; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
reference:&amp;nbsp;&lt;a href=&quot;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&quot;&gt;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; color: black; font-family: Times; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; color: black; font-family: Times; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
  
 
 
  &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 136&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Concurrency with Core Data&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 136&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #555555; font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can use threads, serial operation queues, or dispatch queues for concurrency. For the
sake of conciseness, this article uses “thread” throughout to refer to any of these.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #555555; font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Use Thread Confinement to Support Concurrency&lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The pattern recommended for concurrent programming with Core Data is &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;thread confinement &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;: each thread
must have its own entirely private managed object context.&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 136&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are two possible ways to adopt the pattern:&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 136&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;ol&gt;
&lt;li style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700; vertical-align: 1.000000pt;&quot;&gt;
       &lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;Create a separate managed object context for each thread and share a single persistent store coordinator.
&lt;/span&gt;&lt;br /&gt;

       &lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;This is the typically-recommended approach.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 136&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2.Create a separate managed object context and persistent store coordinator for each thread.
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This approach provides for greater concurrency at the expense of greater complexity (particularly &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if you
need to communicate changes between different contexts) and increased memory usage.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
  
 
 
  &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 136&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You must create the managed context on the thread on which it will be used. If you use &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSOperation&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, note
that its &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;init &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;method is invoked on the same thread as the caller. You must not, therefore, create a managed
object context for the queue in the queue’s &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;init &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;method, otherwise it is associated with the caller’s thread.
Instead, you should create the context in &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;main &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(for a serial queue) or &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;start &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(for a concurrent queue).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Using thread confinement, you should not pass managed objects or managed object contexts between threads.
To “pass” a managed object from one context another across thread boundaries, you either:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;Pass its object ID (&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;objectID&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;) and use &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;objectWithID: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;existingObjectWithID:error: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;on the
receiving managed object context.&amp;nbsp;&lt;/span&gt;
  
 
 
  &lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 137&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; The corresponding managed objects must have been saved—you cannot pass the ID of a newly- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inserted
managed object to another context.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Execute a fetch on the receiving context.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 137&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     
  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 137&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Track Changes in Other Threads Using Notifications&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 137&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Typically, on thread &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;A &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;you register for the managed object context save notification,
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObjectContextDidSaveNotification&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. When you receive the notification, its user info dictionary
contains arrays with the managed objects that were inserted, deleted, and updated on thread B. Because the
managed objects are associated with a different thread, however, you should not access them directly. Instead,
you pass the notification as an argument to &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;mergeChangesFromContextDidSaveNotification: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(which
you send to the context on thread A). Using this method, the context is able to safely merge the changes.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 138&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Fetch in the Background for UI Responsiveness&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Following the thread confinement pattern, you use two managed object contexts associated with a single
persistent store coordinator. You fetch in one managed object context on a background thread, and pass the
&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;object IDs &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;of the fetched objects to another thread. In the second thread (typically the application&#39;s main
thread, so that you can then display the results), you use the second context to fault in objects with those
object IDs (you use &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;objectWithID: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;to instantiate the object). (This technique is only useful if you are using
an SQLite store, since data from binary and XML stores is read into memory immediately on open.)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 138&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Saving in a Background Thread is Error-prone&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 138&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you perform a save operation in a background thread, therefore,
it may be killed before it is able to complete. If you need to save on a background thread, you must write
additional code such that the main thread prevents the application from quitting until all the save operation
is complete.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;If You Don’t Use Thread Containment&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 139&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     
  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you choose not to use the thread containment pattern—that is, if you try to pass managed objects or contexts
between threads, and so on—you must be &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;extremely &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;careful about locking, and as a consequence you are
likely to negate any benefit you may otherwise derive from multi-threading. You also need to consider that:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Any time you manipulate or access managed objects, you use the associated managed object context.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data does not present a situation where reads are “safe” but changes are “dangerous”—&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;every
&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;operation is “dangerous” because every operation has cache coherency effects and can trigger faulting.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Managed objects themselves are not thread safe.&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you want to work with a managed object across different threads, you must lock its context (see&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSLocking&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;).&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Typically you lock the context or coordinator using &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;tryLock &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;lock&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. If you do this, the framework will ensure
that what it does behind the scenes is also thread-safe. For example, if you create one context per thread, but
all pointing to the same persistent store coordinator, Core Data takes care of accessing the coordinator in a
thread-safe way (the &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;lock &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;unlock &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;methods of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObjectContext &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;handle recursion).&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 139&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you lock (or successfully &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;tryLock&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;) a context, you must keep a strong reference to that context until you
invoke &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;unlock&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. If you don’t, in a multi-threaded environment, you may cause a deadlock.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 140&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Core Data Performance&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 141&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Fetching Managed Objects&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Fetch Predicates&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 141&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;How you use predicates can significantly affect the performance of your application.&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 141&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;E&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;specially if the predicate involves text matching (&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;contains&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;endsWith&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;like&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, and &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;matches&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;) since
correct Unicode searching is slow. If the predicate combines textual and non-textual comparisons, then it is
likely to be more efficient to specify the non-textual predicates first, for example &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;(salary &amp;gt; 5000000) AND
(lastName LIKE &#39;Quincey&#39;) &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is better than &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;(lastName LIKE &#39;Quincey&#39;) AND (salary &amp;gt; 5000000)&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 141&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 141&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Fetch Limits&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 141&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can set a limit to the number of objects a fetch will return using the method &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;setFetchLimit: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;as shown
in the following example.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;NSFetchRequest *request = [[NSFetchRequest alloc]init];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;[request setFetchLimit:100];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Faulting Behavior&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can safely invoke the following methods on
a fault without causing it to fire: &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isEqual:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;hash&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;superclass&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;zone&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isProxy&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isKindOfClass:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isMemberOfClass:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;conformsToProtocol:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;respondsToSelector:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;description&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;managedObjectContext&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;entity&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;objectID&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isInserted&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isUpdated&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isDeleted&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, and &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;isFault&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Batch Faulting and Pre-fetching with the SQLite Store&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 142&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;When you execute a fetch, Core Data fetches just instances of the entity you specify.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 147&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Analyzing Performance&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 142&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Analyzing Fetch Behavior with SQLite&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;With OS X version 10.4.3 and later, you can use the user default &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;com.apple.CoreData.SQLDebug &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;to log to
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;stderr &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;the actual SQL sent to SQLite. (Note that user default names are case sensitive.) For example, you can
pass the following as an argument to the application:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;-com.apple.CoreData.SQLDebug 1&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKG6Kq9himAmpTOEBzDkYaa2YyRu2-xLdrLqJyD0f6_EgBaa_NfiHaUz3sgcP1utGK-crrZLIHBPvyH5kvzExlbpFYTP5dKtxVkV4OeEsyIm87qer9kfc65_3CImnqLXaPQxnSVpaWiZjW/s1600/Screen+Shot+2013-07-19+at+5.01.43+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKG6Kq9himAmpTOEBzDkYaa2YyRu2-xLdrLqJyD0f6_EgBaa_NfiHaUz3sgcP1utGK-crrZLIHBPvyH5kvzExlbpFYTP5dKtxVkV4OeEsyIm87qer9kfc65_3CImnqLXaPQxnSVpaWiZjW/s1600/Screen+Shot+2013-07-19+at+5.01.43+PM.png&quot; height=&quot;438&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 149&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Troubleshooting Core Data&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 149&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Object Life-Cycle Problems&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 149&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Merge errors&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 149&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Problem: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You see the error message, &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;Could not merge changes&quot;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Cause: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Two different managed object contexts tried to change the same data. This is also known as an optimistic
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;locking failure.
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Remedy: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Either set a merge policy on the context, or manually (programmatically) resolve the failure. You can
retrieve the currently committed values for an object using &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;committedValuesForKeys:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, and you can re-fault
the object (so that when it is next accessed its data values are retrieved from its persistent store) using
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;refreshObject:mergeChanges:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 149&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Assigning a managed object to a different store&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Problem: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You see an exception that looks similar to this example.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;&lt;nsinvalidargumentexception&gt; [&lt;mymo 0x3036b0=&quot;&quot;&gt;_assignObject:toPersistentStore:]:&lt;/mymo&gt;&lt;/nsinvalidargumentexception&gt;&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 149&quot;&gt;
   &lt;div class=&quot;section&quot;&gt;
    &lt;div class=&quot;layoutArea&quot;&gt;
     &lt;div class=&quot;column&quot;&gt;
      &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;Can’t reassign an object to a different store once it has been saved.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;div class=&quot;page&quot; title=&quot;Page 150&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Cause: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The object you are trying to assign to a store has already been assigned and saved to a different store.
&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Remedy: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;To move an object from one store to another, you must create a new instance, copy the information
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;from the old object, save it to the appropriate store, and then delete the old instance.
&lt;/span&gt;&lt;br /&gt;

         &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 150&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Fault cannot be fulfilled
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 150&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Problem: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You see the error message, &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;Core Data could not fulfill a fault&quot;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.

&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Cause: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The corresponding object&#39;s underlying data has been deleted from the persistent store.
&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Remedy: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You should discard this object.

This problem can occur in at least two situations:
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;First:
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Start with a strong reference to a managed object.
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Delete the managed object via the managed object context.
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Save changes on the object context.
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;At this point, the deleted object has been turned into a fault. It isn’t destroyed because doing so would
violate the rules of memory management.
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Try to retrieve an attribute or relationship from the previously retained reference.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 150&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data will try to fault the faulted managed object but will fail to do so because the object has been deleted
from the store. That is, there is no longer an object with the same global ID in the store.
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Second:
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Delete an object from a managed object context.

Fail to break all relationships from other objects to that object.
Save changes.
&lt;/span&gt;&lt;br /&gt;
     &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Managed object invalidated
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Problem: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You see an exception that looks similar to this example:
&lt;/span&gt;&lt;br /&gt;
     &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;&lt;nsobjectinaccessibleexception&gt; [&lt;mymo 0x3036b0=&quot;&quot;&gt;_assignObject:toPersistentStore:]:
The NSManagedObject with ID:#### has been invalidated.
&lt;/mymo&gt;&lt;/nsobjectinaccessibleexception&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Cause: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Either you have removed the store for the fault you are attempting to fire, or the managed object&#39;s
context has been sent a &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;reset &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;message.&lt;/span&gt;     &lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Remedy: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You should discard this object. If you add the store again, you can try to fetch the object again.
&lt;/span&gt;&lt;br /&gt;

&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Class is not key-value coding compliant&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Problem: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You see an exception that looks similar to the following example.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
      &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;&lt;nsunknownkeyexception&gt; [&lt;mymo 0x3036b0=&quot;&quot;&gt; valueForUndefinedKey:]:
this class is not key value coding-compliant for the key randomKey.
&lt;/mymo&gt;&lt;/nsunknownkeyexception&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 151&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Cause: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Either you used an incorrect key, or you initialized your managed object with &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;init &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;instead of
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;initWithEntity:inManagedObjectContext:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.
&lt;/span&gt;&lt;br /&gt;

     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Remedy: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Use a valid key (check the spelling and case carefully—also review the rules for key-value coding
compliance in &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Key-Value Coding Programming Guide &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;), or ensure that you use the designated initializer for
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(see &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;initWithEntity:insertIntoManagedObjectContext:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;).
&lt;/span&gt;&lt;br /&gt;

        &lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 160&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Efficiently Importing Data
&lt;/span&gt;&lt;br /&gt;
     &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 160&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Cocoa Fundamentals
&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ol&gt;
     &lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/156305081934021859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-5.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/156305081934021859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/156305081934021859'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-5.html' title='Core Data Programming Guide Notes -- Part 5'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKG6Kq9himAmpTOEBzDkYaa2YyRu2-xLdrLqJyD0f6_EgBaa_NfiHaUz3sgcP1utGK-crrZLIHBPvyH5kvzExlbpFYTP5dKtxVkV4OeEsyIm87qer9kfc65_3CImnqLXaPQxnSVpaWiZjW/s72-c/Screen+Shot+2013-07-19+at+5.01.43+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-687231412251377813</id><published>2013-07-18T23:33:00.002-07:00</published><updated>2013-07-18T23:33:14.429-07:00</updated><title type='text'>Core Data Programming Guide Notes -- Part 4</title><content type='html'>This is the notes of Core Data Programing Guide from reading Apple&#39;s document&lt;br /&gt;
&lt;br /&gt;
reference:&amp;nbsp;&lt;a href=&quot;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&quot;&gt;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 115&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Using Persistent Stores&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Creating and Accessing a Store&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 115&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Access to stores is mediated by an instance of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSPersistentStoreCoordinator&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. You should not need to
directly access a file containing a store. From a persistent store coordinator, you can retrieve an object that
represents a particular store on disk. Core Data provides an &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSPersistentStore &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;class to represent persistent
stores.&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 115&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMyfMaBpENRpTW9_Aa8BTmtb9x_8IbDewrS61iM2LEHztv4ieXeCklvuQE8hAN3vrSXl8SXspdkvv7xbdDXMU5ZZrBxjzQcdEcHAFsVsK059T7XFWsmv8k7NKguleXh8wSqs_tgPkG5d88/s1600/Screen+Shot+2013-07-19+at+3.42.38+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMyfMaBpENRpTW9_Aa8BTmtb9x_8IbDewrS61iM2LEHztv4ieXeCklvuQE8hAN3vrSXl8SXspdkvv7xbdDXMU5ZZrBxjzQcdEcHAFsVsK059T7XFWsmv8k7NKguleXh8wSqs_tgPkG5d88/s1600/Screen+Shot+2013-07-19+at+3.42.38+PM.png&quot; height=&quot;278&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 115&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;To retrieve a store object from a coordinator, you use the method &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;persistentStoreForURL:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. You can use
a store to restrict a fetch request to a specific store, as shown in the following code fragment:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnSftIntDSav2loRedXFNc7IyIGyYLBUW1-GCVs9FaFklxOfskWY_A9bxMHGOnaILXMsQ97Kz2lbvpcCCOf9mmbR5CdbJeLogvI-BLCHWQDUopNA5tiaBOIWPeMqmiGcOiBK8bm_9oRycr/s1600/Screen+Shot+2013-07-19+at+3.56.31+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnSftIntDSav2loRedXFNc7IyIGyYLBUW1-GCVs9FaFklxOfskWY_A9bxMHGOnaILXMsQ97Kz2lbvpcCCOf9mmbR5CdbJeLogvI-BLCHWQDUopNA5tiaBOIWPeMqmiGcOiBK8bm_9oRycr/s1600/Screen+Shot+2013-07-19+at+3.56.31+PM.png&quot; height=&quot;48&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-6kYW8NAEoAkcdiIS9c_aUgMZ-Yw2kgMXg4uBsWrPABVIq_KQt3vHefXmKiaW-ddH_Mxc0tbFUfA34_YGkx-hfOvx8kZl5QPnY5qMPoATfuftUlMUl4frQiRhV3zhq2UWxNHmvZFjYWJ8/s1600/Screen+Shot+2013-07-19+at+3.56.35+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-6kYW8NAEoAkcdiIS9c_aUgMZ-Yw2kgMXg4uBsWrPABVIq_KQt3vHefXmKiaW-ddH_Mxc0tbFUfA34_YGkx-hfOvx8kZl5QPnY5qMPoATfuftUlMUl4frQiRhV3zhq2UWxNHmvZFjYWJ8/s1600/Screen+Shot+2013-07-19+at+3.56.35+PM.png&quot; height=&quot;108&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 116&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 120&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Core Data and Cocoa Bindings&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 120&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #555555; font-family: MyriadSet; font-size: 11pt;&quot;&gt;Note that Cocoa bindings are not available on iOS.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 124&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Change Management&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 125&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Conflict Detection and Optimistic Locking&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;When Core Data fetches an object from a persistent store, it takes a &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-weight: 700;&quot;&gt;snapshot &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;of its state. A snapshot is a
dictionary of an object’s persistent properties—typically all its attributes and the global IDs of any objects to
which it has a to-one relationship.&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 126&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If the values are the same, then the store has not been changed since the object was fetched, so the save
proceeds normally. As part of the save operation, the snapshots&#39; values are updated to match the saved
data.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If the values differ, then the store has been changed since the object was fetched or last saved; this
represents an optimistic locking failure.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 126&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Conflict Resolution&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 126&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can get an optimistic locking failure if more than one persistence stack references the same external data
store (whether you have multiple persistence stacks in a single application or you have multiple applications).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 126&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The default behavior is defined by the &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSErrorMergePolicy&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. This policy causes a save to fail if there are any
merge conflicts.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 126&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;In the case of failure, the save method returns with an error with a &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;userInfo &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;dictionary that
contains the key &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;@&quot;conflictList&quot;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 126&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSErrorMergePolicy &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is the only policy that generates an
error. Other policies—&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSMergeByPropertyStoreTrumpMergePolicy&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSMergeByPropertyObjectTrumpMergePolicy&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, and &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSOverwriteMergePolicy&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;—allow the save to
proceed by merging the state of the edited objects with the state of the objects in the store in different ways.
The &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSRollbackMergePolicy &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;discards in-memory state changes for objects in conflict and uses the persistent
store’s version of the objects’ state.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Snapshot Management&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;An application that fetches hundreds of rows of data can build up a large cache of snapshots.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 126&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Responsibility for cleaning up snapshots rests with a mechanism called &lt;/span&gt;&lt;span style=&quot;font-family: &#39;MyriadSet&#39;; font-size: 11.000000pt; font-weight: 700;&quot;&gt;snapshot reference counting&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 127&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Communicating Changes Between Contexts&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The following three strategies are presented in order of increasing complexity.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 127&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;1.The simplest case is when the object itself has not changed in &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt; font-weight: 700;&quot;&gt;moc2 &lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;and you do not have to worry about
undo; in this situation, you can just delete the object. The next time &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt; font-weight: 700;&quot;&gt;moc2 &lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;saves, the framework will notice
that you are trying to re-delete an object, ignore the optimistic locking warning, and continue without
error.&amp;nbsp;&lt;/span&gt;
    &lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 127&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;2.If you do not care about the contents of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt; font-weight: 700;&quot;&gt;moc2&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;, you can simply reset it (using &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt; font-weight: 700;&quot;&gt;reset&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;) and refetch any data
you need after the reset. This will reset the undo stack as well, and the deleted object is now gone. The
only issue here is determining what data to refetch. You can do this by, before you reset, collecting the
IDs (&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt; font-weight: 700;&quot;&gt;objectID&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;) of the managed objects you still need and using those to reload once the reset has
happened (you must exclude the deleted IDs, and it is best to create fetch requests with &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt; font-weight: 700;&quot;&gt;IN &lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;predicates to
avoid problems will not being able to fulfill faults for deleted IDs).&amp;nbsp;&lt;/span&gt;&lt;ol&gt;
     &lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: MyriadSet; font-size: 11pt;&quot;&gt;3.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If the object has changed in &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;moc2&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, but you do not care about undo, your strategy depends on what it
means for the semantics of your application. If the object that was deleted in &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;moc1 &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;has changes in &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;moc2&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;,
should it be deleted from &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;moc2 &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;as well? Or should it be resurrected and the changes saved? What happens
if the original deletion triggered a cascade delete for objects that have not been faulted into &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;moc2&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;? What
if the object was deleted as part of a cascade delete?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 128&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are two workable options (a third, unsatisfactory option is described later):
&lt;/span&gt;&lt;br /&gt;

     &lt;ol style=&quot;list-style-type: lower-latin;&quot;&gt;
&lt;li style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700; vertical-align: 1.000000pt;&quot;&gt;
       &lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;The simplest strategy is to just discard the changes by deleting the object.
&lt;/span&gt;&lt;br /&gt;

      &lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;Alternatively, if the object is standalone, you can set the merge policy on the context to
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSMergePolicyOverwrite&lt;/span&gt;&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;. This will cause the changes in the second context to overwrite the
delete in the database.
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;Note that this will cause &lt;/span&gt;&lt;span style=&quot;font-size: 11pt; font-style: italic; font-weight: 500;&quot;&gt;all &lt;/span&gt;&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;changes in &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;moc2 &lt;/span&gt;&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;to overwrite any changes made in &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;moc1&lt;/span&gt;&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
  
 
 
  &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 130&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Persistent Store Features&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Store Types and Behaviors&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data provides three sorts of disk-based persistent store—XML, atomic, and SQLite—and an in-memory
store.&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet; font-size: 10pt; font-weight: 700;&quot;&gt;
  
 
 
  &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 130&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: rgb(33.330000%, 33.330000%, 33.330000%); font-family: &#39;MyriadSet&#39;; font-size: 11.000000pt; font-weight: 700;&quot;&gt;iOS: &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: MyriadSet; font-size: 11pt;&quot;&gt;The XML store is not available on iOS.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet;&quot;&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUb3r_ZGFoify8SYY1TNszo1UVs9tD8YQ8J2DnAp3xaZmqQ5pSKxHp6zr7DVcpqi9vMIjUMG_eEugo950Bc6jnC3EQFNaxRPrd90t4-I0EzjkRj0dJsxAVboRkbsOJ28odJaWqtpmwjJyG/s1600/Screen+Shot+2013-07-19+at+4.25.57+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUb3r_ZGFoify8SYY1TNszo1UVs9tD8YQ8J2DnAp3xaZmqQ5pSKxHp6zr7DVcpqi9vMIjUMG_eEugo950Bc6jnC3EQFNaxRPrd90t4-I0EzjkRj0dJsxAVboRkbsOJ28odJaWqtpmwjJyG/s1600/Screen+Shot+2013-07-19+at+4.25.57+PM.png&quot; height=&quot;168&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: MyriadSet;&quot;&gt;
  
 
 
  &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 133&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;File Size May Not Reduce After Deleting a Record&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ol style=&quot;list-style-type: lower-latin;&quot;&gt;
     &lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/687231412251377813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/687231412251377813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/687231412251377813'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-4.html' title='Core Data Programming Guide Notes -- Part 4'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMyfMaBpENRpTW9_Aa8BTmtb9x_8IbDewrS61iM2LEHztv4ieXeCklvuQE8hAN3vrSXl8SXspdkvv7xbdDXMU5ZZrBxjzQcdEcHAFsVsK059T7XFWsmv8k7NKguleXh8wSqs_tgPkG5d88/s72-c/Screen+Shot+2013-07-19+at+3.42.38+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-8065450949785195496</id><published>2013-07-18T22:38:00.001-07:00</published><updated>2013-07-18T22:38:31.306-07:00</updated><title type='text'>Core Data Programming Guide Notes -- Part 3</title><content type='html'>This is the notes of Core Data Programing Guide from reading Apple&#39;s document&lt;br /&gt;
&lt;br /&gt;
reference:&amp;nbsp;&lt;a href=&quot;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&quot;&gt;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 79&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Object Lifetime Management&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 79&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;The Role of the Managed Object Context&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 79&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;his means that in general you cannot rely on a context to ensure the longevity of a
managed object instance, and you cannot rely on the existence of a managed object to ensure the longevity
of a context.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 79&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The exception to this rule is that a managed object context maintains a strong reference to any changed
(inserted, deleted, and updated) objects until the pending transaction is committed (with a &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;save:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;) or discarded
(with a &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;reset &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;rollback&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;).&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you have finished with a managed object context, or for some other reason you want to “disconnect” a
context from its persistent store coordinator, you should &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;not &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;set the context’s coordinator to &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 80&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;b&gt;// This will raise an exception&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;[myManagedObjectContext setPersistentStoreCoordinator:nil];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 80&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Instead, you should simply relinquish ownership of the context and allow it to be deallocated normally.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 80&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Breaking Relationship Strong Reference Cycles&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 80&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;To ensure that reference cycles are
broken, when you&#39;re finished with an object you can use the managed object context method
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;refreshObject:mergeChanges: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;to turn it into a fault.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Change and Undo Management&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 80&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A context keeps strong references to managed objects that have pending changes (insertions, deletions, or
updates) until the context is sent a &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;save:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;reset &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;rollback&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, or &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;dealloc &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;message, or the appropriate number
of undos to undo the change.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;The undo manager associated with a context keeps strong references to any changed managed objects.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 80&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 82&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Relationships and Fetched Properties&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 82&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data does not let you create relationships that cross stores. If you need to create a relationship from
objects in one store to objects in another, you should consider using fetched properties.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 82&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Relationship Fundamentals&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 82&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A relationship specifies the entity, or the parent entity, of the objects at the destination. This can be the same
as the entity at the source (a &lt;/span&gt;&lt;span style=&quot;font-family: &#39;MyriadSet&#39;; font-size: 11.000000pt; font-weight: 700;&quot;&gt;reflexive &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;relationship).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can specify a relationship as being to-one or to-many. To-one relationships are represented by a reference
to the destination object. To-many relationships are represented by mutable sets (although fetched properties
are represented by arrays). Implicitly, “to-one” and “to-many” typically refer to “one-to-one” and “one-to-many”&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;relationships respectively. A many-to-many relationship is one where a relationship and its inverse are both
to-many.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 83&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can also put upper and lower limits on the number of objects at the destination of a to-many relationship.
The lower limit does not have to be zero. You can if you want specify that the number of employees in a
department must lie between 3 and 40. You also specify a relationship as either optional or not optional. If a
relationship is not optional, then in order to be valid there must be an object or objects at the destination of
the relationship.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Relationship Delete Rules&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A relationship&#39;s delete rule specifies what should happen if an attempt is made to delete the source object.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 84&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Deny&lt;br /&gt;
If there is at least one object at the relationship destination, then the source object cannot be deleted.
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;For example, if you want to remove a department, you must ensure that all the employees in that
department are first transferred elsewhere (or fired!) otherwise the department cannot be deleted.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 84&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Nullify&lt;br /&gt;
Set the inverse relationship for objects at the destination to null.
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;For example, if you delete a department, set the department for all the current members to null. This
only makes sense if the department relationship for an employee is optional, or if you ensure that you
set a new department for each of the employees before the next save operation.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 84&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Cascade&lt;br /&gt;
Delete the objects at the destination of the relationship.
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;For example, if you delete a department, fire all the employees in that department at the same time.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 84&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;No Action&lt;br /&gt;
Do nothing to the object at the destination of the relationship.
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;For example, if you delete a department, leave all the employees as they are, even if they still believe
they belong to that department.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Manipulating Relationships and Object Graph Integrity&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;anEmployee.department = newDepartment;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Alternatively, you can use:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 85&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;[newDepartment addEmployeeObject:anEmployee];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Many-to-Many Relationships&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You must define many-to-many relationships in both directions—that is,you must specify two
relationships, each being the inverse of the other. You can’t just define a to-many relationship in one
direction and try to use it as a many-to-many. If you do, you will end up with referential integrity problems.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxEuX5i6lPmazgcB5knM8txPfWJC5QDzMukMOmYt9TaxkFa_oQjZe4E7LIoMq8zVjdYgCUrfN8LxIxYRnTACWHUkclKwqcZNzRvGFhhvv0dhEvO-eXBUAk2_8sFjJ4ney5QAWNU-YSmwjC/s1600/Screen+Shot+2013-07-19+at+11.37.24+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxEuX5i6lPmazgcB5knM8txPfWJC5QDzMukMOmYt9TaxkFa_oQjZe4E7LIoMq8zVjdYgCUrfN8LxIxYRnTACWHUkclKwqcZNzRvGFhhvv0dhEvO-eXBUAk2_8sFjJ4ney5QAWNU-YSmwjC/s1600/Screen+Shot+2013-07-19+at+11.37.24+AM.png&quot; height=&quot;294&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 88&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Unidirectional Relationships&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 89&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;in general, you should avoid using unidirectional relationships. Bidirectional relationships
provide the framework with additional information with which to better maintain the object graph. If you do
want to use unidirectional relationships, you need to do some of this maintenance yourself. In the case above,
this would mean that after this line of code:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;[managedObjectContext deleteObject:department];&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;you should write:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;[employee setValue:nil forKey:@&quot;department&quot;];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 89&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 86&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Cross-Store Relationships&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 89&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You must be careful not to create relationships from instances in one persistent store to instances in another
persistent store, as this is not supported by Core Data. If you need to create a relationship between entities in
different stores, you typically use fetched properties.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 89&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Fetched Properties&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Fetched properties represent weak, one-way relationships.&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 89&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A fetched property is like a relationship, but it differs in several important ways:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 89&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Rather than being a &quot;direct&quot; relationship, a fetched property&#39;s value is calculated using a fetch request.
(The fetch request typically uses a predicate to constrain the result.)&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A fetched property is represented by an array, not a set. The fetch request associated with the property
can have a sort ordering, and thus the fetched property may be ordered.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;
  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 90&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;A fetched property is evaluated lazily, and is subsequently cached.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You use &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;refreshObject:mergeChanges: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;to manually refresh
the properties—this causes the fetch request associated with this property to be executed again when the
object fault is next fired.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are two special variables you can use in the predicate of a fetched property—&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;$FETCH_SOURCE &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;and
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;$FETCHED_PROPERTY&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 90&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 91&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Non-Standard Persistent Attributes&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 91&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;he
principle behind the two approaches is the same: you present to consumers of your entity an attribute of the
type you want, and “behind the scenes” it’s converted into a type that Core Data can manage.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 91&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Transformable Attributes&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 103&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Managed Object Validation&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 103&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are two types of validation—property-level and inter-property. You use property-level validation to
ensure the correctness of individual values; you use inter-property validation to ensure the correctness of
combinations of values.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Core Data Validation&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Cocoa provides a basic infrastructure for model value validation. It requires you, though, to write code for all
the constraints you want to apply. Core Data allows you to put validation logic into the managed object model.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you do want to customize validation of individual properties, you use standard validation methods as defined
by the &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSKeyValueCoding &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;protocol&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 104&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: rgb(2.745000%, 41.180000%, 68.240000%); font-family: &#39;MyriadSet&#39;; font-size: 18.000000pt; font-weight: 500;&quot;&gt;Property-Level Validation&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 104&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSKeyValueCoding &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;protocol specifies a method—&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;validateValue:forKey:error:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;—that provides
general support for validation methods in a similar way to that in which &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;valueForKey: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;provides support for
accessor methods.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  

    &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 104&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you want to implement logic in addition to the constraints you provide in the managed object model, you
should not override &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;validateValue:forKey:error:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. Instead you should implement methods of the form
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;validate&lt;key&gt;:error:&lt;/key&gt;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 104&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you do implement custom validation methods, you should typically not invoke them directly.
Instead you should call &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;validateValue:forKey:error: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;with the appropriate key. This ensures that any
constraints defined in the managed object model are also applied.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;-(BOOL)validateAge:(id*)ioValue error:(NSError **)outError{}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 105&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The input value is a pointer to object reference (an &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;id *&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;). This means that in principle you can change the
input value&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 105&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: rgb(2.745000%, 41.180000%, 68.240000%); font-family: &#39;MyriadSet&#39;; font-size: 18.000000pt; font-weight: 500;&quot;&gt;Inter-Property validation&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;provides additional loci for validation—update, insertion, and deletion—through the
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;validateFor... &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;methods such as &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;validateForUpdate:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(2.745000%, 41.180000%, 68.240000%); font-family: &#39;MyriadSet&#39;; font-size: 18.000000pt; font-weight: 500;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 108&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Combining Validation Errors&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 110&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Faulting and Uniquing&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 110&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Faulting is a mechanism Core Data employs to reduce your application’s memory usage.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Faulting Limits the Size of the Object Graph&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 110&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     
  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A fault is a placeholder object that
represents a managed object that has not yet been fully realized, or a collection object that represents a
relationship:&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 110&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;1. A managed object fault is an instance of the appropriate class, but its persistent variables are not yet
initialized.&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;2. A relationship fault is a subclass of the collection class that represents the relationship.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 110&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;To illustrate, consider an application that allows a user to fetch and edit details about a single employee. The
employee has a relationship to a manager and to a department, and these objects in turn have other
relationships. If you retrieve just a single Employee object from a persistent store, its manager, department,
and reports relationships are initially represented by faults. Figure 1 shows an employee’s department
relationship represented by a fault.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZx4KZZ_uKtwEdNgWhyav2GnL_pcPsI1bmbdillmFLAfWsptSPCVF36k3G3bT4chMTKGeQuE_EJ2gl8apSjc8CVTnLZ8fQI2LDgUW5-3nw8bFdSZDIR-bsqmaF0lAdV6hVhiNjgKtxrUE1/s1600/Screen+Shot+2013-07-19+at+3.19.02+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZx4KZZ_uKtwEdNgWhyav2GnL_pcPsI1bmbdillmFLAfWsptSPCVF36k3G3bT4chMTKGeQuE_EJ2gl8apSjc8CVTnLZ8fQI2LDgUW5-3nw8bFdSZDIR-bsqmaF0lAdV6hVhiNjgKtxrUE1/s1600/Screen+Shot+2013-07-19+at+3.19.02+PM.png&quot; height=&quot;240&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 111&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Fault handling is transparent—you do not have to execute a fetch to realize a fault.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 111&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If at some stage a persistent
property of a fault object is accessed, then Core Data automatically retrieves the data for the object and
initializes the object.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Firing Faults&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 111&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Turning Objects into Faults&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 111&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Turning a realized object into a fault can be useful in pruning the object graph.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Turning a managed object into a fault releases unnecessary memory, sets its in-memory property values
to &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, and breaks strong references to related objects.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can turn a realized object into a fault with the &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;refreshObject:mergeChanges: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;method. If you pass
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NO &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;as the &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;mergeChanges &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;argument, you must be sure that there are no changes to that object’s relationships.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;When an object turns into a fault, it is sent a &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;didTurnIntoFault &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;message. You may implement a custom
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;didTurnIntoFault &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;method to perform various “housekeeping” function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Uniquing Ensures a Single Managed Object per Record per Context&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 112&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data ensures that—in a given managed object context—an entry in a persistent store is associated with
only one managed object. The technique is known as &lt;/span&gt;&lt;span style=&quot;font-family: &#39;MyriadSet&#39;; font-size: 11.000000pt; font-weight: 700;&quot;&gt;uniquing&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. &amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 113&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;For example, consider the situation illustrated in Figure 2; two employees have been fetched into &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;a single
managed object context &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. Each has a relationship to a department, but the department is currently represented
by a fault.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgudAslBa-COj4huZYV5FgbGgRb-WCiOhqFQm6RH8rNF0s7E5zQI8FmD5f-6bdWmraZAbrjO7i4tV1m3uUWp0G0qCGcCSd0ZKa1-LpGiAZ9qVZ4_pW5UGB8nGcqUkmkK-JUcccRrUskId2R/s1600/Screen+Shot+2013-07-19+at+3.36.40+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgudAslBa-COj4huZYV5FgbGgRb-WCiOhqFQm6RH8rNF0s7E5zQI8FmD5f-6bdWmraZAbrjO7i4tV1m3uUWp0G0qCGcCSd0ZKa1-LpGiAZ9qVZ4_pW5UGB8nGcqUkmkK-JUcccRrUskId2R/s1600/Screen+Shot+2013-07-19+at+3.36.40+PM.png&quot; height=&quot;426&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;It would appear that each employee has a separate department, and if you asked each employee for their
department in turn—turning the faults into regular objects—you would have two separate Department objects
in memory. However, if both employees belong to the same department (for example, &quot;Marketing&quot;), then Core
Data ensures that (in a given managed object context) only one object representing the Marketing department
is ever created. If both employees belong to the same department, their department relationships would both
therefore reference the same fault&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVhONv-LVO8YE7ILIGNDl1TPwz3UW-I69RUUkjw2o1zYlAjlXXiVHSPvTS5-LXKIvTVY27AUu4qmPjZ3fMOSr572f3eFSG2ijBkxGUQrpzo5XP5fikPwexgpYgYBXjIn30I13qxZtzXPAm/s1600/Screen+Shot+2013-07-19+at+3.37.24+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVhONv-LVO8YE7ILIGNDl1TPwz3UW-I69RUUkjw2o1zYlAjlXXiVHSPvTS5-LXKIvTVY27AUu4qmPjZ3fMOSr572f3eFSG2ijBkxGUQrpzo5XP5fikPwexgpYgYBXjIn30I13qxZtzXPAm/s1600/Screen+Shot+2013-07-19+at+3.37.24+PM.png&quot; height=&quot;432&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 113&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/8065450949785195496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8065450949785195496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/8065450949785195496'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-3.html' title='Core Data Programming Guide Notes -- Part 3'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxEuX5i6lPmazgcB5knM8txPfWJC5QDzMukMOmYt9TaxkFa_oQjZe4E7LIoMq8zVjdYgCUrfN8LxIxYRnTACWHUkclKwqcZNzRvGFhhvv0dhEvO-eXBUAk2_8sFjJ4ney5QAWNU-YSmwjC/s72-c/Screen+Shot+2013-07-19+at+11.37.24+AM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-1870966761828502138</id><published>2013-07-18T17:43:00.001-07:00</published><updated>2013-07-18T17:43:51.067-07:00</updated><title type='text'>Core Data Programming Guide Notes -- Part 2</title><content type='html'>This is the notes of Core Data Programing Guide from reading Apple&#39;s document&lt;br /&gt;
&lt;br /&gt;
reference:&amp;nbsp;&lt;a href=&quot;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&quot;&gt;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 38&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Managed Objects&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 38&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Basics&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Managed objects are instances of the &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;class, or of a subclass of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObject&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, that
represent instances of an entity. &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is a generic class that implements all the basic behavior
required of a managed object.&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 38&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A managed object is also associated with a managed object context (“context”).&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 39&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Custom Managed Object Classes&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 39&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;In combination with the entity description in the managed object model, &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;provides a rich
set of default behaviors including support for arbitrary properties and value validation.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 41&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Object Life-Cycle—Initialization and Deallocation&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data “owns” the life-cycle of managed objects&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The two other methods, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;awakeFromInsert &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;awakeFromFetch&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;,
allow you to differentiate between two different situations:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 41&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 41&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;1.awakeFromInsert &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is invoked only once in the lifetime of an object—when it is first created.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;2.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;awakeFromFetch &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is invoked when an object is re-initialized from a persistent store (during a fetch).&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 42&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Validation&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 42&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;validateValue:forKey:error:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 42&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 44&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Managed Object Accessor Methods&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You do need to write
custom accessor methods if you use transient properties to support non-standard data types (see &lt;/span&gt;&lt;span style=&quot;color: #0088cc; font-family: MyriadSet; font-size: 11pt;&quot;&gt;“Non-Standard
Persistent Attributes” &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(page 91)) or if you use scalar instance variables to represent an attribute.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 44&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 44&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Custom implementation&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;disables automatic &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 10pt;&quot;&gt;key-value observing &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(KVO) change notifications for modeled
properties, and the primitive accessor methods do not invoke the access and change notification methods.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 51&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: &#39;MyriadSet&#39;; font-size: 11.000000pt; font-weight: 700;&quot;&gt;Important: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You are strongly encouraged to use dynamic properties (that is, properties whose
implementation you specify as &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;@dynamic&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;) instead of creating custom implementations for standard or
primitive accessor methods.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

     &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Creating and Deleting Managed Objects&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Creating, Initializing, and Saving a Managed Object&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; in three main ways—a managed object:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; Must be an instance of &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or of a class that inherits from &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObject&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; Exists in an environment defined by its managed object context&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; Has an associated entity description that describes the properties of the object&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The
following example shows the easiest way to create a new instance of an entity named “Employee”.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 56&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;    NSManagedObject *newEmployee = [NSEntityDescription
    insertNewObjectForEntityForName:@&quot;Employee&quot;
    inManagedObjectContext:context];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;div class=&quot;page&quot; title=&quot;Page 57&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;The Managed Object Context &lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 58&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;The Entity Description
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 58&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Given a managed object context, you could retrieve the appropriate entity description through the persistent
store coordinator as illustrated in the following example:
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 58&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectContext *context = &amp;lt;#Get a context#&amp;gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;
NSManagedObjectModel *managedObjectModel =&lt;/span&gt;      &lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;    [[context persistentStoreCoordinator] managedObjectModel];
NSEntityDescription *employeeEntity =
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;[[managedObjectModel entitiesByName] objectForKey:@&quot;Employee&quot;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 58&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;In practice, you would use the convenience method &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;entityForName:inManagedObjectContext: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;of
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSEntityDescription &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;which does the same thing—as illustrated in the following example:
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 58&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectContext *context = /* assume this exists */;
NSEntityDescription *employeeEntity = [NSEntityDescription
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;            entityForName:@&quot;Employee&quot;
            inManagedObjectContext:context];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 58&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Creating a Managed Object
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 58&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObject *newEmployee = [[NSManagedObject alloc]
              initWithEntity:employeeEntity &lt;/span&gt;&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;insertIntoManagedObjectContext:context];&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;div class=&quot;page&quot; title=&quot;Page 59&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 59&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Assigning an Object to a Store
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 59&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Typically there is only one persistent store for a given entity, and Core Data automatically ensures that new objects are saved to this store when the object&#39;s managed object context is saved.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 59&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You specify the store for an object using the &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObjectContext &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;method,
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;assignObject:toPersistentStore:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 59&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSURL *storeURL = &amp;lt;#URL for path to global store#&amp;gt;;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;id globalStore = [[context persistentStoreCoordinator]
    persistentStoreForURL:storeURL];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObject *newEmployee = [NSEntityDescription
    insertNewObjectForEntityForName:@&quot;Employee&quot;
    inManagedObjectContext:context];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[context assignObject:newEmployee toPersistentStore:globalStore];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 60&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Of course, the object is not saved to the store until the managed object context is saved.&lt;/span&gt;        &lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 60&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Deleting a Managed Object
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 60&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[aContext deleteObject:aManagedObject];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 60&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Relationships&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 60&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;When you delete a managed object it is important to consider its relationships and in particular the delete
rules specified for the relationships. If all of a managed object&#39;s relationship delete rules are &lt;b&gt;Nullify&lt;/b&gt;, then for
that object at least there is no additional work to do (you may have to consider other objects that were at the
destination of the relationship—if the inverse relationship was either mandatory or had a lower limit on
cardinality, then the destination object or objects might be in an invalid state). If a relationship delete rule is
&lt;b&gt;Cascade&lt;/b&gt;, then deleting one object may result in the deletion of others. If a rule is &lt;b&gt;Deny&lt;/b&gt;, then before you delete
an object you must remove the destination object or objects from the relationship, otherwise you will get a
validation error when you save. If a delete rule is No Action, then you must ensure that you take whatever
steps are necessary to ensure the integrity of the object graph.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 61&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Fetching Managed Objects
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 61&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Fetching Managed Objects
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 61&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectContext *moc = [self managedObjectContext];
  NSEntityDescription *entityDescription = [NSEntityDescription
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;      entityForName:@&quot;Employee&quot; inManagedObjectContext:moc];
  NSFetchRequest *request = [[NSFetchRequest alloc] init];
  [request setEntity:entityDescription];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;  // Set example predicate and sort orderings...
  NSNumber *minimumSalary = ...;
  NSPredicate *predicate = [NSPredicate predicateWithFormat:
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;      @&quot;(lastName LIKE[c] &#39;Worsley&#39;) AND (salary &amp;gt; %@)&quot;, minimumSalary];
  [request setPredicate:predicate];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;  NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
      initWithKey:@&quot;firstName&quot; ascending:YES];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;  [request setSortDescriptors:@[sortDescriptor]];
&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 62&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;  NSError *error;
  NSArray *array = [moc executeFetchRequest:request error:&amp;amp;error];
  if (array == nil)
  {&lt;/span&gt;    &lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;      // Deal with error...
  }
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The count of the array returned from the fetch will be &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;0 &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;if the target object has been deleted. If you need to
test for the existence of several objects, it is more efficient to use the &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;IN &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;operator than it is to execute multiple
fetches for individual objects, for example:
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;self IN %@&quot;,
                                            arrayOfManagedObjectIDs];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Fetching Specific Values
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Sometimes you don’t want to fetch actual managed objects; instead, you just want to retrieve—for example—the
largest or smallest value of a particular attribute. In OS X v10.6 and later and on iOS, you can use
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSExpressionDescription &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;to directly retrieve values that meet your criteria.
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You create a fetch request object and set its entity, just as you would for a normal fetch, but:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You specify that the fetch should return dictionaries.&lt;/span&gt;     &lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You send the fetch request a &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;setResultType: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;message with the argument &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSDictionaryResultType&lt;/span&gt;&lt;span style=&quot;color: #444444; font-size: 15px;&quot;&gt;&lt;span style=&quot;font-family: MyriadSet;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;


&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You create instances of &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSExpressionDescription &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;to specify the properties you want to retrieve.
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you just want a single value—such as the largest salary in an Employee table—then you just create a
single expression description.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are a number of steps to follow to create and use the expression description.&lt;/span&gt;     &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;First you need to create expressions (instances of &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSExpression&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;) to represent the key-path for the value&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;you’re interested in, and to represent the function you want to apply (such as &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;max: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;min:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;):&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 63&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSExpression *keyPathExpression = [NSExpression&lt;/span&gt;    &lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;     expressionForKeyPath:@&quot;salary&quot;];
&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 64&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt; NSExpression *maxSalaryExpression = [NSExpression
     expressionForFunction:@&quot;max:&lt;/span&gt; &lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;arguments:[NSArray&lt;/span&gt;   &lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;     arrayWithObject:keyPathExpression]];&lt;/span&gt;     &lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;     &lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 64&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You then create the expression description and set its name, expression, and result type.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 64&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSExpressionDescription *expressionDescription = [[NSExpressionDescription
alloc] init];&lt;/span&gt;     &lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[expressionDescription setName:@&quot;maxSalary&quot;];
[expressionDescription setExpression:maxSalaryExpression];
[expressionDescription setExpressionResultType:NSDecimalAttributeType];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 64&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Finally, you set the request’s properties to fetch just the property represented by the expression:
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 64&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[request setPropertiesToFetch:[NSArray
arrayWithObject:expressionDescription]];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 67&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Using Managed Objects
&lt;/span&gt;&lt;br /&gt;


&lt;div class=&quot;page&quot; title=&quot;Page 67&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Accessing and Modifying Properties
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 67&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSString *firstName = [anEmployee firstName];
Employee *manager = anEmployee.manager;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 67&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;newEmployee.firstName = @&quot;Stig&quot;;
[newEmployee setManager:manager];
&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 68&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can also use &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 10pt;&quot;&gt;key-value coding &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(KVC) to get or set the value of a simple attribute as illustrated in the following
code fragment.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 68&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[newEmployee setValue:@&quot;Stig&quot; forKey:@&quot;firstName&quot;];&lt;/span&gt;      &lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[aDepartment setValue:[NSNumber numberWithInteger:100000]
forKeyPath:@&quot;manager.salary&quot;];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 68&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You must, however, change attribute values in a KVC-compliant fashion. For example, the following typically
represents a programming error:
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 68&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSMutableString *mutableString = [NSMutableString stringWithString:@&quot;Stig&quot;];
[newEmployee setFirstName:mutableString];
[mutableString setString:@&quot;Laura&quot;];&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 68&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;To-many relationships
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 69&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
      &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSMutableSet *employees = [aDepartment mutableSetValueForKey:@&quot;employees&quot;];
[employees addObject:newEmployee];
[employees removeObject:firedEmployee];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;// or
[aDepartment addEmployeesObject:newEmployee];
[aDepartment removeEmployeesObject:firedEmployee];&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;div class=&quot;page&quot; title=&quot;Page 69&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[aDepartment.employees addObject:newEmployee]; &lt;b&gt;// do not do this!&lt;/b&gt;&lt;/span&gt;   &lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;then KVO change notifications are &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;not &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;emitted and the inverse relationship is not updated correctly.&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 69&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Saving Changes
&lt;/span&gt;&lt;br /&gt;
     &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can create and register managed objects with it, make changes to the objects,
and undo and redo changes as you wish. If you make changes to managed objects associated with a given
context, those changes remain local to that context until you commit the changes by sending the context a
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;save: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;message.
&lt;/span&gt;&lt;br /&gt;
     &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Managed Object IDs and URIs
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;An &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObjectID &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;object is a universal identifier for a managed object, and provides basis for uniquing
in the Core Data Framework. A managed object ID uniquely identifies the same managed object both between
managed object contexts in a single application, and in multiple applications (as in distributed systems). 
&lt;/span&gt;&lt;br /&gt;
     &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectID *moID = [managedObject objectID];&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are two forms of an object ID. When a managed object is first created, Core Data assigns it a temporary
ID; only if it is saved to a persistent store does Core Data assign a managed object a permanent ID. You can&lt;/span&gt; &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;readily discover whether an ID is temporary:
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;column&quot;&gt;
    &lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;BOOL isTemporary = [[managedObject objectID] isTemporaryID];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 70&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can also transform an object ID into a URI representation:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 71&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSURL *moURI = [[managedObject objectID] URIRepresentation];&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;div class=&quot;page&quot; title=&quot;Page 74&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Undo Management
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 74&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The Core Data framework provides automatic support for undo and redo. Undo management even extends
to transient properties (properties that are not saved to persistent store, but are specified in the managed
object model).
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 74&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Managed objects are associated with a managed object context. Each managed object context maintains an
undo manager. The context uses key-value observing to keep track of modifications to its registered objects.
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 74&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;To undo an operation, you simply send the context an &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;undo &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;message and to redo it send the context a &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;redo
&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;message. You can also roll back all changes made since the last save operation using &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;rollback &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(this also clears
the undo stack) and reset a context to its base state using &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;reset&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.
&lt;/span&gt;&lt;br /&gt;


&lt;div class=&quot;page&quot; title=&quot;Page 75&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
      &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectContext *moc = ...;
[moc processPendingChanges];  // flush operations for which you want undos
[[moc undoManager] disableUndoRegistration];
// make changes for which undo operations are not to be recorded
[moc processPendingChanges];  // flush operations for which you do not want undos
[[moc undoManager] enableUndoRegistration];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 75&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Faults
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 75&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSString *managersName =&lt;/span&gt;&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;[[anEmployee valueForKey:@&quot;manager&quot;] valueForKey:@&quot;lastName];&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 75&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 75&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or more easily using key paths:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 75&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
      &lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSString *managersName = &lt;/span&gt;&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;[anEmployee valueForKeyPath:@&quot;manager.lastName&quot;];&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 75&quot;&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 76&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Ensuring Data Is Up-to-Date
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 76&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;To refresh a managed object&#39;s property values, you use the managed object context method
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;refreshObject:mergeChanges:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. If the &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;mergeChanges &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;flag is &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;YES&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, the method merges the object&#39;s property
values with those of the object available in the persistent store coordinator; if the flag is &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, the method simply&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 15px;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;turns an object back into a fault without merging (which also causes strong references to other related managed&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 15px;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;objects to be broken, so you can use this method to trim the portion of your object graph you want to hold&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 15px;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;in memory).&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 77&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/1870966761828502138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1870966761828502138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1870966761828502138'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-2.html' title='Core Data Programming Guide Notes -- Part 2'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-1264120158018102186</id><published>2013-07-17T19:15:00.001-07:00</published><updated>2013-07-17T19:15:36.384-07:00</updated><title type='text'>Core Data Programming Guide Notes -- Part 1</title><content type='html'>This is the notes of Core Data Programing Guide from reading Apple&#39;s document&lt;br /&gt;
&lt;br /&gt;
reference:&amp;nbsp;&lt;a href=&quot;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&quot;&gt;http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 15&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Why Should You Use Core Data?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; 50% to 70% smaller as measured by lines of code&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 15&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; Core Data has a mature code base whose quality is maintained&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 15&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp; Core Data integrates well with the OS X tool chain&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

  
 
 
  &lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 15&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;What Core Data Is Not&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data is not a relational database or a relational database management system (RDBMS).&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 16&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data is not a silver bullet.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data does not rely on Cocoa bindings.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 17&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Basic Core Data Architecture&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGCgOw3ykBU2HCdXoiWp9yZxHa5cmUbEHcJT6UlAhM2fDc0EvMtyJUsooS6pAkW_J7a8MpAECd9t_XDx6RxckQ1IXg8pjIS86h6hOB9RKfz824LzqyCs14PnCbTt3bvI7NGMSpiJVNcwIg/s1600/Screen+Shot+2013-07-18+at+10.51.45+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGCgOw3ykBU2HCdXoiWp9yZxHa5cmUbEHcJT6UlAhM2fDc0EvMtyJUsooS6pAkW_J7a8MpAECd9t_XDx6RxckQ1IXg8pjIS86h6hOB9RKfz824LzqyCs14PnCbTt3bvI7NGMSpiJVNcwIg/s1600/Screen+Shot+2013-07-18+at+10.51.45+AM.png&quot; height=&quot;625&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 20&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Managed Objects and Contexts&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can think of a managed object context as an intelligent scratch pad. When you fetch objects from a
persistent store, you bring temporary copies onto the scratch pad where they form an object graph (or a
collection of object graphs). You can then modify those objects however you like. Unless you actually save
those changes, however, the persistent store remains unaltered.&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 20&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 10pt;&quot;&gt;Model objects &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;that tie into in the Core Data framework are known as &lt;/span&gt;&lt;span style=&quot;font-family: &#39;MyriadSet&#39;; font-size: 11.000000pt; font-weight: 700;&quot;&gt;managed objects&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. All managed objects
must be registered with a managed object context.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 20&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Fetch Requests&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;To retrieve data using a managed object context, you create a &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-weight: 700;&quot;&gt;fetch request&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. A fetch request is an object that
specifies what data you want, for example, “all Employees,” or “all Employees in the Marketing department
ordered by salary, highest to lowest.”&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjNddx3pygFTRaUAXzIyxu8tOAWzjvng-nnn4bJ5IotHlydiuM_cHIaDIWlXLkSyDSCVdpJ2hgZ6WSmhKQhz6LmLC-1w4RnE1tCIUyfeGeTzS1MMlQP60F71bTatVSVmV6OuUevhWIufaX/s1600/Screen+Shot+2013-07-18+at+10.57.46+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjNddx3pygFTRaUAXzIyxu8tOAWzjvng-nnn4bJ5IotHlydiuM_cHIaDIWlXLkSyDSCVdpJ2hgZ6WSmhKQhz6LmLC-1w4RnE1tCIUyfeGeTzS1MMlQP60F71bTatVSVmV6OuUevhWIufaX/s1600/Screen+Shot+2013-07-18+at+10.57.46+AM.png&quot; height=&quot;387&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 21&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Persistent Store Coordinator&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Between managed object contexts and
persistent object stores there is a &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-weight: 700;&quot;&gt;persistent store coordinator&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 23&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Persistent Documents&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSPersistentDocument &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;class
is a subclass of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSDocument &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;that is designed to let you easily take advantage of the Core Data framework. By
default, an &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSPersistentDocument &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;instance creates its own ready-to-use persistence stack, including a
managed object context and a single persistent object store. There is in this case a one-to-one mapping
between a document and an external data store.&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 24&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Managed Objects and the Managed Object Model&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-weight: 700;&quot;&gt;managed object model &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is a schema that provides a description of the managed
objects, or entities, used by your application&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF4xTWgCQlwZHOvOO8EO0b6dN6DdFim0vj_tJ14ox2SGbLLzdx7p1XhFDeRAlEpVy3p0W7ZkJDQ_cZ2Ejg8LVdJ6jvFMWV96kF01lSGKM3Nae_djDyQiPIOuBpSL9rvdJl2oBb6kmCZGW1/s1600/Screen+Shot+2013-07-18+at+11.09.01+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF4xTWgCQlwZHOvOO8EO0b6dN6DdFim0vj_tJ14ox2SGbLLzdx7p1XhFDeRAlEpVy3p0W7ZkJDQ_cZ2Ejg8LVdJ6jvFMWV96kF01lSGKM3Nae_djDyQiPIOuBpSL9rvdJl2oBb6kmCZGW1/s1600/Screen+Shot+2013-07-18+at+11.09.01+AM.png&quot; height=&quot;230&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdAJX6E4jg9pqGmqfRnVObVZgpjpbgqbg4whWcPZ7Jf9bTAYDlaitJIGUZNnQlIGobS53hJlKzz-BvJBEKIt2hv7gjbNMIrAu1aDspuIHRalWQt_6EHRCb160WdyxSXg1tJS2nMA13VhwJ/s1600/Screen+Shot+2013-07-18+at+11.10.44+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdAJX6E4jg9pqGmqfRnVObVZgpjpbgqbg4whWcPZ7Jf9bTAYDlaitJIGUZNnQlIGobS53hJlKzz-BvJBEKIt2hv7gjbNMIrAu1aDspuIHRalWQt_6EHRCb160WdyxSXg1tJS2nMA13VhwJ/s1600/Screen+Shot+2013-07-18+at+11.10.44+AM.png&quot; height=&quot;500&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 25&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Managed objects must be instances of either &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or of a subclass of &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObject&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.
&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is able to represent any entity.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Managed Object Models&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;he schema is represented by a managed object
model—an instance of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObjectModel&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. In general, the richer the model, the better Core Data is
able to support your application.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 26&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Features of a Managed Object Model&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 26&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A managed object model is an instance of the &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;NSManagedObjectModel &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;class&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Entities&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A model contains &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSEntityDescription &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;objects that represent the model&#39;s entities. Two important features
of an entity are its name, and the name of the class used to represent the entity at runtime.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 26&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;Entity Inheritance&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyoVufsSEONW8AKiy3tkKpqXbud2kkVIH45ll0rUiUsabY7OQTA5DRnBrkd3C6ZpMFT8lPQwmfV7dd7hYXWGExTsnhYbgWf8UZCzozW5ZR4njmDrAcEEgaphruydORzyqa34gQA56Q43JY/s1600/Screen+Shot+2013-07-18+at+11.21.16+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyoVufsSEONW8AKiy3tkKpqXbud2kkVIH45ll0rUiUsabY7OQTA5DRnBrkd3C6ZpMFT8lPQwmfV7dd7hYXWGExTsnhYbgWf8UZCzozW5ZR4njmDrAcEEgaphruydORzyqa34gQA56Q43JY/s1600/Screen+Shot+2013-07-18+at+11.21.16+AM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 27&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;Abstract Entities&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can specify that an entity is abstract—that is, that you will not create any instances of that entity. You
typically make an entity abstract if you have a number of entities that all represent specializations of (inherit
from) a common entity which should not itself be instantiated&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 27&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Properties&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;An entity&#39;s properties are its attributes and relationships, including its fetched properties (if it has any).&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A property
name cannot be the same as any no-parameter method name of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSObject &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;or &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObject&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;—for
example, you cannot give a property the name “description” (see &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSPropertyDescription&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 28&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;Attributes&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data natively supports a variety of attribute types, such as string, date, and integer (represented as
instances of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSString&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSDate&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, and &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSNumber &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;respectively).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can specify that an attribute is optional—that is, it is not required to have a value. In general, however,
you are discouraged from doing so—especially for numeric values (&lt;b&gt;typically you can get better results using
a mandatory attribute with a default value—in the model—of &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;&lt;b&gt;0&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;). The reason for this is that SQL has special
comparison behavior for &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NULL &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;that is unlike Objective-C&#39;s &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NULL &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;in a database is not the same as &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, and
searches for &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;0 &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;will not match columns with &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 28&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;Relationships&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Core Data supports to-one and to-many relationships, and &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-weight: 700;&quot;&gt;fetched properties&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. Fetched properties represent
weak, one-way relationships. I&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 29&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Fetch Request Templates&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You use the &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSFetchRequest &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;class to describe fetch requests to retrieve objects from a persistent store. It is
often the case that you want to execute the same request on multiple occasions, or execute requests that
follow a given pattern but which contain variable elements (typically supplied by the user). For example, you
might want to be able to retrieve all publications written by a certain author, perhaps after a date specified
by the user at runtime.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can predefine fetch requests and store them in a managed object model as named templates. This allows
you to pre-define queries that you can retrieve as necessary from the model. Typically, you define fetch request
templates using the Xcode data modeling tool (see &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;Xcode Tools for Core Data &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;). The template may include
variables, as shown in Figure 2.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYFEK6OHuGz4RQnFwZBwjCS3lPKiNObB0kVtXtnzoIhh31E81vlGR0PKO_VjGrVDc8rRW-cnE7a2qxmyifKD-5Ap79iL62hane278PGyZWiMoAKCTCiyUbQmOUpVq1gKMbERgLOtlBzXsB/s1600/Screen+Shot+2013-07-18+at+11.29.04+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYFEK6OHuGz4RQnFwZBwjCS3lPKiNObB0kVtXtnzoIhh31E81vlGR0PKO_VjGrVDc8rRW-cnE7a2qxmyifKD-5Ap79iL62hane278PGyZWiMoAKCTCiyUbQmOUpVq1gKMbERgLOtlBzXsB/s1600/Screen+Shot+2013-07-18+at+11.29.04+AM.png&quot; height=&quot;92&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 29&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Configurations&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 29&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;A configuration has a name and an associated set of entities.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 30&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You typically use configurations if you want to store different entities in different stores. A persistent store
coordinator can only have one managed object model, so by default each store associated with a given
coordinator must contain the same entities.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhACv5gfBYjkIcQvvFq0XiEvij5kiJT8oS46ObWhmwkr6FdwcMR9dyJCfQTKCSgbp-u-rbx5Glpwu3GP8VhjLeWkIfne5O5na7cMuIEuyjVv1VCQY-Tx1xbBBr7HEwWO32XOidX25lqORT5/s1600/Screen+Shot+2013-07-18+at+11.31.52+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhACv5gfBYjkIcQvvFq0XiEvij5kiJT8oS46ObWhmwkr6FdwcMR9dyJCfQTKCSgbp-u-rbx5Glpwu3GP8VhjLeWkIfne5O5na7cMuIEuyjVv1VCQY-Tx1xbBBr7HEwWO32XOidX25lqORT5/s1600/Screen+Shot+2013-07-18+at+11.31.52+AM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 31&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #222222; font-family: MyriadSet; font-size: 24pt;&quot;&gt;Using a Managed Object Model&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 31&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Creating and Loading a Managed Object Model&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 31&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet;&quot;&gt;&lt;span style=&quot;font-size: 20px;&quot;&gt;Managed Object Model means abc.xcdatamodeld&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet;&quot;&gt;&lt;span style=&quot;font-size: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Compiling a Data Model&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The model file is compiled using the model compiler, &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;momc&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;,
to remove the extraneous information and make runtime loading of the resource as efficient as possible. An
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;xcdatamodeld &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;“source” directory is compiled into a &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;momd &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;deployment directory, and an &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;xcdatamodel
&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;“source” file is compiled into a &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;mom &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;deployment file.&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;div class=&quot;page&quot; title=&quot;Page 31&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					
					&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;momc &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is located in &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;/Developer/usr/bin/&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;. If you want to use it in your own build scripts, its usage is &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;momc
source destination&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, where &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;source &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is the path of the Core Data model to compile and &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;destination &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;is
the path of the output.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 31&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Loading a Data Model&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 31&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you want to load a model yourself, there are two mechanisms you can use:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;1.You can load a single model from a specific URL, using the instance method &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;initWithContentsOfURL:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;2.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can create a merged model from a specific collection of bundles, using the class method
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;mergedModelFromBundles:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;div class=&quot;page&quot; title=&quot;Page 32&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 32&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Problems May Arise if Your Project Contains More Than One Model&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 32&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you simply rename your model file, Core Data attempts to merge the current and the old versions and
you get an error similar to the following:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 32&quot;&gt;
			&lt;div class=&quot;section&quot;&gt;
				&lt;div class=&quot;layoutArea&quot;&gt;
					&lt;div class=&quot;column&quot;&gt;
						&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;reason = &quot;&#39;Can&#39;t merge models with two different entities named
&#39;EntityName&#39;&#39;&quot;;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 32&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you create a new model that contains different entities from those in your original model, then Core
Data merges the old and new models. If you have an existing store, you get an error similar to the following
when you attempt to open it:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 32&quot;&gt;
			&lt;div class=&quot;section&quot;&gt;
				&lt;div class=&quot;layoutArea&quot;&gt;
					&lt;div class=&quot;column&quot;&gt;
						&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;reason = &quot;The model used to open the store is incompatible with the one
used to create the store&quot;;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 32&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;There are two solutions:&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;1. Make sure that you clean any old build products before running the application. If the application bundle
itself contains old model files, you can delete the application.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;2.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Instead of &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;mergedModelFromBundles:&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;, use &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;initWithContentsOfURL: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;to initialize the model. The
URL uniquely identifies a model so that Core Data will not merge the current model with any legacy models.&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Changing the Schema Makes a Model Incompatible With Old Stores&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;If you add a new entity or a new
attribute to an existing entity, you will not be able to open old stores; if you add a validation constraint or set
a new default value for an attribute, you will be able to open old stores.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;section&quot;&gt;
				&lt;div class=&quot;layoutArea&quot;&gt;
					&lt;div class=&quot;column&quot;&gt;
						&lt;span style=&quot;font-family: &#39;MyriadSet&#39;; font-size: 11.000000pt; font-weight: 700;&quot;&gt;Important: &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Ifyouwanttochangethemodelbutalsoretaintheabilitytoopenstorescreatedusinga
previous version of the model, &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt; font-style: italic;&quot;&gt;you must keep the previous version of the model &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;(as a version in a versioned
model). Core Data cannot open a store for which it has no compatible model. Thus, if you want to change
the model but also retain the ability to open existing stores, you must:
&lt;/span&gt;&lt;br /&gt;

						&lt;ol&gt;
&lt;li style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700; vertical-align: 1.000000pt;&quot;&gt;
								&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;Ensure that you have a versioned model—if you don’t, make the current model into a versioned model.
&lt;/span&gt;&lt;br /&gt;

							&lt;/li&gt;
&lt;li style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700; vertical-align: 1.000000pt;&quot;&gt;
								&lt;span style=&quot;font-size: 11pt; font-style: italic; font-weight: 500;&quot;&gt;Before editing the schema &lt;/span&gt;&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-weight: 500;&quot;&gt;create a new version of the current model&lt;/span&gt;&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;.
&lt;/span&gt;&lt;br /&gt;

							&lt;/li&gt;
&lt;li style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700; vertical-align: 1.000000pt;&quot;&gt;
								&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;Edit the new current version of the model, leaving the old version unaltered.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 11pt; font-weight: 500;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

							&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Accessing and Using a Managed Object Model at Runtime&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;Thus to get
the model from a managed object context, you use the following code:&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;[[&amp;lt;#A managed object context#&amp;gt; persistentStoreCoordinator] managedObjectModel];&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 33&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can also retrieve the model from an entity description, so given a managed object you can retrieve its
entity description and hence the model, as shown in the following example.&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;[[&amp;lt;#A managed object#&amp;gt; entity] managedObjectModel];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Creating Fetch Request Templates Programmatically&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 34&quot;&gt;
			&lt;div class=&quot;section&quot;&gt;
				&lt;div class=&quot;layoutArea&quot;&gt;
					&lt;div class=&quot;column&quot;&gt;
						&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectModel *model = &amp;lt;#Get a model#&amp;gt;;
NSFetchRequest *requestTemplate = [[NSFetchRequest alloc] init];
NSEntityDescription *publicationEntity =
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;    [[model entitiesByName] objectForKey:@&quot;Publication&quot;];
[requestTemplate setEntity:publicationEntity];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat:
    @&quot;(mainAuthor.firstName like[cd] $FIRST_NAME) AND \
        (mainAuthor.lastName like[cd] $LAST_NAME) AND \
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;        (publicationDate &amp;gt; $DATE)&quot;];
[requestTemplate setPredicate:predicateTemplate];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[model setFetchRequestTemplate:requestTemplate
    forName:@&quot;PublicationsForAuthorSinceDate&quot;];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 34&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Accessing Fetch Request Templates&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;div class=&quot;page&quot; title=&quot;Page 35&quot;&gt;
			&lt;div class=&quot;section&quot;&gt;
				&lt;div class=&quot;layoutArea&quot;&gt;
					&lt;div class=&quot;column&quot;&gt;
						&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectModel *model = &amp;lt;#Get a model#&amp;gt;;&lt;br /&gt;
NSError *error = nil;&lt;br /&gt;
NSDictionary *substitutionDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
&lt;/span&gt;&lt;br /&gt;

						&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;    @&quot;Fiona&quot;, @&quot;FIRST_NAME&quot;, @&quot;Verde&quot;, @&quot;LAST_NAME&quot;,
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;    [NSDate dateWithTimeIntervalSinceNow:-31356000], @&quot;DATE&quot;, nil];
NSFetchRequest *fetchRequest =
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;    [model fetchRequestFromTemplateWithName:@&quot;PublicationsForAuthorSinceDate&quot;
            substitutionVariables:substitutionDictionary];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSArray *results =&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;&amp;nbsp; &amp;nbsp; [aManagedObjectContext executeFetchRequest:fetchRequest error:&amp;amp;error];&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 35&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;Localizing a Managed Object Model&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You localize a model by providing a localization dictionary that follows the pattern shown in the table below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 18pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;div class=&quot;page&quot; title=&quot;Page 35&quot;&gt;
			&lt;table style=&quot;border-collapse: collapse;&quot;&gt;&lt;colgroup&gt;&lt;col style=&quot;width: 62.395486%;&quot;&gt;&lt;/col&gt;&lt;col style=&quot;width: 28.398312%;&quot;&gt;&lt;/col&gt;&lt;col style=&quot;width: 9.206202%;&quot;&gt;&lt;/col&gt;
				&lt;/colgroup&gt;&lt;tbody&gt;
&lt;tr&gt;
					&lt;td style=&quot;background-color: rgb(87.060000%, 91.760000%, 95.290000%); border-bottom-color: rgb(48.627451%, 63.137255%, 70.196078%); border-bottom-width: 0.400000pt; border-left-color: rgb(100.000000%, 100.000000%, 100.000000%); border-left-width: 0.500000pt; border-right-color: rgb(100.000000%, 100.000000%, 100.000000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(100.000000%, 100.000000%, 100.000000%); border-top-width: 0.500000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700;&quot;&gt;Key
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;background-color: rgb(87.060000%, 91.760000%, 95.290000%); border-bottom-color: rgb(48.425197%, 62.992126%, 70.078740%); border-bottom-width: 0.400000pt; border-left-color: rgb(100.000000%, 100.000000%, 100.000000%); border-left-width: 0.500000pt; border-right-color: rgb(100.000000%, 100.000000%, 100.000000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(100.000000%, 100.000000%, 100.000000%); border-top-width: 0.500000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700;&quot;&gt;Value
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;background-color: rgb(87.060000%, 91.760000%, 95.290000%); border-bottom-color: rgb(48.412698%, 63.095238%, 69.841270%); border-bottom-width: 0.400000pt; border-left-color: rgb(100.000000%, 100.000000%, 100.000000%); border-left-width: 0.500000pt; border-right-color: rgb(100.000000%, 100.000000%, 100.000000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(100.000000%, 100.000000%, 100.000000%); border-top-width: 0.500000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(20.000000%, 20.000000%, 20.000000%); font-family: &#39;MyriadSet&#39;; font-size: 10.000000pt; font-weight: 700;&quot;&gt;Note
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
				&lt;/tr&gt;
&lt;tr&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.627451%, 63.137255%, 70.196078%); border-bottom-width: 0.400000pt; border-left-color: rgb(92.828685%, 92.828685%, 92.828685%); border-left-width: 0.500000pt; border-right-color: rgb(92.800000%, 92.800000%, 92.800000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.627451%, 63.137255%, 70.196078%); border-top-width: 0.400000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;Entity/&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;NonLocalizedEntityName&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.425197%, 62.992126%, 70.078740%); border-bottom-width: 0.400000pt; border-left-color: rgb(92.800000%, 92.800000%, 92.800000%); border-left-width: 0.500000pt; border-right-color: rgb(92.800000%, 92.800000%, 92.800000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.425197%, 62.992126%, 70.078740%); border-top-width: 0.400000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;LocalizedEntityName&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.412698%, 63.095238%, 69.841270%); border-bottom-width: 0.400000pt; border-left-color: rgb(92.800000%, 92.800000%, 92.800000%); border-left-width: 0.500000pt; border-right-color: rgb(92.828685%, 92.828685%, 92.828685%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.412698%, 63.095238%, 69.841270%); border-top-width: 0.400000pt;&quot;&gt;
					&lt;/td&gt;
				&lt;/tr&gt;
&lt;tr&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.627451%, 63.137255%, 70.196078%); border-bottom-width: 0.400000pt; border-left-color: rgb(92.828685%, 92.828685%, 92.828685%); border-left-width: 0.500000pt; border-right-color: rgb(92.800000%, 92.800000%, 92.800000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.627451%, 63.137255%, 70.196078%); border-top-width: 0.400000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;Property/&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;NonLocalizedPropertyName&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;/Entity/&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;EntityName&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.425197%, 62.992126%, 70.078740%); border-bottom-width: 0.400000pt; border-left-color: rgb(92.800000%, 92.800000%, 92.800000%); border-left-width: 0.500000pt; border-right-color: rgb(92.800000%, 92.800000%, 92.800000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.425197%, 62.992126%, 70.078740%); border-top-width: 0.400000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;LocalizedPropertyName&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.412698%, 63.095238%, 69.841270%); border-bottom-width: 0.400000pt; border-left-color: rgb(92.800000%, 92.800000%, 92.800000%); border-left-width: 0.500000pt; border-right-color: rgb(92.828685%, 92.828685%, 92.828685%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.412698%, 63.095238%, 69.841270%); border-top-width: 0.400000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;1
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
				&lt;/tr&gt;
&lt;tr&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.627451%, 63.137255%, 70.196078%); border-bottom-width: 0.350000pt; border-left-color: rgb(92.828685%, 92.828685%, 92.828685%); border-left-width: 0.500000pt; border-right-color: rgb(92.800000%, 92.800000%, 92.800000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.627451%, 63.137255%, 70.196078%); border-top-width: 0.400000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;Property/&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;NonLocalizedPropertyName&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.425197%, 62.992126%, 70.078740%); border-bottom-width: 0.350000pt; border-left-color: rgb(92.800000%, 92.800000%, 92.800000%); border-left-width: 0.500000pt; border-right-color: rgb(92.800000%, 92.800000%, 92.800000%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.425197%, 62.992126%, 70.078740%); border-top-width: 0.400000pt;&quot;&gt;
						&lt;div class=&quot;layoutArea&quot;&gt;
							&lt;div class=&quot;column&quot;&gt;
								&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;LocalizedPropertyName&lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;&quot;
&lt;/span&gt;&lt;br /&gt;

							&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
					&lt;td style=&quot;border-bottom-color: rgb(48.616601%, 62.845850%, 69.960474%); border-bottom-width: 0.350000pt; border-left-color: rgb(92.800000%, 92.800000%, 92.800000%); border-left-width: 0.500000pt; border-right-color: rgb(92.828685%, 92.828685%, 92.828685%); border-right-width: 0.500000pt; border-style: solid; border-top-color: rgb(48.412698%, 63.095238%, 69.841270%); border-top-width: 0.400000pt;&quot;&gt;
					&lt;/td&gt;
				&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 36&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can access the localization dictionary using the method &lt;/span&gt;&lt;span style=&quot;color: rgb(26.670000%, 26.670000%, 26.670000%); font-family: &#39;Menlo&#39;; font-size: 10.000000pt;&quot;&gt;localizationDictionary&lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;

		
	
	
		&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 36&quot;&gt;
			&lt;div class=&quot;layoutArea&quot;&gt;
				&lt;div class=&quot;column&quot;&gt;
					&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Strings File&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;The easiest way to localize a model is to create a corresponding strings file—the strings file name is the same
as the model file name, but with a &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;.strings &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;rather than a &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;.xcdatamodel &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;extension&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;div class=&quot;page&quot; title=&quot;Page 36&quot;&gt;
			&lt;div class=&quot;section&quot;&gt;
				&lt;div class=&quot;layoutArea&quot;&gt;
					&lt;div class=&quot;column&quot;&gt;
						&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;&quot;Entity/Emp&quot; = &quot;Employee&quot;;
&quot;Property/firstName&quot; = &quot;First Name&quot;;
&quot;Property/lastName&quot; = &quot;Last Name&quot;;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;&quot;Property/salary&quot; = &quot;Salary&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;

		
	
	
		&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;Setting a Localization Dictionary Programmatically&lt;/span&gt;&lt;br /&gt;

		
	
	
		&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;You can set a localization dictionary at runtime using the &lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;NSManagedObjectModel &lt;/span&gt;&lt;span style=&quot;font-family: MyriadSet; font-size: 11pt;&quot;&gt;method
&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Menlo; font-size: 10pt;&quot;&gt;setLocalizationDictionary:&lt;/span&gt;&lt;span style=&quot;color: #0769ae; font-family: MyriadSet; font-size: 15pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

				&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 37&quot;&gt;
			
			&lt;div class=&quot;section&quot;&gt;
				&lt;div class=&quot;layoutArea&quot;&gt;
					&lt;div class=&quot;column&quot;&gt;
						&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSManagedObjectModel *mom = [[NSManagedObjectModel alloc] init];
NSEntityDescription *runEntity = [[NSEntityDescription alloc] init];
[runEntity setName:@&quot;Run&quot;];
[runEntity setManagedObjectClassName:@&quot;Run&quot;];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[mom setEntities:@[runEntity]];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSMutableArray *runProperties = [NSMutableArray array];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSAttributeDescription *dateAttribute = [[NSAttributeDescription alloc] init];
[runProperties addObject:dateAttribute];
[dateAttribute setName:@&quot;date&quot;];
[dateAttribute setAttributeType:NSDateAttributeType];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[dateAttribute setOptional:NO];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSAttributeDescription *idAttribute= [[NSAttributeDescription alloc] init];
[runProperties addObject:idAttribute];
[idAttribute setName:@&quot;processID&quot;];
[idAttribute setAttributeType:NSInteger32AttributeType];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[idAttribute setOptional:NO];
[idAttribute setDefaultValue:@0];
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSPredicate *validationPredicate = [NSPredicate predicateWithFormat:@&quot;SELF &amp;gt;= 0&quot;];
NSString *validationWarning = @&quot;Process ID &amp;lt; 0&quot;;&lt;br /&gt;
[idAttribute setValidationPredicates:@[validationPredicate]
&lt;/span&gt;&lt;br /&gt;

						&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;    withValidationWarnings:@[validationWarning]];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[runEntity setProperties:runProperties];
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;NSDictionary *localizationDictionary = @{
    @&quot;Property/processID/Entity/Run&quot; : @&quot;Process ID&quot;,
    @&quot;Property/date/Entity/Run&quot; : @&quot;Date&quot;
    @&quot;ErrorString/Process ID &amp;lt; 0&quot; : @&quot;Process ID must not be less than 0&quot; };
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Menlo&#39;; font-size: 9.000000pt;&quot;&gt;[mom setLocalizationDictionary:localizationDictionary];
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/1264120158018102186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1264120158018102186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1264120158018102186'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/core-data-programming-guide-notes-part-1.html' title='Core Data Programming Guide Notes -- Part 1'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGCgOw3ykBU2HCdXoiWp9yZxHa5cmUbEHcJT6UlAhM2fDc0EvMtyJUsooS6pAkW_J7a8MpAECd9t_XDx6RxckQ1IXg8pjIS86h6hOB9RKfz824LzqyCs14PnCbTt3bvI7NGMSpiJVNcwIg/s72-c/Screen+Shot+2013-07-18+at+10.51.45+AM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-7036282453028690266</id><published>2013-07-10T22:31:00.000-07:00</published><updated>2013-07-10T22:31:00.375-07:00</updated><title type='text'>iOS - set certain format to numbers</title><content type='html'>&lt;br /&gt;
If you have a number, like 123, but you want to display like 000123, you can do this like&lt;br /&gt;
&lt;br /&gt;








&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp;&lt;/span&gt;NSString&lt;span class=&quot;s1&quot;&gt; *transID =[&lt;/span&gt;NSString&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;stringWithFormat&lt;span class=&quot;s1&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;@&quot;%06d&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;,123&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Then it will fill up the empty space with 0&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/7036282453028690266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/ios-set-certain-format-to-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/7036282453028690266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/7036282453028690266'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/ios-set-certain-format-to-numbers.html' title='iOS - set certain format to numbers'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-2723483346512456406</id><published>2013-07-10T18:49:00.000-07:00</published><updated>2013-07-10T18:49:38.298-07:00</updated><title type='text'>Ten iOS interview questions</title><content type='html'>I had viewed some blogs, which mentioned ten iOS interview questions. I think it&#39;s basic but important. If you have 2-3 years iOS development&amp;nbsp;experiments, you should answer the questions easily.&lt;br /&gt;
&lt;br /&gt;
Ok, let&#39;s start.&lt;br /&gt;
&lt;br /&gt;
1. Have you use objective-c runtime programming? If you did, what you use it for.&lt;br /&gt;
&lt;br /&gt;
2. Have you use multi thread core data? which method you use? How do you do with &amp;nbsp; NSPersistenStoreCoordinator,NsManagedObjectContext and NSManagedObject&lt;br /&gt;
&lt;br /&gt;
3. Have you use CoreAnimation and COreGraphics. What is the relationship between UI framework, CA framework and CG framework.&lt;br /&gt;
&lt;br /&gt;
4. Have you use CoreText or CoreImage? Tell me about that.&lt;br /&gt;
&lt;br /&gt;
5. What is NSNotification and KVO? What&#39;s the difference between them? when to use NSNotification and when to use KVO? can you use protocol and delegate to implement the same function like NSNotification and KVO? why?&lt;br /&gt;
&lt;br /&gt;
6. Have you use NSOperationQueue? Why you use NSOperationQueue and what for? Tell me about the difference between NSOperationQueue and GCD.&lt;br /&gt;
&lt;br /&gt;
7. What you need to care when you use GCD and block? are they the same thing?&lt;br /&gt;
&lt;br /&gt;
8. How to deal with&amp;nbsp;Asynchronous Network? how do you implement that?&lt;br /&gt;
&lt;br /&gt;
9. How do you think of Objective-C, pros and cons? Have you think about the redo some functions about Objective-C?&lt;br /&gt;
&lt;br /&gt;
10. Have you implement a framework or&amp;nbsp;library? If you do, tell me about that. If you do not, try to design a public API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These questions might be too hard for junior iOS developer. If you need to answer all of that, maybe you at least have 2-3 years development experiments.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Reference:&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.blogger.com/goog_2046067751&quot;&gt;http://onevcat.com/2013/04/ios-interview/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://wufawei.com/2013/05/11-interview-questions/&quot;&gt;http://wufawei.com/2013/05/11-interview-questions/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/2723483346512456406/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/07/ten-ios-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/2723483346512456406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/2723483346512456406'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/07/ten-ios-interview-questions.html' title='Ten iOS interview questions'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-7249076206481785056</id><published>2013-06-02T22:00:00.000-07:00</published><updated>2013-06-02T22:00:34.109-07:00</updated><title type='text'>iOS -- A new way to implement segment control</title><content type='html'>&lt;br /&gt;
Recently I have found a new way to implement segment control, wich is HMSegmentControl.&lt;br /&gt;
&lt;br /&gt;
I found a very good project in GitHub, here is the link:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/HeshamMegid/HMSegmentedControl&quot;&gt;https://github.com/HeshamMegid/HMSegmentedControl&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNuc2kKOGweZbI8NW9rfKwAtnE5Gn-nkh-02-lF7z37VIAVGM2NeAFi3sxnC3536BRk0IbGkGhHK5RSU8F5EQVTWxIWX25haCmNBI7eqhKIN2Itp43QlqsFzbvR-E7N5Zc-EHpIcqHTALZ/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNuc2kKOGweZbI8NW9rfKwAtnE5Gn-nkh-02-lF7z37VIAVGM2NeAFi3sxnC3536BRk0IbGkGhHK5RSU8F5EQVTWxIWX25haCmNBI7eqhKIN2Itp43QlqsFzbvR-E7N5Zc-EHpIcqHTALZ/s1600/1.png&quot; height=&quot;400&quot; width=&quot;212&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/7249076206481785056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/06/ios-new-way-to-implement-segment-control.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/7249076206481785056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/7249076206481785056'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/06/ios-new-way-to-implement-segment-control.html' title='iOS -- A new way to implement segment control'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNuc2kKOGweZbI8NW9rfKwAtnE5Gn-nkh-02-lF7z37VIAVGM2NeAFi3sxnC3536BRk0IbGkGhHK5RSU8F5EQVTWxIWX25haCmNBI7eqhKIN2Itp43QlqsFzbvR-E7N5Zc-EHpIcqHTALZ/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-2699333078150421061</id><published>2013-05-30T22:57:00.001-07:00</published><updated>2013-05-30T22:57:29.122-07:00</updated><title type='text'>SQL -- Understand Index (Clustered vs. Non-Clustered index)</title><content type='html'>Here is three&amp;nbsp;articles&amp;nbsp;to help you to understand Index in SQL.&lt;br /&gt;
&lt;br /&gt;






&lt;!--StartFragment--&gt;

&lt;br /&gt;
&lt;div class=&quot;O1&quot; style=&quot;direction: ltr; margin-bottom: 0pt; margin-left: .81in; margin-top: 3.84pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: justify; text-indent: -.31in; text-justify: inter-ideograph; unicode-bidi: embed; word-break: normal;&quot;&gt;
&lt;span style=&quot;font-size: 16.0pt;&quot;&gt;&lt;span style=&quot;font-family: Arial; mso-special-format: bullet;&quot;&gt;–&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Calibri; font-size: 16pt; font-style: italic;&quot;&gt;&lt;a href=&quot;http://www.itbully.com/articles/sql-indexing-and-performance-part-2-clustered-and-non-clustered&quot;&gt;http://www.itbully.com/articles/sql-indexing-and-performance-part-2-clustered-and-non-clustered&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;O1&quot; style=&quot;direction: ltr; margin-bottom: 0pt; margin-left: .81in; margin-top: 3.84pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: justify; text-indent: -.31in; text-justify: inter-ideograph; unicode-bidi: embed; word-break: normal;&quot;&gt;
&lt;span style=&quot;font-size: 16.0pt;&quot;&gt;&lt;span style=&quot;font-family: Arial; mso-special-format: bullet;&quot;&gt;–&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Calibri; font-size: 16pt; font-style: italic;&quot;&gt;&lt;a href=&quot;http://www.devtoolshed.com/content/clustered-index-vs-non-clustered-index-sql-server&quot;&gt;http://www.devtoolshed.com/content/clustered-index-vs-non-clustered-index-sql-server&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;O1&quot; style=&quot;direction: ltr; margin-bottom: 0pt; margin-left: .81in; margin-top: 3.84pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: justify; text-indent: -.31in; text-justify: inter-ideograph; unicode-bidi: embed; word-break: normal;&quot;&gt;
&lt;span style=&quot;font-size: 16.0pt;&quot;&gt;&lt;span style=&quot;font-family: Arial; mso-special-format: bullet;&quot;&gt;–&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Calibri; font-size: 16pt; font-style: italic;&quot;&gt;&lt;a href=&quot;http://odetocode.com/articles/70.aspx&quot;&gt;http://odetocode.com/articles/70.aspx&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/2699333078150421061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/05/sql-understand-index-clustered-vs-non.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/2699333078150421061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/2699333078150421061'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/05/sql-understand-index-clustered-vs-non.html' title='SQL -- Understand Index (Clustered vs. Non-Clustered index)'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-6151309894310970544</id><published>2013-05-29T20:56:00.001-07:00</published><updated>2013-05-29T20:56:24.519-07:00</updated><title type='text'>Xamarin -- Running .Net in Mac </title><content type='html'>I just found a awesome IDE, Xamarin, which can run .Net project in Mac OS.&lt;br /&gt;
&lt;br /&gt;
Here is the link:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.go-mono.com/mono-downloads/download.html&quot;&gt;http://monodevelop.com/Download&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsSKPL8GoyUvDubyQ7nc9RVmHUEJQ2UQvu6bN621H11OGMYcTQ-2le6woELXdTADWWl9Wx2AOnYC9d5gwB-py5vK3sm849IjftwZFz2Z7nrmk4kVM-BjlyamI-4JFZUotchcvEnWA2Pg4u/s1600/ss-main-window.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsSKPL8GoyUvDubyQ7nc9RVmHUEJQ2UQvu6bN621H11OGMYcTQ-2le6woELXdTADWWl9Wx2AOnYC9d5gwB-py5vK3sm849IjftwZFz2Z7nrmk4kVM-BjlyamI-4JFZUotchcvEnWA2Pg4u/s1600/ss-main-window.png&quot; height=&quot;276&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/6151309894310970544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/05/xamarin-running-net-in-mac.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/6151309894310970544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/6151309894310970544'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/05/xamarin-running-net-in-mac.html' title='Xamarin -- Running .Net in Mac '/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsSKPL8GoyUvDubyQ7nc9RVmHUEJQ2UQvu6bN621H11OGMYcTQ-2le6woELXdTADWWl9Wx2AOnYC9d5gwB-py5vK3sm849IjftwZFz2Z7nrmk4kVM-BjlyamI-4JFZUotchcvEnWA2Pg4u/s72-c/ss-main-window.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-9004645835731427749</id><published>2013-04-20T03:37:00.001-07:00</published><updated>2013-04-20T03:37:32.866-07:00</updated><title type='text'>Add a Textfield in UIActionsheet</title><content type='html'>If you want to add a UITextfield to a UIActionsheet in ios development, you can not just directly add the textfield to the actionsheet. &lt;br /&gt;
&lt;br /&gt;
If you just add a textfield to actionsheet, you can not type any words in the textfield. It seems like some methods in textfield is not working&amp;nbsp;properly.&lt;br /&gt;
&lt;br /&gt;
So is it any way to add the textfield to actionsheet? The answer is yes.&lt;br /&gt;
&lt;br /&gt;
Thanks to the following answer:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://stackoverflow.com/questions/4367494/keypad-not-working-for-textfield-in-uiactionsheet&quot;&gt;http://stackoverflow.com/questions/4367494/keypad-not-working-for-textfield-in-uiactionsheet&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
we can successfully add a textfield in actionsheet. &amp;nbsp;The idea is show the actionsheet first, and then add the textfield above the actionsheet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I just dont want to go through the detail. I have add the code to github. If you are looking for the solution about this. You can download it freely.&lt;br /&gt;
&lt;br /&gt;
Here is the link:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/fisherv1/actionsheetWithTextFiled.git&quot;&gt;https://github.com/fisherv1/actionsheetWithTextFiled.git&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is what it looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRx08klTwSLb9Wc7ZjqX4GdQ_n54vwlKVbENgRyD8n8QwQGsIRtDvQdoLX5-ziY0QOFyvcTVOZNLppCMz_0dpzhocMvtVgKJgB-ZhEVtHzwsGS4LoXb1PQgQCmZb9_sXHFAPme_8NFtDD6/s1600/Screen+Shot+2013-04-20+at+8.32.23+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRx08klTwSLb9Wc7ZjqX4GdQ_n54vwlKVbENgRyD8n8QwQGsIRtDvQdoLX5-ziY0QOFyvcTVOZNLppCMz_0dpzhocMvtVgKJgB-ZhEVtHzwsGS4LoXb1PQgQCmZb9_sXHFAPme_8NFtDD6/s1600/Screen+Shot+2013-04-20+at+8.32.23+PM.png&quot; height=&quot;320&quot; width=&quot;216&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/9004645835731427749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/04/add-textfield-in-uiactionsheet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/9004645835731427749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/9004645835731427749'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/04/add-textfield-in-uiactionsheet.html' title='Add a Textfield in UIActionsheet'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRx08klTwSLb9Wc7ZjqX4GdQ_n54vwlKVbENgRyD8n8QwQGsIRtDvQdoLX5-ziY0QOFyvcTVOZNLppCMz_0dpzhocMvtVgKJgB-ZhEVtHzwsGS4LoXb1PQgQCmZb9_sXHFAPme_8NFtDD6/s72-c/Screen+Shot+2013-04-20+at+8.32.23+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-6064510619219372237</id><published>2013-03-19T23:52:00.000-07:00</published><updated>2014-06-25T23:42:35.048-07:00</updated><title type='text'>Ubuntu setup Git Server</title><content type='html'>1. Setup&lt;br /&gt;
&lt;br /&gt;
1.1 install Git-Core in Ubuntu server&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp; sudo apt-get install git-core&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
1.2 install Gitosis in Ubuntu server&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp; sudo apt-get install python-setuptools&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mkdir ~/src&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cd &amp;nbsp;~/src&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; git clone https://github.com/res0nat0r/gitosis.git&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cd gitosis&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sudo &amp;nbsp;python setup.py install&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Configuration&lt;br /&gt;
&lt;br /&gt;
2.1 Enable ssh service in Ubuntu server&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; to use ssh-server, must open port 22 for&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; install ubuntu open ssh&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt;sudo apt-get install openssh-server&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;to make sure ssh server enable or not, run &amp;nbsp;&lt;i&gt;ps -e | grep ssh&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if only can see ssh-agent, means ssh-server not start yet, if see sshd means, ssh-server already start.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;And then restart ssh server&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;run : &amp;nbsp; &amp;nbsp; sudo /etc/init.d/ssh restart&lt;br /&gt;
&lt;br /&gt;
3. Add new user&lt;br /&gt;
&lt;br /&gt;
3.1 cd to gitosis-admin&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; copy new user&#39;s id_rsa.pub to keydir folder, named as new_user.pub&lt;br /&gt;
&lt;br /&gt;
3.2 &amp;nbsp;edit gitosis.conf&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt;vim gitosis.conf&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; edit as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp;[group &lt;b&gt;ProjectName&lt;/b&gt;]&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;members = old_user1 old_user2 &lt;b&gt;new_user&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;writable =&amp;nbsp;&lt;b&gt;ProjectName&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;save and exit&lt;br /&gt;
&lt;br /&gt;
3.3 back to gitosis-admin folder, push the change to server, then the sever will allow new member to download&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt; &amp;nbsp;git add .&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;git commit -am &quot;add new user&quot;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;git push&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Now the user can clone from the new user&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
4. Create new project&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;4.1 &amp;nbsp; &amp;nbsp;in local pc, open gitosis.conf, enter&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp;[group &lt;b&gt;NewProject&lt;/b&gt;]&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;members = matthewlu@mamembers = matthewlu@matthews-MacBook-Pro.local vic mac_mini&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;writable =&amp;nbsp;&lt;b&gt;NewProject&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;save and exit&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;i&gt; &amp;nbsp;push the change to server&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp;git commit -am &quot;create a new project&quot;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp;git push&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
4.2 in server, in repositories folder , create a new folder&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp; mkdir NewProject&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;cd to NewProject&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Init a new git repository&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;git init --bare&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;4.3 in local machine&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Create the NewProject&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp;mkdir NewProject&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; git init&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; git remote add origin admin@YOURSERVER:NewProject&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; git add .&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; git commit -am &quot;init a new project&quot;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; git push origin master&lt;/i&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
5. Create .gitignore for new create Xcode git project&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;5.1 touch .gitignore&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;The location of .gitignore is same as .git, .gitignore is not inside .git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;5.2. vim .gitignore&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;add the content below to .gitignore&lt;br /&gt;
&lt;br /&gt;
# Mac OS X&lt;br /&gt;
*.DS_Store&lt;br /&gt;
&lt;br /&gt;
# Xcode&lt;br /&gt;
*.pbxuser&lt;br /&gt;
*.mode1v3&lt;br /&gt;
*.mode2v3&lt;br /&gt;
*.perspectivev3&lt;br /&gt;
*.xcuserstate&lt;br /&gt;
project.xcworkspace/&lt;br /&gt;
xcuserdata/&lt;br /&gt;
&lt;br /&gt;
# Generated files&lt;br /&gt;
*.o&lt;br /&gt;
*.pyc&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#Python modules&lt;br /&gt;
MANIFEST&lt;br /&gt;
dist/&lt;br /&gt;
build/&lt;br /&gt;
&lt;br /&gt;
# Backup files&lt;br /&gt;
*~.nib&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
Then save and exit&lt;br /&gt;
&lt;br /&gt;
5.3 &amp;nbsp;add .gitignore to git&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; git add .gitignore&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; git commit &amp;nbsp;-am &quot;create .gitignore file&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; git push origin master&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add ssh key to server&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; get the publick key &amp;nbsp;key.pub&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; copy the key content to server authorzied_key&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; refresh ssh&lt;br /&gt;
&lt;br /&gt;
7. gitignore file for visual studio&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; #&lt;br /&gt;









&lt;div class=&quot;p1&quot;&gt;
# Windows and Mac OS X Temp Cache Files&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
[Tt]humbs.db&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.DS_Store&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#Visual Studio files&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.[Oo]bj&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.user&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.aps&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.pch&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.vspscc&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.vssscc&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*_i.c&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*_p.c&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.ncb&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.suo&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.tlb&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.tlh&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.bak&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.[Cc]ache&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.ilk&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.log&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.lib&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.sbr&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.sdf&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
ipch/&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
obj/&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
[Bb]in&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
[Dd]ebug*/&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
[Rr]elease*/&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#Tooling&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
_ReSharper*/&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
*.resharper&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
[Tt]est[Rr]esult*&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#Project files&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
[Bb]uild/&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#Subversion files&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
.svn&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
# Microsoft Office Temp Files&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
#&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
~$*&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
# End of File&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
8. windows connect to ubuntu server&lt;br /&gt;
&amp;nbsp; &amp;nbsp; the path format is below:&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; 192.168.1.26:repositories/EngagerIntranet.git&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/6064510619219372237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/03/ubuntu-setup-git-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/6064510619219372237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/6064510619219372237'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/03/ubuntu-setup-git-server.html' title='Ubuntu setup Git Server'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5839038201833626823.post-1924104309596093060</id><published>2013-03-18T15:45:00.003-07:00</published><updated>2013-03-18T15:46:19.603-07:00</updated><title type='text'>Converting Longitude and Latitude to a Meaningful Address</title><content type='html'>&lt;br /&gt;
&lt;br /&gt;
This part of code is from Book&amp;nbsp;&lt;ios 6=&quot;&quot; cookbook=&quot;&quot; programming=&quot;&quot;&gt;, Vandad Nahavandipoor.&lt;/ios&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Declare a property of type CLGeocoder&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #009999; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #009999; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #009999; font-family: TheSansMonoCd;&quot;&gt;#import &lt;uikit it.h=&quot;&quot;&gt;&lt;/uikit&gt;&lt;/span&gt;&lt;br /&gt;

  
 
 
  &lt;div class=&quot;page&quot; title=&quot;Page 470&quot;&gt;
   &lt;div class=&quot;layoutArea&quot;&gt;
    &lt;div class=&quot;column&quot;&gt;
     &lt;span style=&quot;color: #009999; font-family: TheSansMonoCd;&quot;&gt;&amp;nbsp; &amp;nbsp;#import &lt;corelocation orelocation.h=&quot;&quot;&gt;&amp;nbsp;&lt;/corelocation&gt;&lt;/span&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;@interface&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #00aa88; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Converting_Meaningful_Addresses_to_Longitude_and_LatitudeViewController&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #00aa88; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;UIViewController&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&amp;nbsp; &amp;nbsp; @property&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;nonatomic&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;strong&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;CLGeocoder&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;myGeocoder&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&amp;nbsp; &amp;nbsp; @end&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
2. In viewdidload&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;CLLocation &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;location &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;[[&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;CLLocation alloc&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;]
&lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;initWithLatitude:&lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;38.4112810&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;page&quot; title=&quot;Page 471&quot;&gt;
&lt;div class=&quot;layoutArea&quot;&gt;
&lt;div class=&quot;column&quot;&gt;
&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;longitude:&lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;122.8409780f&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;];
&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;myGeocoder &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;[[&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;CLGeocoder alloc&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;];
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;myGeocoder&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;reverseGeocodeLocation:&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;location
&lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;completionHandler:&lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSArray &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemarks&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSError &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;) {
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;error &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: #336666; font-family: TheSansMonoCd;&quot;&gt;nil &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;&amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemarks count&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;){
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;CLPlacemark &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemark &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemarks &lt;/span&gt;&lt;span style=&quot;color: #9999ff; font-family: TheSansMonoCd;&quot;&gt;objectAtIndex:&lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;];
&lt;/span&gt;&lt;span style=&quot;color: #35586c; font-family: TheSansMonoCd; font-style: italic;&quot;&gt;/* We received the results */&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSLog&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;Country = %@&quot;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemark&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;country&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSLog&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;Postal Code = %@&quot;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemark&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;postalCode&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSLog&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;Locality = %@&quot;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemark&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;locality&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;}&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;else if &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;error &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: #336666; font-family: TheSansMonoCd;&quot;&gt;nil &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;&amp;amp;&amp;amp;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;placemarks count&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-family: TheSansMonoCd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;){
&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSLog&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;No results were returned.&quot;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;}&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;color: #006699; font-family: TheSansMonoCd; font-weight: 700;&quot;&gt;else if &lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;error &lt;/span&gt;&lt;span style=&quot;color: #555555; font-family: TheSansMonoCd;&quot;&gt;!= &lt;/span&gt;&lt;span style=&quot;color: #336666; font-family: TheSansMonoCd;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;){
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;NSLog&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cc3300; font-family: TheSansMonoCd;&quot;&gt;@&quot;An error occurred = %@&quot;&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #000088; font-family: TheSansMonoCd;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;);
}
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: TheSansMonoCd;&quot;&gt;}];&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://juehualu.blogspot.com/feeds/1924104309596093060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://juehualu.blogspot.com/2013/03/converting-longitude-and-latitude-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1924104309596093060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5839038201833626823/posts/default/1924104309596093060'/><link rel='alternate' type='text/html' href='http://juehualu.blogspot.com/2013/03/converting-longitude-and-latitude-to.html' title='Converting Longitude and Latitude to a Meaningful Address'/><author><name>JUEHUA  LU</name><uri>http://www.blogger.com/profile/08611242718655469004</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>