-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathab-testing-ios.html
272 lines (239 loc) · 18 KB
/
ab-testing-ios.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://ogp.me/ns#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Clutch.io - iOS SDK - Documentation</title>
<link rel="stylesheet" href="_static/basic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/main.js"></script>
<script type="text/javascript" src="_static/bootstrap-modal.js"></script>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="top" title="Clutch 1.0 documentation" href="index.html" />
<link rel="up" title="Clutch A/B Testing" href="ab-testing.html" />
<link rel="next" title="Android SDK" href="ab-testing-android.html" />
<link rel="prev" title="Overview" href="ab-testing-overview.html" />
</head>
<body id="docs" class="secondary ">
<div id="header">
<div class="content">
<div class="ribbon"></div>
<h1 class="logo"><a href="/">Clutch.io</a></h1>
</div>
</div>
<div class="edge"></div>
<div class="document">
<div class="documentwrapper section-wrap">
<div class="relbar">
<div class="breadcrumbs">
<a href="index.html" class="main-link">Clutch 1.0 documentation</a> »
<a href="ab-testing.html" accesskey="U">Clutch A/B Testing</a> »
iOS SDK
</div>
<div class="rellinks">
<a href="index.html" class="left">home</a>
<a href="genindex.html" class="right" title="General Index" accesskey="I">index</a>
<a href="ab-testing-android.html" class="right" title="Android SDK" accesskey="N">next</a>
<a href="ab-testing-overview.html" class="right" title="Overview" accesskey="P">previous</a>
</div>
<div class="clear"></div>
</div>
<div class="bodywrapper content">
<div class="body main-sec">
<div class="section" id="ios-sdk">
<h1>iOS SDK<a class="headerlink" href="#ios-sdk" title="Permalink to this headline">¶</a></h1>
<p>If you don’t have an account on your Clutch.io instance yet, you’ll need to
<a class="reference external" href="http://127.0.0.1:8000/register/">do that first</a>. If you don’t have a Clutch.io instance set up yet, follow
the steps on the <a class="reference external" href="https://github.com/clutchio/clutch/blob/master/README.rst">Clutch project README</a>. Otherwise, follow the steps below.</p>
<div class="section" id="getting-started">
<h2>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h2>
<p>First make sure you have the <a class="reference external" href="https://github.com/downloads/clutchio/clutchios/Clutch-iOS-Latest.zip">Clutch library</a> added to your project. To do
so, download the library, extract the zip file, and drag the Clutch.framework
folder into your project. Make sure that the library is in your project’s
linked frameworks section. The <a class="reference external" href="https://github.com/downloads/clutchio/clutchios/Clutch-iOS-Latest.zip">Clutch library</a> depends on libsqlite3.dylib,
so make sure to link that as well.</p>
<p>Now import the Clutch A/B Testing library in your project’s <tt class="docutils literal"><span class="pre">AppDelegate.h</span></tt>,
like so:</p>
<div class="highlight-obj-c"><div class="highlight"><pre><span class="cp">#import <Clutch/ClutchAB.h></span>
</pre></div>
</div>
<p>Now in your project’s <tt class="docutils literal"><span class="pre">AppDelegate.m</span></tt>, under
<tt class="docutils literal"><span class="pre">application:didFinishLaunchingWithOptions:</span></tt>, add the following code:</p>
<div class="highlight-obj-c"><div class="highlight"><pre><span class="p">[</span><span class="n">ClutchAB</span> <span class="nl">setupForKey:</span><span class="s">@"YOUR_APPLICATION_KEY"</span> <span class="nl">rpcURL:</span><span class="s">@"YOUR_RPC_URL"</span><span class="p">];</span>
</pre></div>
</div>
<p>That’s it–you’re now set up to run tests!</p>
</div>
<div class="section" id="normal-tests">
<h2>Normal Tests<a class="headerlink" href="#normal-tests" title="Permalink to this headline">¶</a></h2>
<p>The function for running a test is <tt class="docutils literal"><span class="pre">testWithName:A:B:</span></tt>. This can be given up
to 10 different code blocks, by adding the next letter in the alphabet. A test
with four code blocks would look like this: <tt class="docutils literal"><span class="pre">testWithName:A:B:C:D:</span></tt>.</p>
<p>Example:</p>
<div class="highlight-obj-c"><div class="highlight"><pre><span class="c1">// Create a button and add it to the navigation bar</span>
<span class="n">UIBarButtonItem</span> <span class="o">*</span><span class="n">loginButton</span> <span class="o">=</span> <span class="p">[</span>
<span class="p">[</span><span class="n">UIBarButtonItem</span> <span class="n">alloc</span><span class="p">]</span> <span class="nl">initWithTitle:</span><span class="s">@"Log In"</span>
<span class="nl">style:</span><span class="n">UIBarButtonItemStyleBordered</span>
<span class="nl">target:</span><span class="n">self</span>
<span class="nl">action:</span><span class="k">@selector</span><span class="p">(</span><span class="n">ensureUser</span><span class="p">)];</span>
<span class="n">self</span><span class="p">.</span><span class="n">navigationItem</span><span class="p">.</span><span class="n">rightBarButtonItem</span> <span class="o">=</span> <span class="n">loginButton</span><span class="p">;</span>
<span class="c1">// Test which color of tint performs better</span>
<span class="p">[</span><span class="n">ClutchAB</span> <span class="nl">testWithName:</span><span class="s">@"loginButtonColor"</span> <span class="nl">A:</span><span class="o">^</span><span class="p">{</span>
<span class="c1">// Red?</span>
<span class="n">loginButton</span><span class="p">.</span><span class="n">tintColor</span> <span class="o">=</span> <span class="p">[</span><span class="n">UIColor</span> <span class="n">redColor</span><span class="p">];</span>
<span class="p">}</span> <span class="nl">B:</span><span class="o">^</span><span class="p">{</span>
<span class="c1">// Or green?</span>
<span class="n">loginButton</span><span class="p">.</span><span class="n">tintColor</span> <span class="o">=</span> <span class="p">[</span><span class="n">UIColor</span> <span class="n">greenColor</span><span class="p">];</span>
<span class="p">}];</span>
<span class="p">[</span><span class="n">loginButton</span> <span class="n">release</span><span class="p">];</span>
</pre></div>
</div>
</div>
<div class="section" id="data-driven-tests">
<h2>Data-driven Tests<a class="headerlink" href="#data-driven-tests" title="Permalink to this headline">¶</a></h2>
<p>The function for running a data-driven test is <tt class="docutils literal"><span class="pre">testWithName:data</span></tt>. The code
block that’s passed in must accept one NSDictionary argument.</p>
<p>Example:</p>
<div class="highlight-obj-c"><div class="highlight"><pre><span class="c1">// Create a button and add it to the navigation bar</span>
<span class="n">UIBarButtonItem</span> <span class="o">*</span><span class="n">loginButton</span> <span class="o">=</span> <span class="p">[</span>
<span class="p">[</span><span class="n">UIBarButtonItem</span> <span class="n">alloc</span><span class="p">]</span> <span class="nl">initWithTitle:</span><span class="s">@"Log In"</span>
<span class="nl">style:</span><span class="n">UIBarButtonItemStyleBordered</span>
<span class="nl">target:</span><span class="n">self</span>
<span class="nl">action:</span><span class="k">@selector</span><span class="p">(</span><span class="n">ensureUser</span><span class="p">)];</span>
<span class="n">self</span><span class="p">.</span><span class="n">navigationItem</span><span class="p">.</span><span class="n">rightBarButtonItem</span> <span class="o">=</span> <span class="n">loginButton</span><span class="p">;</span>
<span class="p">[</span><span class="n">ClutchAB</span> <span class="nl">testWithName:</span><span class="s">@"loginButtonTitle"</span> <span class="nl">data:</span><span class="o">^</span><span class="p">(</span><span class="n">NSDictionary</span> <span class="o">*</span><span class="n">testData</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Extract the title from the testData dictionary, and assign it to the button.</span>
<span class="n">loginButton</span><span class="p">.</span><span class="n">title</span> <span class="o">=</span> <span class="p">[</span><span class="n">testData</span> <span class="nl">objectForKey:</span><span class="s">@"title"</span><span class="p">];</span>
<span class="p">}];</span>
<span class="p">[</span><span class="n">loginButton</span> <span class="n">release</span><span class="p">];</span>
</pre></div>
</div>
</div>
<div class="section" id="goal-reached">
<h2>Goal Reached<a class="headerlink" href="#goal-reached" title="Permalink to this headline">¶</a></h2>
<p>The function for noting that a goal was reached is <tt class="docutils literal"><span class="pre">goalReached:</span></tt>, where the
argument is the test’s short name.</p>
<p>Example:</p>
<div class="highlight-obj-c"><div class="highlight"><pre><span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="nf">newAccountCreated</span> <span class="p">{</span>
<span class="c1">// A new account was created, so whatever button color was chosen, worked!</span>
<span class="p">[</span><span class="n">ClutchAB</span> <span class="nl">goalReached:</span><span class="s">@"loginButtonColor"</span><span class="p">];</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="extras">
<h2>Extras<a class="headerlink" href="#extras" title="Permalink to this headline">¶</a></h2>
<p>It’s very common for data-driven tests to be color-related. To aid in this, we
have provided a simple function for getting a UIColor out of a hex-string.</p>
<p>Example:</p>
<div class="highlight-obj-c"><div class="highlight"><pre><span class="n">UIColor</span> <span class="o">*</span><span class="n">buttonColor</span> <span class="o">=</span> <span class="p">[</span><span class="n">ClutchAB</span> <span class="nl">colorFromHex:</span><span class="s">@"FF0044"</span><span class="p">];</span>
</pre></div>
</div>
<p>Here’s how it might be used with a data-driven test:</p>
<div class="highlight-obj-c"><div class="highlight"><pre><span class="p">[</span><span class="n">ClutchAB</span> <span class="nl">testWithName:</span><span class="s">@"loginButtonVariableColor"</span> <span class="nl">data:</span><span class="o">^</span><span class="p">(</span><span class="n">NSDictionary</span> <span class="o">*</span><span class="n">testData</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Extract the color from the testData dictionary, and assign it to the button.</span>
<span class="n">loginButton</span><span class="p">.</span><span class="n">tintColor</span> <span class="o">=</span> <span class="p">[</span><span class="n">ClutchAB</span> <span class="nl">colorFromHex:</span><span class="p">[</span><span class="n">testData</span> <span class="nl">objectForKey:</span><span class="s">@"color"</span><span class="p">]];</span>
<span class="p">}];</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar secondary-sec">
<div class="sphinxsidebarwrapper">
<h3 class="contents">Contents</h3>
<div class="pad">
<ul>
<li><a class="reference internal" href="#">iOS SDK</a><ul>
<li><a class="reference internal" href="#getting-started">Getting Started</a></li>
<li><a class="reference internal" href="#normal-tests">Normal Tests</a></li>
<li><a class="reference internal" href="#data-driven-tests">Data-driven Tests</a></li>
<li><a class="reference internal" href="#goal-reached">Goal Reached</a></li>
<li><a class="reference internal" href="#extras">Extras</a></li>
</ul>
</li>
</ul>
</div>
<h4>Previous topic</h4>
<p class="topless pad">
<a href="ab-testing-overview.html" title="previous chapter">Overview</a>
</p>
<h4>Next topic</h4>
<p class="topless pad">
<a href="ab-testing-android.html" title="next chapter">Android SDK</a>
</p>
<h3>This Page</h3>
<ul class="this-page-menu pad">
<li>
<a href="_sources/ab-testing-ios.txt" rel="nofollow">Show Source</a>
</li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<div class="pad">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" class="btn gray small" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip">
Enter search terms or a module, class or function name.
</p>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<div id="footer">
<div class="content">
<div class="left">
<ul>
<li><a href="/">Home</a></li>
<li class="#"><a href="http://blog.clutch.io">Blog</a></li>
</ul>
<br class="cl">
<a href="https://twitter.com/clutchio" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @clutchio</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div class="right">
<p class="copyright">Copyright © 2011-2012 Boilerplate Inc. San Francisco, CA.
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</p>
</div>
</div>
</div>
<!-- begin olark code --><script type='text/javascript'>/*{literal}<![CDATA[*/window.olark||(function(i){var e=window,h=document,a=e.location.protocol=="https:"?"https:":"http:",g=i.name,b="load";(function(){e[g]=function(){(c.s=c.s||[]).push(arguments)};var c=e[g]._={},f=i.methods.length; while(f--){(function(j){e[g][j]=function(){e[g]("call",j,arguments)}})(i.methods[f])} c.l=i.loader;c.i=arguments.callee;c.f=setTimeout(function(){if(c.f){(new Image).src=a+"//"+c.l.replace(".js",".png")+"&"+escape(e.location.href)}c.f=null},20000);c.p={0:+new Date};c.P=function(j){c.p[j]=new Date-c.p[0]};function d(){c.P(b);e[g](b)}e.addEventListener?e.addEventListener(b,d,false):e.attachEvent("on"+b,d); (function(){function l(j){j="head";return["<",j,"></",j,"><",z,' onl'+'oad="var d=',B,";d.getElementsByTagName('head')[0].",y,"(d.",A,"('script')).",u,"='",a,"//",c.l,"'",'"',"></",z,">"].join("")}var z="body",s=h[z];if(!s){return setTimeout(arguments.callee,100)}c.P(1);var y="appendChild",A="createElement",u="src",r=h[A]("div"),G=r[y](h[A](g)),D=h[A]("iframe"),B="document",C="domain",q;r.style.display="none";s.insertBefore(r,s.firstChild).id=g;D.frameBorder="0";D.id=g+"-loader";if(/MSIE[ ]+6/.test(navigator.userAgent)){D.src="javascript:false"} D.allowTransparency="true";G[y](D);try{D.contentWindow[B].open()}catch(F){i[C]=h[C];q="javascript:var d="+B+".open();d.domain='"+h.domain+"';";D[u]=q+"void(0);"}try{var H=D.contentWindow[B];H.write(l());H.close()}catch(E){D[u]=q+'d.write("'+l().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}c.P(2)})()})()})({loader:(function(a){return "static.olark.com/jsclient/loader0.js?ts="+(a?a[1]:(+new Date))})(document.cookie.match(/olarkld=([0-9]+)/)),name:"olark",methods:["configure","extend","declare","identify"]});
/* custom configuration goes here (www.olark.com/documentation) */
olark.configure('system.domain', '.clutch.io');
olark.identify('8940-141-10-1241');/*]]>{/literal}*/</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29049023-2']);
_gaq.push(['_setDomainName', 'clutch.io']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>