edited readme

This commit is contained in:
Peter 2016-04-12 08:47:31 -04:00
parent cda7853b85
commit d0eb446ee3
3 changed files with 200 additions and 50 deletions

View File

@ -119,6 +119,7 @@
<a href='#swiftddp' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h1 id='swiftddp'>SwiftDDP</h1>
<a href='#a_client_for_meteor_servers_written_in_swift' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='a_client_for_meteor_servers_written_in_swift'>A client for Meteor servers, written in Swift</h2>
<a href='#version_0_3_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='version_0_3_0'>version 0.3.0</h3>
<a href='#license' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='license'>License</h4>
<p>MIT </p>
@ -126,39 +127,45 @@
<p><a href="http://cocoapods.org/pods/SwiftDDP"><img src="https://img.shields.io/cocoapods/v/SwiftDDP.svg?style=flat" alt="Version"></a>
<a href="http://cocoapods.org/pods/SwiftDDP"><img src="https://img.shields.io/cocoapods/l/SwiftDDP.svg?style=flat" alt="License"></a>
<a href="http://cocoapods.org/pods/SwiftDDP"><img src="https://img.shields.io/cocoapods/p/SwiftDDP.svg?style=flat" alt="Platform"></a></p>
<a href='#changelog' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='changelog'>Changelog</h2>
<a href='#0_3_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_3_0'>0.3.0:</h3>
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<ul>
<li>Changed default subscription behavior</li>
<li>Added a method to sign a user in via username</li>
</ul>
<a href='#version_0_3_0_contains_breaking_changes' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h5 id='version_0_3_0_contains_breaking_changes'>Version 0.3.0 contains breaking changes</h5>
<li><a href="#installation">Installation</a></li>
<li><a href="#documentation">Documentation</a>
<ul>
<li>You can now update a subscription by changing its parameters without first unsubscribing. This will subscribe the client to any documents associated with the new subscription and parameters. When you pass a new set of parameters to a subscription that you have previously subscribed to, you remain subscribed to any documents associated with that prior subscription.<br></li>
<li>The subscription method returns an id. To unsubscribe to documents associated with a specific set of parameters, you must unsubscribe with this id.</li>
<li>Unsubscribing by name now works differently. When unsubscribing by name, you unsubscribe to any and all subscriptions with that name.</li>
<li>You can no longer pass a callback to <code>unsubscribe(name:String)</code>. It now returns an array with the ids of the subscriptions you&rsquo;ve unsubscribed to.</li>
</ul>
<a href='#0_2_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_2_1'>0.2.2.1:</h3>
<li><a href="#quick-start">Quick Start</a></li>
<li><a href="#setting-basic-configuration-options">Setting basic configuration options</a></li>
<li><a href="#connecting-to-a-meteor-server">Connecting to a Meteor server</a></li>
<li><a href="#login-&amp;-logout-with-facebook-twitter-etc-beta">Login &amp; Logout with Facebook, Twitter, etc. (beta)</a></li>
<li><a href="#gotchas-and-implementation-notes-for-oauth-login-flows">Gotchas and implementation notes for OAuth login flows</a></li>
<li><a href="#login-&amp;-logout-with-password">Login &amp; Logout with password</a></li>
<li><a href="#subscribe-to-a-subset-of-a-collection">Subscribe to a subset of a collection</a></li>
<li><a href="#change-the-subscriptions-parameters-and-manage-your-subscription-with-unsubscribe">Change the subscription&rsquo;s parameters and manage your subscription with unsubscribe</a></li>
<li><a href="#call-a-method-on-the-server">Call a method on the server</a></li>
<li><a href="#simple-in-memory-persistence">Simple in-memory persistence</a></li>
</ul></li>
<li><a href="#example-projects">Example Projects</a>
<ul>
<li>Improved subscription handling across app states</li>
<li>Dependencies updated for Swift 2.2</li>
</ul>
<a href='#0_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_1'>0.2.1:</h3>
<li><a href="#todos">Todos</a></li>
</ul></li>
<li><a href="#example-creating-an-array-based-custom-collection">Example: Creating an array based custom collection</a></li>
<li><a href="#changelog">Changelog</a>
<ul>
<li>Reconnection behavior improvements: reconnect attempts now follow an exponential backoff pattern</li>
<li>Client now connects to servers using self signed SSL certificates when allowSelfSignedSSL is set to true</li>
<li>The loglevel can now be set directly using the logLevel property on the client. The default setting is .None</li>
<li><a href="#030">0.3.0</a></li>
<li><a href="#0221">0.2.2.1</a></li>
<li><a href="#021">0.2.1</a></li>
<li><a href="#020">0.2.0</a></li>
</ul></li>
<li><a href="#contributing">Contributing</a></li>
</ul>
<a href='#0_2_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_0'>0.2.0:</h3>
<ul>
<li>Integration with Meteor&rsquo;s Facebook, Twitter &amp; other login services</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<a href='#installation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='installation'>Installation</h2>
<p>With <a href="http://cocoapods.org">CocoaPods</a>. Add the following line to your Podfile:</p>
@ -259,7 +266,7 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
<span class="nf">print</span><span class="p">(</span><span class="s">"The user just signed out!"</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>
<a href='#subscribe_to_a_subset_of_a_collection_on_the_server' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='subscribe_to_a_subset_of_a_collection_on_the_server'>Subscribe to a subset of a collection on the server</h4>
<a href='#subscribe_to_a_subset_of_a_collection' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='subscribe_to_a_subset_of_a_collection'>Subscribe to a subset of a collection</h4>
<pre class="highlight swift"><code><span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"todos"</span><span class="p">)</span>
<span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"todos"</span><span class="p">)</span> <span class="p">{</span>
@ -270,6 +277,39 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
<span class="c1">// Do something when the todos subscription is ready</span>
<span class="p">}</span>
</code></pre>
<a href='#change_the_subscription_39_s_parameters_and_manage_your_subscription_with_unsubscribe' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='change_the_subscription_39_s_parameters_and_manage_your_subscription_with_unsubscribe'>Change the subscription&rsquo;s parameters and manage your subscription with unsubscribe</h4>
<pre class="highlight swift"><code>
<span class="c1">// Suppose you want to subscribe to a list of all cities and towns near a specific major city</span>
<span class="c1">// Subscribe to cities near Boston</span>
<span class="k">let</span> <span class="nv">id1</span> <span class="o">=</span> <span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">,</span> <span class="p">[</span><span class="s">"lat"</span><span class="p">:</span> <span class="mf">42.358056</span> <span class="p">,</span><span class="s">"lon"</span><span class="p">:</span> <span class="o">-</span><span class="mf">71.063611</span><span class="p">])</span> <span class="p">{</span>
<span class="c1">// You are now subscribed to cities associated with the coordinates 42.358056, -71.063611</span>
<span class="c1">// id1 contains a key that allows you to cancel the subscription associated with </span>
<span class="c1">// the parameters ["lat": 42.358056 ,"lon": -71.063611]</span>
<span class="p">}</span>
<span class="c1">// Subscribe to cities near Paris</span>
<span class="k">let</span> <span class="nv">id2</span> <span class="o">=</span> <span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">,</span> <span class="p">[</span><span class="s">"lat"</span><span class="p">:</span> <span class="mf">48.8567</span><span class="p">,</span> <span class="s">"lon"</span><span class="p">:</span> <span class="mf">2.3508</span><span class="p">]){</span>
<span class="c1">// You are now subscribed to cities associated with the coordinates 48.8567, 2.3508</span>
<span class="c1">// id2 contains a key that allows you to cancel the subscription associated with </span>
<span class="c1">// the parameters ["lat": 48.8567 ,"lon": 2.3508]</span>
<span class="p">}</span>
<span class="c1">// Subscribe to cities near New York</span>
<span class="k">let</span> <span class="nv">id3</span> <span class="o">=</span> <span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">,</span> <span class="p">[</span><span class="s">"lat"</span><span class="p">:</span> <span class="mf">40.7127</span><span class="p">,</span> <span class="s">"lon"</span><span class="p">:</span> <span class="o">-</span><span class="mf">74.0059</span><span class="p">]){</span>
<span class="c1">// You are now subscribed to cities associated with the coordinates 40.7127, -74.0059</span>
<span class="c1">// id3 contains a key that allows you to cancel the subscription associated with </span>
<span class="c1">// the parameters ["lat": 40.7127 ,"lon": -74.0059]</span>
<span class="p">}</span>
<span class="c1">// When these subscriptions have completed, the collection associated with "cities" will now contain all</span>
<span class="c1">// documents returned from the three subscriptions</span>
<span class="kt">Meteor</span><span class="o">.</span><span class="nf">unsubscribe</span><span class="p">(</span><span class="nv">withId</span><span class="p">:</span> <span class="n">id2</span><span class="p">)</span>
<span class="c1">// Your collection will now contain cities near Boston and New York, but not Paris</span>
<span class="kt">Meteor</span><span class="o">.</span><span class="nf">unsubscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">)</span>
<span class="c1">// You are now unsubscribed to all subscriptions associated with the publication "cities"</span>
</code></pre>
<a href='#call_a_method_on_the_server' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='call_a_method_on_the_server'>Call a method on the server</h4>
<pre class="highlight swift"><code><span class="kt">Meteor</span><span class="o">.</span><span class="nf">call</span><span class="p">(</span><span class="s">"foo"</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> <span class="p">{</span> <span class="n">result</span><span class="p">,</span> <span class="n">error</span> <span class="k">in</span>
<span class="c1">// Do something with the method result</span>
@ -320,7 +360,8 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
<p>Once you&rsquo;ve created and started the Meteor todos server, set the url variable in AppDelegate.swift to ws://localhost:3000/websocket, then run the iOS app.</p>
<a href='#example_creating_an_array_based_custom_collection' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='example_creating_an_array_based_custom_collection'>Example: Creating an array based custom collection</h2>
<a href='#the_following_pattern_can_be_used_to_create_custom_collections_backed_by_any_datastore' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='the_following_pattern_can_be_used_to_create_custom_collections_backed_by_any_datastore'>The following pattern can be used to create custom collections backed by any datastore</h4>
<p><strong>The following pattern can be used to create custom collections backed by any datastore</strong></p>
<p>In this example, we&rsquo;ll create a simple collection to hold a list of contacts. The first thing we&rsquo;ll do is create an object to represent a contact. This object has four properties and a method named <em>update</em> that maps the <em>fields</em> NSDictionary to the struct&rsquo;s properties. <em>Update</em> is called when an object is created and when an update is performed. Meteor will always transmit an <strong>id</strong> to identify the object that should be added, updated or removed, so objects that represent Meteor documents must <strong>always</strong> have an id field. Here we&rsquo;re sticking to the MongoDB convention of naming our id <em>_id</em>.</p>
<pre class="highlight swift"><code>
@ -418,6 +459,40 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
- (3) remove the contact from the local store if the server rejects the insert</p>
<p>Creating update and remove methods are also easy to create, and follow the same patern as insert. For a more extensive example of the patterns shown here, have a look at <a href="https://github.com/siegesmund/SwiftDDP/blob/master/SwiftDDP/MeteorCollection.swift">MeteorCollection.swift</a>. MeteorCollection is an in-memory collection implementation suitable for simple applications.</p>
<a href='#changelog' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='changelog'>Changelog</h2>
<a href='#0_3_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_3_0'>0.3.0</h3>
<ul>
<li>Changed default subscription behavior</li>
<li>Added a method to sign a user in via username</li>
</ul>
<p><strong>Version 0.3.0 contains breaking changes</strong>
- You can now update a subscription by changing its parameters without first unsubscribing. This will subscribe the client to any documents associated with the new subscription and parameters. When you pass a new set of parameters to a subscription that you have previously subscribed to, you remain subscribed to any documents associated with that prior subscription.<br>
- The subscription method returns an id. To unsubscribe to documents associated with a specific set of parameters, you must unsubscribe with this id.
- Unsubscribing by name now works differently. When unsubscribing by name, you unsubscribe to any and all subscriptions with that name.
- You can no longer pass a callback to <code>unsubscribe(name:String)</code>. It now returns an array with the ids of the subscriptions you&rsquo;ve unsubscribed to.</p>
<a href='#0_2_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_2_1'>0.2.2.1</h3>
<ul>
<li>Improved subscription handling across app states</li>
<li>Dependencies updated for Swift 2.2</li>
</ul>
<a href='#0_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_1'>0.2.1</h3>
<ul>
<li>Reconnection behavior improvements: reconnect attempts now follow an exponential backoff pattern</li>
<li>Client now connects to servers using self signed SSL certificates when allowSelfSignedSSL is set to true</li>
<li>The loglevel can now be set directly using the logLevel property on the client. The default setting is .None</li>
</ul>
<a href='#0_2_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_0'>0.2.0</h3>
<ul>
<li>Integration with Meteor&rsquo;s Facebook, Twitter &amp; other login services</li>
</ul>
<a href='#contributing' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='contributing'>Contributing</h2>
<p>Pull requests, feature requests are feedback are welcome. If you&rsquo;re using SwiftDDP in a production app, let us know.</p>
</section>
</section>

Binary file not shown.

View File

@ -119,6 +119,7 @@
<a href='#swiftddp' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h1 id='swiftddp'>SwiftDDP</h1>
<a href='#a_client_for_meteor_servers_written_in_swift' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='a_client_for_meteor_servers_written_in_swift'>A client for Meteor servers, written in Swift</h2>
<a href='#version_0_3_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='version_0_3_0'>version 0.3.0</h3>
<a href='#license' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='license'>License</h4>
<p>MIT </p>
@ -126,39 +127,45 @@
<p><a href="http://cocoapods.org/pods/SwiftDDP"><img src="https://img.shields.io/cocoapods/v/SwiftDDP.svg?style=flat" alt="Version"></a>
<a href="http://cocoapods.org/pods/SwiftDDP"><img src="https://img.shields.io/cocoapods/l/SwiftDDP.svg?style=flat" alt="License"></a>
<a href="http://cocoapods.org/pods/SwiftDDP"><img src="https://img.shields.io/cocoapods/p/SwiftDDP.svg?style=flat" alt="Platform"></a></p>
<a href='#changelog' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='changelog'>Changelog</h2>
<a href='#0_3_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_3_0'>0.3.0:</h3>
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<ul>
<li>Changed default subscription behavior</li>
<li>Added a method to sign a user in via username</li>
</ul>
<a href='#version_0_3_0_contains_breaking_changes' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h5 id='version_0_3_0_contains_breaking_changes'>Version 0.3.0 contains breaking changes</h5>
<li><a href="#installation">Installation</a></li>
<li><a href="#documentation">Documentation</a>
<ul>
<li>You can now update a subscription by changing its parameters without first unsubscribing. This will subscribe the client to any documents associated with the new subscription and parameters. When you pass a new set of parameters to a subscription that you have previously subscribed to, you remain subscribed to any documents associated with that prior subscription.<br></li>
<li>The subscription method returns an id. To unsubscribe to documents associated with a specific set of parameters, you must unsubscribe with this id.</li>
<li>Unsubscribing by name now works differently. When unsubscribing by name, you unsubscribe to any and all subscriptions with that name.</li>
<li>You can no longer pass a callback to <code>unsubscribe(name:String)</code>. It now returns an array with the ids of the subscriptions you&rsquo;ve unsubscribed to.</li>
</ul>
<a href='#0_2_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_2_1'>0.2.2.1:</h3>
<li><a href="#quick-start">Quick Start</a></li>
<li><a href="#setting-basic-configuration-options">Setting basic configuration options</a></li>
<li><a href="#connecting-to-a-meteor-server">Connecting to a Meteor server</a></li>
<li><a href="#login-&amp;-logout-with-facebook-twitter-etc-beta">Login &amp; Logout with Facebook, Twitter, etc. (beta)</a></li>
<li><a href="#gotchas-and-implementation-notes-for-oauth-login-flows">Gotchas and implementation notes for OAuth login flows</a></li>
<li><a href="#login-&amp;-logout-with-password">Login &amp; Logout with password</a></li>
<li><a href="#subscribe-to-a-subset-of-a-collection">Subscribe to a subset of a collection</a></li>
<li><a href="#change-the-subscriptions-parameters-and-manage-your-subscription-with-unsubscribe">Change the subscription&rsquo;s parameters and manage your subscription with unsubscribe</a></li>
<li><a href="#call-a-method-on-the-server">Call a method on the server</a></li>
<li><a href="#simple-in-memory-persistence">Simple in-memory persistence</a></li>
</ul></li>
<li><a href="#example-projects">Example Projects</a>
<ul>
<li>Improved subscription handling across app states</li>
<li>Dependencies updated for Swift 2.2</li>
</ul>
<a href='#0_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_1'>0.2.1:</h3>
<li><a href="#todos">Todos</a></li>
</ul></li>
<li><a href="#example-creating-an-array-based-custom-collection">Example: Creating an array based custom collection</a></li>
<li><a href="#changelog">Changelog</a>
<ul>
<li>Reconnection behavior improvements: reconnect attempts now follow an exponential backoff pattern</li>
<li>Client now connects to servers using self signed SSL certificates when allowSelfSignedSSL is set to true</li>
<li>The loglevel can now be set directly using the logLevel property on the client. The default setting is .None</li>
<li><a href="#030">0.3.0</a></li>
<li><a href="#0221">0.2.2.1</a></li>
<li><a href="#021">0.2.1</a></li>
<li><a href="#020">0.2.0</a></li>
</ul></li>
<li><a href="#contributing">Contributing</a></li>
</ul>
<a href='#0_2_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_0'>0.2.0:</h3>
<ul>
<li>Integration with Meteor&rsquo;s Facebook, Twitter &amp; other login services</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<a href='#installation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='installation'>Installation</h2>
<p>With <a href="http://cocoapods.org">CocoaPods</a>. Add the following line to your Podfile:</p>
@ -259,7 +266,7 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
<span class="nf">print</span><span class="p">(</span><span class="s">"The user just signed out!"</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>
<a href='#subscribe_to_a_subset_of_a_collection_on_the_server' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='subscribe_to_a_subset_of_a_collection_on_the_server'>Subscribe to a subset of a collection on the server</h4>
<a href='#subscribe_to_a_subset_of_a_collection' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='subscribe_to_a_subset_of_a_collection'>Subscribe to a subset of a collection</h4>
<pre class="highlight swift"><code><span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"todos"</span><span class="p">)</span>
<span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"todos"</span><span class="p">)</span> <span class="p">{</span>
@ -270,6 +277,39 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
<span class="c1">// Do something when the todos subscription is ready</span>
<span class="p">}</span>
</code></pre>
<a href='#change_the_subscription_39_s_parameters_and_manage_your_subscription_with_unsubscribe' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='change_the_subscription_39_s_parameters_and_manage_your_subscription_with_unsubscribe'>Change the subscription&rsquo;s parameters and manage your subscription with unsubscribe</h4>
<pre class="highlight swift"><code>
<span class="c1">// Suppose you want to subscribe to a list of all cities and towns near a specific major city</span>
<span class="c1">// Subscribe to cities near Boston</span>
<span class="k">let</span> <span class="nv">id1</span> <span class="o">=</span> <span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">,</span> <span class="p">[</span><span class="s">"lat"</span><span class="p">:</span> <span class="mf">42.358056</span> <span class="p">,</span><span class="s">"lon"</span><span class="p">:</span> <span class="o">-</span><span class="mf">71.063611</span><span class="p">])</span> <span class="p">{</span>
<span class="c1">// You are now subscribed to cities associated with the coordinates 42.358056, -71.063611</span>
<span class="c1">// id1 contains a key that allows you to cancel the subscription associated with </span>
<span class="c1">// the parameters ["lat": 42.358056 ,"lon": -71.063611]</span>
<span class="p">}</span>
<span class="c1">// Subscribe to cities near Paris</span>
<span class="k">let</span> <span class="nv">id2</span> <span class="o">=</span> <span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">,</span> <span class="p">[</span><span class="s">"lat"</span><span class="p">:</span> <span class="mf">48.8567</span><span class="p">,</span> <span class="s">"lon"</span><span class="p">:</span> <span class="mf">2.3508</span><span class="p">]){</span>
<span class="c1">// You are now subscribed to cities associated with the coordinates 48.8567, 2.3508</span>
<span class="c1">// id2 contains a key that allows you to cancel the subscription associated with </span>
<span class="c1">// the parameters ["lat": 48.8567 ,"lon": 2.3508]</span>
<span class="p">}</span>
<span class="c1">// Subscribe to cities near New York</span>
<span class="k">let</span> <span class="nv">id3</span> <span class="o">=</span> <span class="kt">Meteor</span><span class="o">.</span><span class="nf">subscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">,</span> <span class="p">[</span><span class="s">"lat"</span><span class="p">:</span> <span class="mf">40.7127</span><span class="p">,</span> <span class="s">"lon"</span><span class="p">:</span> <span class="o">-</span><span class="mf">74.0059</span><span class="p">]){</span>
<span class="c1">// You are now subscribed to cities associated with the coordinates 40.7127, -74.0059</span>
<span class="c1">// id3 contains a key that allows you to cancel the subscription associated with </span>
<span class="c1">// the parameters ["lat": 40.7127 ,"lon": -74.0059]</span>
<span class="p">}</span>
<span class="c1">// When these subscriptions have completed, the collection associated with "cities" will now contain all</span>
<span class="c1">// documents returned from the three subscriptions</span>
<span class="kt">Meteor</span><span class="o">.</span><span class="nf">unsubscribe</span><span class="p">(</span><span class="nv">withId</span><span class="p">:</span> <span class="n">id2</span><span class="p">)</span>
<span class="c1">// Your collection will now contain cities near Boston and New York, but not Paris</span>
<span class="kt">Meteor</span><span class="o">.</span><span class="nf">unsubscribe</span><span class="p">(</span><span class="s">"cities"</span><span class="p">)</span>
<span class="c1">// You are now unsubscribed to all subscriptions associated with the publication "cities"</span>
</code></pre>
<a href='#call_a_method_on_the_server' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='call_a_method_on_the_server'>Call a method on the server</h4>
<pre class="highlight swift"><code><span class="kt">Meteor</span><span class="o">.</span><span class="nf">call</span><span class="p">(</span><span class="s">"foo"</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> <span class="p">{</span> <span class="n">result</span><span class="p">,</span> <span class="n">error</span> <span class="k">in</span>
<span class="c1">// Do something with the method result</span>
@ -320,7 +360,8 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
<p>Once you&rsquo;ve created and started the Meteor todos server, set the url variable in AppDelegate.swift to ws://localhost:3000/websocket, then run the iOS app.</p>
<a href='#example_creating_an_array_based_custom_collection' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='example_creating_an_array_based_custom_collection'>Example: Creating an array based custom collection</h2>
<a href='#the_following_pattern_can_be_used_to_create_custom_collections_backed_by_any_datastore' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='the_following_pattern_can_be_used_to_create_custom_collections_backed_by_any_datastore'>The following pattern can be used to create custom collections backed by any datastore</h4>
<p><strong>The following pattern can be used to create custom collections backed by any datastore</strong></p>
<p>In this example, we&rsquo;ll create a simple collection to hold a list of contacts. The first thing we&rsquo;ll do is create an object to represent a contact. This object has four properties and a method named <em>update</em> that maps the <em>fields</em> NSDictionary to the struct&rsquo;s properties. <em>Update</em> is called when an object is created and when an update is performed. Meteor will always transmit an <strong>id</strong> to identify the object that should be added, updated or removed, so objects that represent Meteor documents must <strong>always</strong> have an id field. Here we&rsquo;re sticking to the MongoDB convention of naming our id <em>_id</em>.</p>
<pre class="highlight swift"><code>
@ -418,6 +459,40 @@ Meteor.loginWithPassword("user@swiftddp.com", password: "********") { result, er
- (3) remove the contact from the local store if the server rejects the insert</p>
<p>Creating update and remove methods are also easy to create, and follow the same patern as insert. For a more extensive example of the patterns shown here, have a look at <a href="https://github.com/siegesmund/SwiftDDP/blob/master/SwiftDDP/MeteorCollection.swift">MeteorCollection.swift</a>. MeteorCollection is an in-memory collection implementation suitable for simple applications.</p>
<a href='#changelog' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='changelog'>Changelog</h2>
<a href='#0_3_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_3_0'>0.3.0</h3>
<ul>
<li>Changed default subscription behavior</li>
<li>Added a method to sign a user in via username</li>
</ul>
<p><strong>Version 0.3.0 contains breaking changes</strong>
- You can now update a subscription by changing its parameters without first unsubscribing. This will subscribe the client to any documents associated with the new subscription and parameters. When you pass a new set of parameters to a subscription that you have previously subscribed to, you remain subscribed to any documents associated with that prior subscription.<br>
- The subscription method returns an id. To unsubscribe to documents associated with a specific set of parameters, you must unsubscribe with this id.
- Unsubscribing by name now works differently. When unsubscribing by name, you unsubscribe to any and all subscriptions with that name.
- You can no longer pass a callback to <code>unsubscribe(name:String)</code>. It now returns an array with the ids of the subscriptions you&rsquo;ve unsubscribed to.</p>
<a href='#0_2_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_2_1'>0.2.2.1</h3>
<ul>
<li>Improved subscription handling across app states</li>
<li>Dependencies updated for Swift 2.2</li>
</ul>
<a href='#0_2_1' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_1'>0.2.1</h3>
<ul>
<li>Reconnection behavior improvements: reconnect attempts now follow an exponential backoff pattern</li>
<li>Client now connects to servers using self signed SSL certificates when allowSelfSignedSSL is set to true</li>
<li>The loglevel can now be set directly using the logLevel property on the client. The default setting is .None</li>
</ul>
<a href='#0_2_0' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='0_2_0'>0.2.0</h3>
<ul>
<li>Integration with Meteor&rsquo;s Facebook, Twitter &amp; other login services</li>
</ul>
<a href='#contributing' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='contributing'>Contributing</h2>
<p>Pull requests, feature requests are feedback are welcome. If you&rsquo;re using SwiftDDP in a production app, let us know.</p>
</section>
</section>