Several common methods of storage in iOS development
Last Update:2015-05-10
Source: Internet
Author: User
<span id="Label3"></p><p><p>1. Archive Archive</p></p> <blockquote> <blockquote> <p>Preservation of data</p> <pre class="alt"><span class="lnum"> 1: </span>as <span class="kwrd"></span> String)</pre> <pre><span class="lnum"> 2: </span> println (<span class="str">"save result \ (result)"</span>)</pre> <style type="text/css">.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }</style> </blockquote> </blockquote><p><p>Read the Data:</p></p> <blockquote> <pre class="alt"><pre class="alt"><span class="lnum"> 1: </span>var t:[contact]?</pre></pre> <pre><pre><span class="lnum"> 2: </span>as <span class="kwrd"></span> String)</pre></pre> <pre class="alt"><pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd">if</span> any = = Nil {</pre></pre> <pre><pre><span class="lnum"> 4: </span> t = [contact] ()</pre></pre> <pre class="alt"><pre class="alt"><span class="lnum"> 5: </span> }<span class="kwrd">else</span>{</pre></pre> <pre><pre><span class="lnum"> 6: </span> println (<span class="str">"read success"</span>)</pre></pre> <pre class="alt"><pre class="alt"><span class="lnum"> 7: </span>as <span class="kwrd"></span>? [contact]</pre></pre> <pre><pre><span class="lnum"> 8: </span> }</pre></pre> <style type="text/css"><style type="text/css">.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }</style></style> </blockquote><p><p>The init with Coder method and Encodewithcoder method need to be implemented in the model</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>2. User Default</p></p><p><p></p></p><p><p>3. plist Storage</p></p><p><p></p></p> <pre class="alt"><pre class="alt"><span class="lnum"> 1: </span> [datadic setvalue:eachdarray forkey:<span class="str">"key"</span>];</pre></pre> <pre><pre><span class="lnum"> 2: </span>[datadic writetofile:filename atomically:yes];</pre></pre><style type="text/css"><style type="text/css">.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }</style></style><p><p>Several common methods of storage in iOS development</p></p></span>