jazzy 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -5
  3. data/Rakefile +2 -0
  4. data/bin/jazzy +1 -1
  5. data/jazzy.gemspec +1 -0
  6. data/lib/jazzy.rb +1 -0
  7. data/lib/jazzy/assets/css/highlight.css.scss +63 -0
  8. data/lib/jazzy/assets/css/jazzy.css.scss +27 -1
  9. data/lib/jazzy/assets/js/jazzy.js +8 -2
  10. data/lib/jazzy/config.rb +32 -0
  11. data/lib/jazzy/doc.mustache +15 -1
  12. data/lib/jazzy/doc_builder.rb +24 -12
  13. data/lib/jazzy/docset_builder.rb +77 -0
  14. data/lib/jazzy/docset_builder/info_plist.mustache +20 -0
  15. data/lib/jazzy/gem_version.rb +1 -1
  16. data/lib/jazzy/highlighter.rb +10 -0
  17. data/lib/jazzy/partials/task.mustache +3 -3
  18. data/lib/jazzy/source_declaration.rb +3 -3
  19. data/lib/jazzy/source_declaration/type.rb +136 -0
  20. data/lib/jazzy/source_module.rb +10 -0
  21. data/lib/jazzy/sourcekitten.rb +35 -62
  22. data/logo.sketch +0 -0
  23. data/spec/integration_spec.rb +10 -0
  24. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Info.plist +20 -0
  25. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Classes.html +267 -0
  26. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Classes/Manager.html +488 -0
  27. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Classes/Manager/init(configuration:).html +218 -0
  28. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Classes/Request.html +841 -0
  29. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Enums.html +257 -0
  30. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Enums/ParameterEncoding.html +346 -0
  31. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Extensions.html +708 -0
  32. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Extensions/Manager.html +344 -0
  33. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Extensions/Request.html +368 -0
  34. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Functions.html +1040 -0
  35. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Global Variables.html +226 -0
  36. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Manager.html +344 -0
  37. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Manager/init(configuration:).html +218 -0
  38. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/ParameterEncoding.html +346 -0
  39. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Protocols.html +275 -0
  40. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Protocols/URLRequestConvertible.html +227 -0
  41. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Protocols/URLStringConvertible.html +227 -0
  42. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/Request.html +368 -0
  43. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/URLRequestConvertible.html +227 -0
  44. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/URLStringConvertible.html +227 -0
  45. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/carat.png +0 -0
  46. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/css/highlight.css +202 -0
  47. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/css/jazzy.css +708 -0
  48. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/dash.png +0 -0
  49. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/gh.png +0 -0
  50. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/highlight.css +202 -0
  51. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/img/carat.png +0 -0
  52. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/img/dash.png +0 -0
  53. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/img/gh.png +0 -0
  54. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/index.html +755 -0
  55. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/init(configuration:).html +218 -0
  56. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/jazzy.css +708 -0
  57. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/jazzy.js +21 -0
  58. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/jquery.min.js +4 -0
  59. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/js/jazzy.js +21 -0
  60. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/Documents/js/jquery.min.js +4 -0
  61. data/spec/integration_specs/document_alamofire/after/docs/Alamofire.docset/Contents/Resources/docSet.dsidx.csv +81 -0
  62. data/spec/integration_specs/document_alamofire/after/docs/Classes.html +18 -7
  63. data/spec/integration_specs/document_alamofire/after/docs/Classes/Manager.html +31 -19
  64. data/spec/integration_specs/document_alamofire/after/docs/Classes/Manager/init(configuration:).html +14 -1
  65. data/spec/integration_specs/document_alamofire/after/docs/Classes/Request.html +61 -46
  66. data/spec/integration_specs/document_alamofire/after/docs/Enums.html +18 -7
  67. data/spec/integration_specs/document_alamofire/after/docs/Enums/ParameterEncoding.html +20 -4
  68. data/spec/integration_specs/document_alamofire/after/docs/Extensions.html +68 -48
  69. data/spec/integration_specs/document_alamofire/after/docs/Extensions/Manager.html +21 -7
  70. data/spec/integration_specs/document_alamofire/after/docs/Extensions/Request.html +22 -10
  71. data/spec/integration_specs/document_alamofire/after/docs/Functions.html +51 -34
  72. data/spec/integration_specs/document_alamofire/after/docs/Global Variables.html +15 -4
  73. data/spec/integration_specs/document_alamofire/after/docs/Protocols.html +20 -7
  74. data/spec/integration_specs/document_alamofire/after/docs/Protocols/URLRequestConvertible.html +16 -4
  75. data/spec/integration_specs/document_alamofire/after/docs/Protocols/URLStringConvertible.html +16 -4
  76. data/spec/integration_specs/document_alamofire/after/docs/css/highlight.css +202 -0
  77. data/spec/integration_specs/document_alamofire/after/docs/css/jazzy.css +14 -0
  78. data/spec/integration_specs/document_alamofire/after/docs/index.html +53 -42
  79. data/spec/integration_specs/document_alamofire/after/docs/js/jazzy.js +8 -2
  80. data/spec/integration_specs/misc_jazzy_features/after/docs/Classes.html +34 -22
  81. data/spec/integration_specs/misc_jazzy_features/after/docs/Classes/ImplicitlyInternalTopLevelClass.html +16 -4
  82. data/spec/integration_specs/misc_jazzy_features/after/docs/Enums.html +16 -4
  83. data/spec/integration_specs/misc_jazzy_features/after/docs/Enums/DocumentedEnum.html +14 -1
  84. data/spec/integration_specs/misc_jazzy_features/after/docs/Global Variables.html +16 -4
  85. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Info.plist +20 -0
  86. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/Classes.html +309 -0
  87. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/Classes/ImplicitlyInternalTopLevelClass.html +143 -0
  88. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/DocumentedEnum.html +134 -0
  89. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/Enums.html +147 -0
  90. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/Enums/DocumentedEnum.html +134 -0
  91. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/Global Variables.html +146 -0
  92. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/ImplicitlyInternalTopLevelClass.html +143 -0
  93. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/carat.png +0 -0
  94. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/css/highlight.css +202 -0
  95. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/css/jazzy.css +708 -0
  96. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/dash.png +0 -0
  97. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/gh.png +0 -0
  98. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/highlight.css +202 -0
  99. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/img/carat.png +0 -0
  100. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/img/dash.png +0 -0
  101. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/img/gh.png +0 -0
  102. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/index.html +106 -0
  103. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/jazzy.css +708 -0
  104. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/jazzy.js +21 -0
  105. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/jquery.min.js +4 -0
  106. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/js/jazzy.js +21 -0
  107. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/Documents/js/jquery.min.js +4 -0
  108. data/spec/integration_specs/misc_jazzy_features/after/docs/MiscJazzyFeatures.docset/Contents/Resources/docSet.dsidx.csv +15 -0
  109. data/spec/integration_specs/misc_jazzy_features/after/docs/css/highlight.css +202 -0
  110. data/spec/integration_specs/misc_jazzy_features/after/docs/css/jazzy.css +14 -0
  111. data/spec/integration_specs/misc_jazzy_features/after/docs/index.html +12 -1
  112. data/spec/integration_specs/misc_jazzy_features/after/docs/js/jazzy.js +8 -2
  113. metadata +88 -5
  114. data/lib/jazzy/assets/css/github_syntax_highlighting.css.scss +0 -142
  115. data/spec/integration_specs/document_alamofire/after/docs/css/github_syntax_highlighting.css +0 -98
  116. data/spec/integration_specs/misc_jazzy_features/after/docs/css/github_syntax_highlighting.css +0 -98
@@ -0,0 +1,202 @@
1
+ /* Credit to https://gist.github.com/wataru420/2048287 */
2
+ .highlight {
3
+ /* Comment */
4
+ /* Error */
5
+ /* Keyword */
6
+ /* Operator */
7
+ /* Comment.Multiline */
8
+ /* Comment.Preproc */
9
+ /* Comment.Single */
10
+ /* Comment.Special */
11
+ /* Generic.Deleted */
12
+ /* Generic.Deleted.Specific */
13
+ /* Generic.Emph */
14
+ /* Generic.Error */
15
+ /* Generic.Heading */
16
+ /* Generic.Inserted */
17
+ /* Generic.Inserted.Specific */
18
+ /* Generic.Output */
19
+ /* Generic.Prompt */
20
+ /* Generic.Strong */
21
+ /* Generic.Subheading */
22
+ /* Generic.Traceback */
23
+ /* Keyword.Constant */
24
+ /* Keyword.Declaration */
25
+ /* Keyword.Pseudo */
26
+ /* Keyword.Reserved */
27
+ /* Keyword.Type */
28
+ /* Literal.Number */
29
+ /* Literal.String */
30
+ /* Name.Attribute */
31
+ /* Name.Builtin */
32
+ /* Name.Class */
33
+ /* Name.Constant */
34
+ /* Name.Entity */
35
+ /* Name.Exception */
36
+ /* Name.Function */
37
+ /* Name.Namespace */
38
+ /* Name.Tag */
39
+ /* Name.Variable */
40
+ /* Operator.Word */
41
+ /* Text.Whitespace */
42
+ /* Literal.Number.Float */
43
+ /* Literal.Number.Hex */
44
+ /* Literal.Number.Integer */
45
+ /* Literal.Number.Oct */
46
+ /* Literal.String.Backtick */
47
+ /* Literal.String.Char */
48
+ /* Literal.String.Doc */
49
+ /* Literal.String.Double */
50
+ /* Literal.String.Escape */
51
+ /* Literal.String.Heredoc */
52
+ /* Literal.String.Interpol */
53
+ /* Literal.String.Other */
54
+ /* Literal.String.Regex */
55
+ /* Literal.String.Single */
56
+ /* Literal.String.Symbol */
57
+ /* Name.Builtin.Pseudo */
58
+ /* Name.Variable.Class */
59
+ /* Name.Variable.Global */
60
+ /* Name.Variable.Instance */
61
+ /* Literal.Number.Integer.Long */ }
62
+ .highlight .c {
63
+ color: #999988;
64
+ font-style: italic; }
65
+ .highlight .err {
66
+ color: #a61717;
67
+ background-color: #e3d2d2; }
68
+ .highlight .k {
69
+ color: #000000;
70
+ font-weight: bold; }
71
+ .highlight .o {
72
+ color: #000000;
73
+ font-weight: bold; }
74
+ .highlight .cm {
75
+ color: #999988;
76
+ font-style: italic; }
77
+ .highlight .cp {
78
+ color: #999999;
79
+ font-weight: bold; }
80
+ .highlight .c1 {
81
+ color: #999988;
82
+ font-style: italic; }
83
+ .highlight .cs {
84
+ color: #999999;
85
+ font-weight: bold;
86
+ font-style: italic; }
87
+ .highlight .gd {
88
+ color: #000000;
89
+ background-color: #ffdddd; }
90
+ .highlight .gd .x {
91
+ color: #000000;
92
+ background-color: #ffaaaa; }
93
+ .highlight .ge {
94
+ color: #000000;
95
+ font-style: italic; }
96
+ .highlight .gr {
97
+ color: #aa0000; }
98
+ .highlight .gh {
99
+ color: #999999; }
100
+ .highlight .gi {
101
+ color: #000000;
102
+ background-color: #ddffdd; }
103
+ .highlight .gi .x {
104
+ color: #000000;
105
+ background-color: #aaffaa; }
106
+ .highlight .go {
107
+ color: #888888; }
108
+ .highlight .gp {
109
+ color: #555555; }
110
+ .highlight .gs {
111
+ font-weight: bold; }
112
+ .highlight .gu {
113
+ color: #aaaaaa; }
114
+ .highlight .gt {
115
+ color: #aa0000; }
116
+ .highlight .kc {
117
+ color: #000000;
118
+ font-weight: bold; }
119
+ .highlight .kd {
120
+ color: #000000;
121
+ font-weight: bold; }
122
+ .highlight .kp {
123
+ color: #000000;
124
+ font-weight: bold; }
125
+ .highlight .kr {
126
+ color: #000000;
127
+ font-weight: bold; }
128
+ .highlight .kt {
129
+ color: #445588;
130
+ font-weight: bold; }
131
+ .highlight .m {
132
+ color: #009999; }
133
+ .highlight .s {
134
+ color: #d14; }
135
+ .highlight .na {
136
+ color: #008080; }
137
+ .highlight .nb {
138
+ color: #0086B3; }
139
+ .highlight .nc {
140
+ color: #445588;
141
+ font-weight: bold; }
142
+ .highlight .no {
143
+ color: #008080; }
144
+ .highlight .ni {
145
+ color: #800080; }
146
+ .highlight .ne {
147
+ color: #990000;
148
+ font-weight: bold; }
149
+ .highlight .nf {
150
+ color: #990000;
151
+ font-weight: bold; }
152
+ .highlight .nn {
153
+ color: #555555; }
154
+ .highlight .nt {
155
+ color: #000080; }
156
+ .highlight .nv {
157
+ color: #008080; }
158
+ .highlight .ow {
159
+ color: #000000;
160
+ font-weight: bold; }
161
+ .highlight .w {
162
+ color: #bbbbbb; }
163
+ .highlight .mf {
164
+ color: #009999; }
165
+ .highlight .mh {
166
+ color: #009999; }
167
+ .highlight .mi {
168
+ color: #009999; }
169
+ .highlight .mo {
170
+ color: #009999; }
171
+ .highlight .sb {
172
+ color: #d14; }
173
+ .highlight .sc {
174
+ color: #d14; }
175
+ .highlight .sd {
176
+ color: #d14; }
177
+ .highlight .s2 {
178
+ color: #d14; }
179
+ .highlight .se {
180
+ color: #d14; }
181
+ .highlight .sh {
182
+ color: #d14; }
183
+ .highlight .si {
184
+ color: #d14; }
185
+ .highlight .sx {
186
+ color: #d14; }
187
+ .highlight .sr {
188
+ color: #009926; }
189
+ .highlight .s1 {
190
+ color: #d14; }
191
+ .highlight .ss {
192
+ color: #990073; }
193
+ .highlight .bp {
194
+ color: #999999; }
195
+ .highlight .vc {
196
+ color: #008080; }
197
+ .highlight .vg {
198
+ color: #008080; }
199
+ .highlight .vi {
200
+ color: #008080; }
201
+ .highlight .il {
202
+ color: #009999; }
@@ -0,0 +1,755 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Alamofire Reference</title>
5
+ <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
6
+ <link rel="stylesheet" type="text/css" href="css/highlight.css" />
7
+ <meta charset='utf-8'>
8
+ <script type="text/javascript">
9
+ window.jazzy = {'docset': false}
10
+ if (typeof window.dash != 'undefined') {
11
+ document.documentElement.className += ' dash'
12
+ window.jazzy.docset = true
13
+ }
14
+ if (navigator.userAgent.match(/xcode/i)) {
15
+ document.documentElement.className += ' xcode'
16
+ window.jazzy.docset = true
17
+ }
18
+ </script>
19
+ <script src="js/jquery.min.js" defer></script>
20
+ <script src="js/jazzy.js" defer></script>
21
+ </head>
22
+ <body id="reference" class="Swift">
23
+ <a title="Alamofire Reference"></a>
24
+ <header>
25
+ <div class="content-wrapper">
26
+ <p class="header-text"><a href="index.html">Alamofire Docs</a> (40% documented)</p>
27
+ <p id="header-links"><a href="https://github.com/Alamofire/Alamofire"><img id="header-icon" src="img/gh.png" height="16px" width="16px" />View on GitHub</a></p>
28
+ </div>
29
+ </header>
30
+ <section id="valence">
31
+ <div class="content-wrapper">
32
+ <p id="hierarchial_navigation">
33
+ <a href="index.html" id="design_resources_link">Alamofire Reference</a>
34
+ <img id="carat" src="img/carat.png" height="10px" width="6px" />
35
+ Alamofire Reference
36
+ </p>
37
+ </div>
38
+ </section>
39
+ <div class="content-wrapper">
40
+ <nav class="book-parts">
41
+ <ul class="nav-parts">
42
+ <li class="part-name tasks">
43
+ <a href="Classes.html">Classes</a>
44
+ <ul class="nav-chapters">
45
+ <li class="nav-chapter">
46
+ <a href="Classes/Manager.html">Manager</a>
47
+ </li>
48
+ <li class="nav-chapter">
49
+ <a href="Classes/Request.html">Request</a>
50
+ </li>
51
+ </ul>
52
+ </li>
53
+ <li class="part-name tasks">
54
+ <a href="Global Variables.html">Global Variables</a>
55
+ <ul class="nav-chapters">
56
+ <li class="nav-chapter">
57
+ <a href="Global Variables.html#/s:v9Alamofire20AlamofireErrorDomainSS">AlamofireErrorDomain</a>
58
+ </li>
59
+ </ul>
60
+ </li>
61
+ <li class="part-name tasks">
62
+ <a href="Enums.html">Enums</a>
63
+ <ul class="nav-chapters">
64
+ <li class="nav-chapter">
65
+ <a href="Enums.html#/s:O9Alamofire6Method">Method</a>
66
+ </li>
67
+ <li class="nav-chapter">
68
+ <a href="Enums/ParameterEncoding.html">ParameterEncoding</a>
69
+ </li>
70
+ </ul>
71
+ </li>
72
+ <li class="part-name tasks">
73
+ <a href="Extensions.html">Extensions</a>
74
+ <ul class="nav-chapters">
75
+ <li class="nav-chapter">
76
+ <a href="Extensions.html#/s:SS">String</a>
77
+ </li>
78
+ <li class="nav-chapter">
79
+ <a href="Extensions.html#/c:objc(cs)NSURLRequest">NSURLRequest</a>
80
+ </li>
81
+ <li class="nav-chapter">
82
+ <a href="Extensions.html#/c:objc(cs)NSURLRequest">NSURLRequest</a>
83
+ </li>
84
+ <li class="nav-chapter">
85
+ <a href="Extensions/Request.html">Request</a>
86
+ </li>
87
+ <li class="nav-chapter">
88
+ <a href="Extensions/Manager.html">Manager</a>
89
+ </li>
90
+ <li class="nav-chapter">
91
+ <a href="Extensions.html#/s:C9Alamofire7Request">Request</a>
92
+ </li>
93
+ <li class="nav-chapter">
94
+ <a href="Extensions/Manager.html">Manager</a>
95
+ </li>
96
+ <li class="nav-chapter">
97
+ <a href="Extensions/Request.html">Request</a>
98
+ </li>
99
+ <li class="nav-chapter">
100
+ <a href="Extensions/Request.html">Request</a>
101
+ </li>
102
+ <li class="nav-chapter">
103
+ <a href="Extensions/Request.html">Request</a>
104
+ </li>
105
+ <li class="nav-chapter">
106
+ <a href="Extensions/Request.html">Request</a>
107
+ </li>
108
+ <li class="nav-chapter">
109
+ <a href="Extensions/Request.html">Request</a>
110
+ </li>
111
+ <li class="nav-chapter">
112
+ <a href="Extensions/Request.html">Request</a>
113
+ </li>
114
+ </ul>
115
+ </li>
116
+ <li class="part-name tasks">
117
+ <a href="Functions.html">Functions</a>
118
+ <ul class="nav-chapters">
119
+ <li class="nav-chapter">
120
+ <a href="Functions.html#/s:F9Alamofire7requestFTOS_6MethodPS_20URLStringConvertible_10parametersGSqGVSs10DictionarySSPSs9AnyObject___8encodingOS_17ParameterEncoding_CS_7Request">request(_:_:parameters:encoding:)</a>
121
+ </li>
122
+ <li class="nav-chapter">
123
+ <a href="Functions.html#/s:F9Alamofire7requestFPS_21URLRequestConvertible_CS_7Request">request(_:)</a>
124
+ </li>
125
+ <li class="nav-chapter">
126
+ <a href="Functions.html#/s:F9Alamofire6uploadFTOS_6MethodPS_20URLStringConvertible_CSo5NSURL_CS_7Request">upload(_:_:_:)</a>
127
+ </li>
128
+ <li class="nav-chapter">
129
+ <a href="Functions.html#/s:F9Alamofire6uploadFTPS_21URLRequestConvertible_CSo5NSURL_CS_7Request">upload(_:_:)</a>
130
+ </li>
131
+ <li class="nav-chapter">
132
+ <a href="Functions.html#/s:F9Alamofire6uploadFTOS_6MethodPS_20URLStringConvertible_CSo6NSData_CS_7Request">upload(_:_:_:)</a>
133
+ </li>
134
+ <li class="nav-chapter">
135
+ <a href="Functions.html#/s:F9Alamofire6uploadFTPS_21URLRequestConvertible_CSo6NSData_CS_7Request">upload(_:_:)</a>
136
+ </li>
137
+ <li class="nav-chapter">
138
+ <a href="Functions.html#/s:F9Alamofire6uploadFTOS_6MethodPS_20URLStringConvertible_CSo13NSInputStream_CS_7Request">upload(_:_:_:)</a>
139
+ </li>
140
+ <li class="nav-chapter">
141
+ <a href="Functions.html#/s:F9Alamofire6uploadFTPS_21URLRequestConvertible_CSo13NSInputStream_CS_7Request">upload(_:_:)</a>
142
+ </li>
143
+ <li class="nav-chapter">
144
+ <a href="Functions.html#/s:F9Alamofire8downloadFTOS_6MethodPS_20URLStringConvertible_FTCSo5NSURLCSo17NSHTTPURLResponse_S2__CS_7Request">download(_:_:_:)</a>
145
+ </li>
146
+ <li class="nav-chapter">
147
+ <a href="Functions.html#/s:F9Alamofire8downloadFTPS_21URLRequestConvertible_FTCSo5NSURLCSo17NSHTTPURLResponse_S1__CS_7Request">download(_:_:)</a>
148
+ </li>
149
+ <li class="nav-chapter">
150
+ <a href="Functions.html#/s:F9Alamofire8downloadFT10resumeDataCSo6NSDataFTCSo5NSURLCSo17NSHTTPURLResponse_S1__CS_7Request">download(resumeData:_:)</a>
151
+ </li>
152
+ </ul>
153
+ </li>
154
+ <li class="part-name tasks">
155
+ <a href="Protocols.html">Protocols</a>
156
+ <ul class="nav-chapters">
157
+ <li class="nav-chapter">
158
+ <a href="Protocols/URLStringConvertible.html">URLStringConvertible</a>
159
+ </li>
160
+ <li class="nav-chapter">
161
+ <a href="Protocols/URLRequestConvertible.html">URLRequestConvertible</a>
162
+ </li>
163
+ </ul>
164
+ </li>
165
+ </ul>
166
+ </nav>
167
+ <div class="pixel-line"></div>
168
+ <div class="rubber-band-gap"></div>
169
+ <article class="chapter">
170
+ <a name="/"></a>
171
+ <h1 class="chapter-name">Alamofire</h1>
172
+ <section>
173
+ <section class="section">
174
+ <div class='readme'><p class="para"><img src="https://raw.githubusercontent.com/Alamofire/Alamofire/assets/alamofire.png" alt="Alamofire: Elegant Networking in Swift"></p><p class="para">Alamofire is an HTTP networking library written in Swift, from the <a href="https://github.com/mattt">creator</a> of <a href="https://github.com/afnetworking/afnetworking">AFNetworking</a>.</p><a href='#features' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='features'>Features</h2>
175
+
176
+ <ul>
177
+ <li>[x] Chainable Request / Response methods</li>
178
+ <li>[x] URL / JSON / plist Parameter Encoding</li>
179
+ <li>[x] Upload File / Data / Stream</li>
180
+ <li>[x] Download using Request or Resume data</li>
181
+ <li>[x] Authentication with NSURLCredential</li>
182
+ <li>[x] HTTP Response Validation</li>
183
+ <li>[x] Progress Closure &amp; NSProgress</li>
184
+ <li>[x] cURL Debug Output</li>
185
+ <li>[x] Comprehensive Unit Test Coverage</li>
186
+ <li>[x] Complete Documentation</li>
187
+ </ul>
188
+ <a href='#requirements' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='requirements'>Requirements</h2>
189
+
190
+ <ul>
191
+ <li>iOS 7.0+ / Mac OS X 10.9+</li>
192
+ <li>Xcode 6.1</li>
193
+ </ul>
194
+ <a href='#communication' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='communication'>Communication</h2>
195
+
196
+ <ul>
197
+ <li>If you <strong>need help</strong>, use <a href="http://stackoverflow.com/questions/tagged/alamofire">Stack Overflow</a>. (Tag &lsquo;alamofire&rsquo;)</li>
198
+ <li>If you&rsquo;d like to <strong>ask a general question</strong>, use <a href="http://stackoverflow.com/questions/tagged/alamofire">Stack Overflow</a>.</li>
199
+ <li>If you <strong>found a bug</strong>, open an issue.</li>
200
+ <li>If you <strong>have a feature request</strong>, open an issue.</li>
201
+ <li>If you <strong>want to contribute</strong>, submit a pull request.</li>
202
+ </ul>
203
+ <a href='#installation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='installation'>Installation</h2>
204
+
205
+ <blockquote>
206
+ <p class="para">For application targets that do not support embedded frameworks, such as iOS 7, Alamofire can be integrated by including the <code>Alamofire.swift</code> source file directly, and making the appropriate changes to calling semantics.</p></blockquote>
207
+ <p class="para"><em>Due to the current lack of <a href="http://cocoapods.org">proper infrastructure</a> for Swift dependency management, using Alamofire in your project requires the following steps:</em></p>
208
+ <ol>
209
+ <li>Add Alamofire as a <a href="http://git-scm.com/docs/git-submodule">submodule</a> by opening the Terminal, <code>cd</code>-ing into your top-level project directory, and entering the command <code>git submodule add https://github.com/Alamofire/Alamofire.git</code></li>
210
+ <li>Open the <code>Alamofire</code> folder, and drag <code>Alamofire.xcodeproj</code> into the file navigator of your app project.</li>
211
+ <li>In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the <q>Targets</q> heading in the sidebar.</li>
212
+ <li>Ensure that the deployment target of Alamofire.framework matches that of the application target.</li>
213
+ <li>In the tab bar at the top of that window, open the <q>Build Phases</q> panel.</li>
214
+ <li>Expand the <q>Target Dependencies</q> group, and add <code>Alamofire.framework</code>.</li>
215
+ <li>Click on the <code>+</code> button at the top left of the panel and select <q>New Copy Files Phase</q>. Rename this new phase to <q>Copy Frameworks</q>, set the <q>Destination</q> to <q>Frameworks</q>, and add <code>Alamofire.framework</code>.</li>
216
+ </ol>
217
+
218
+ <hr>
219
+ <a href='#usage' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='usage'>Usage</h2>
220
+ <a href='#making_a_request' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='making_a_request'>Making a Request</h3>
221
+ <pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Alamofire</span>
222
+
223
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">)</span>
224
+ </code></pre>
225
+ <a href='#response_handling' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='response_handling'>Response Handling</h3>
226
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="p">[</span><span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">])</span>
227
+ <span class="o">.</span><span class="n">response</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
228
+ <span class="nf">println</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
229
+ <span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
230
+ <span class="nf">println</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
231
+ <span class="p">}</span>
232
+ </code></pre>
233
+
234
+ <blockquote>
235
+ <p class="para">Networking in Alamofire is done <em>asynchronously</em>. Asynchronous programming may be a source of frustration to programmers unfamiliar with the concept, but there are <a href="https://developer.apple.com/library/ios/qa/qa1693/_index.html">very good reasons</a> for doing it this way.</p><p class="para">Rather than blocking execution to wait for a response from the server, a <a href="http://en.wikipedia.org/wiki/Callback_%28computer_programming%29">callback</a> is specified to handle the response once it&rsquo;s received. The result of a request is only available inside the scope of a response handler. Any execution contingent on the response or data received from the server must be done within a handler.</p></blockquote>
236
+ <a href='#response_serialization' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='response_serialization'>Response Serialization</h3>
237
+ <p class="para"><strong>Built-in Response Methods</strong></p>
238
+ <ul>
239
+ <li><code>response()</code></li>
240
+ <li><code>responseString(encoding: NSStringEncoding)</code></li>
241
+ <li><code>responseJSON(options: NSJSONReadingOptions)</code></li>
242
+ <li><code>responsePropertyList(options: NSPropertyListReadOptions)</code></li>
243
+ </ul>
244
+ <a href='#response_string_handler' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='response_string_handler'>Response String Handler</h4>
245
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">)</span>
246
+ <span class="o">.</span><span class="n">responseString</span> <span class="p">{</span> <span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">string</span><span class="p">,</span> <span class="n">_</span><span class="p">)</span> <span class="k">in</span>
247
+ <span class="nf">println</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
248
+ <span class="p">}</span>
249
+ </code></pre>
250
+ <a href='#response_json_handler' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='response_json_handler'>Response JSON Handler</h4>
251
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">)</span>
252
+ <span class="o">.</span><span class="n">responseJSON</span> <span class="p">{</span> <span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="kt">JSON</span><span class="p">,</span> <span class="n">_</span><span class="p">)</span> <span class="k">in</span>
253
+ <span class="nf">println</span><span class="p">(</span><span class="kt">JSON</span><span class="p">)</span>
254
+ <span class="p">}</span>
255
+ </code></pre>
256
+ <a href='#chained_response_handlers' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='chained_response_handlers'>Chained Response Handlers</h4>
257
+ <p class="para">Response handlers can even be chained:</p><pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">)</span>
258
+ <span class="o">.</span><span class="n">responseString</span> <span class="p">{</span> <span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">string</span><span class="p">,</span> <span class="n">_</span><span class="p">)</span> <span class="k">in</span>
259
+ <span class="nf">println</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
260
+ <span class="p">}</span>
261
+ <span class="o">.</span><span class="n">responseJSON</span> <span class="p">{</span> <span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="kt">JSON</span><span class="p">,</span> <span class="n">_</span><span class="p">)</span> <span class="k">in</span>
262
+ <span class="nf">println</span><span class="p">(</span><span class="kt">JSON</span><span class="p">)</span>
263
+ <span class="p">}</span>
264
+ </code></pre>
265
+ <a href='#http_methods' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='http_methods'>HTTP Methods</h3>
266
+ <p class="para"><code>Alamofire.Method</code> lists the HTTP methods defined in <a href="http://tools.ietf.org/html/rfc7231#section-4.3">RFC 7231 §4.3</a>:</p><pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">enum</span> <span class="kt">Method</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span>
267
+ <span class="k">case</span> <span class="kt">OPTIONS</span> <span class="o">=</span> <span class="s">"OPTIONS"</span>
268
+ <span class="k">case</span> <span class="kt">GET</span> <span class="o">=</span> <span class="s">"GET"</span>
269
+ <span class="k">case</span> <span class="kt">HEAD</span> <span class="o">=</span> <span class="s">"HEAD"</span>
270
+ <span class="k">case</span> <span class="kt">POST</span> <span class="o">=</span> <span class="s">"POST"</span>
271
+ <span class="k">case</span> <span class="kt">PUT</span> <span class="o">=</span> <span class="s">"PUT"</span>
272
+ <span class="k">case</span> <span class="kt">PATCH</span> <span class="o">=</span> <span class="s">"PATCH"</span>
273
+ <span class="k">case</span> <span class="kt">DELETE</span> <span class="o">=</span> <span class="s">"DELETE"</span>
274
+ <span class="k">case</span> <span class="kt">TRACE</span> <span class="o">=</span> <span class="s">"TRACE"</span>
275
+ <span class="k">case</span> <span class="kt">CONNECT</span> <span class="o">=</span> <span class="s">"CONNECT"</span>
276
+ <span class="p">}</span>
277
+ </code></pre>
278
+ <p class="para">These values can be passed as the first argument of the <code>Alamofire.request</code> method:</p><pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">POST</span><span class="p">,</span> <span class="s">"http://httpbin.org/post"</span><span class="p">)</span>
279
+
280
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">PUT</span><span class="p">,</span> <span class="s">"http://httpbin.org/put"</span><span class="p">)</span>
281
+
282
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">DELETE</span><span class="p">,</span> <span class="s">"http://httpbin.org/delete"</span><span class="p">)</span>
283
+ </code></pre>
284
+ <a href='#parameters' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='parameters'>Parameters</h3>
285
+ <a href='#get_request_with_url_encoded_parameters' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='get_request_with_url_encoded_parameters'>GET Request With URL-Encoded Parameters</h4>
286
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="p">[</span><span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">])</span>
287
+ <span class="c1">// http://httpbin.org/get?foo=bar
288
+ </span></code></pre>
289
+ <a href='#post_request_with_url_encoded_parameters' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='post_request_with_url_encoded_parameters'>POST Request With URL-Encoded Parameters</h4>
290
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">parameters</span> <span class="o">=</span> <span class="p">[</span>
291
+ <span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">,</span>
292
+ <span class="s">"baz"</span><span class="p">:</span> <span class="p">[</span><span class="s">"a"</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
293
+ <span class="s">"qux"</span><span class="p">:</span> <span class="p">[</span>
294
+ <span class="s">"x"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
295
+ <span class="s">"y"</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
296
+ <span class="s">"z"</span><span class="p">:</span> <span class="mi">3</span>
297
+ <span class="p">]</span>
298
+ <span class="p">]</span>
299
+
300
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">POST</span><span class="p">,</span> <span class="s">"http://httpbin.org/post"</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="n">parameters</span><span class="p">)</span>
301
+ <span class="c1">// HTTP body: foo=bar&amp;baz[]=a&amp;baz[]=1&amp;qux[x]=1&amp;qux[y]=2&amp;qux[z]=3
302
+ </span></code></pre>
303
+ <a href='#parameter_encoding' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='parameter_encoding'>Parameter Encoding</h3>
304
+ <p class="para">Parameters can also be encoded as JSON, Property List, or any custom format, using the <code>ParameterEncoding</code> enum:</p><pre class="highlight swift"><code><span class="kd">enum</span> <span class="kt">ParameterEncoding</span> <span class="p">{</span>
305
+ <span class="k">case</span> <span class="kt">URL</span>
306
+ <span class="k">case</span> <span class="kt">JSON</span>
307
+ <span class="k">case</span> <span class="kt">PropertyList</span><span class="p">(</span><span class="nv">format</span><span class="p">:</span> <span class="kt">NSPropertyListFormat</span><span class="p">,</span>
308
+ <span class="nv">options</span><span class="p">:</span> <span class="kt">NSPropertyListWriteOptions</span><span class="p">)</span>
309
+
310
+ <span class="kd">func</span> <span class="nf">encode</span><span class="p">(</span><span class="nv">request</span><span class="p">:</span> <span class="kt">NSURLRequest</span><span class="p">,</span>
311
+ <span class="nv">parameters</span><span class="p">:</span> <span class="p">[</span><span class="kt">String</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">]?)</span> <span class="o">-&gt;</span>
312
+ <span class="p">(</span><span class="kt">NSURLRequest</span><span class="p">,</span> <span class="kt">NSError</span><span class="p">?)</span>
313
+ <span class="p">{</span> <span class="o">...</span> <span class="p">}</span>
314
+ <span class="p">}</span>
315
+ </code></pre>
316
+
317
+ <ul>
318
+ <li><code>URL</code>: A query string to be set as or appended to any existing URL query for <code>GET</code>, <code>HEAD</code>, and <code>DELETE</code> requests, or set as the body for requests with any other HTTP method. The <code>Content-Type</code> HTTP header field of an encoded request with HTTP body is set to <code>application/x-www-form-urlencoded</code>. <em>Since there is no published specification for how to encode collection types, the convention of appending <code>[]</code> to the key for array values (<code>foo[]=1&amp;foo[]=2</code>), and appending the key surrounded by square brackets for nested dictionary values (<code>foo[bar]=baz</code>).</em></li>
319
+ <li><code>JSON</code>: Uses <code>NSJSONSerialization</code> to create a JSON representation of the parameters object, which is set as the body of the request. The <code>Content-Type</code> HTTP header field of an encoded request is set to <code>application/json</code>.</li>
320
+ <li><code>PropertyList</code>: Uses <code>NSPropertyListSerialization</code> to create a plist representation of the parameters object, according to the associated format and write options values, which is set as the body of the request. The <code>Content-Type</code> HTTP header field of an encoded request is set to <code>application/x-plist</code>.</li>
321
+ <li><code>Custom</code>: Uses the associated closure value to construct a new request given an existing request and parameters.</li>
322
+ </ul>
323
+ <a href='#manual_parameter_encoding_of_an_nsurlrequest' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='manual_parameter_encoding_of_an_nsurlrequest'>Manual Parameter Encoding of an NSURLRequest</h4>
324
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">URL</span> <span class="o">=</span> <span class="kt">NSURL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="s">"http://httpbin.org/get"</span><span class="p">)</span>
325
+ <span class="k">var</span> <span class="nv">request</span> <span class="o">=</span> <span class="kt">NSURLRequest</span><span class="p">(</span><span class="kt">URL</span><span class="p">:</span> <span class="kt">URL</span><span class="p">)</span>
326
+
327
+ <span class="k">let</span> <span class="nv">parameters</span> <span class="o">=</span> <span class="p">[</span><span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">]</span>
328
+ <span class="k">let</span> <span class="nv">encoding</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">ParameterEncoding</span><span class="o">.</span><span class="kt">URL</span>
329
+ <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">_</span><span class="p">)</span> <span class="o">=</span> <span class="n">encoding</span><span class="o">.</span><span class="nf">encode</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">parameters</span><span class="p">)</span>
330
+ </code></pre>
331
+ <a href='#post_request_with_json_encoded_parameters' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='post_request_with_json_encoded_parameters'>POST Request with JSON-encoded Parameters</h4>
332
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">parameters</span> <span class="o">=</span> <span class="p">[</span>
333
+ <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>
334
+ <span class="s">"bar"</span><span class="p">:</span> <span class="p">[</span>
335
+ <span class="s">"baz"</span><span class="p">:</span> <span class="s">"qux"</span>
336
+ <span class="p">]</span>
337
+ <span class="p">]</span>
338
+
339
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">POST</span><span class="p">,</span> <span class="s">"http://httpbin.org/post"</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="n">parameters</span><span class="p">,</span> <span class="nv">encoding</span><span class="p">:</span> <span class="o">.</span><span class="kt">JSON</span><span class="p">)</span>
340
+ <span class="c1">// HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}
341
+ </span></code></pre>
342
+ <a href='#caching' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='caching'>Caching</h3>
343
+ <p class="para">Caching is handled on the system framework level by <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLCache_Class/Reference/Reference.html#//apple_ref/occ/cl/NSURLCache"><code>NSURLCache</code></a>.</p><a href='#uploading' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='uploading'>Uploading</h3>
344
+ <p class="para"><strong>Supported Upload Types</strong></p>
345
+ <ul>
346
+ <li>File</li>
347
+ <li>Data</li>
348
+ <li>Stream</li>
349
+ </ul>
350
+ <a href='#uploading_a_file' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='uploading_a_file'>Uploading a File</h4>
351
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">fileURL</span> <span class="o">=</span> <span class="kt">NSBundle</span><span class="o">.</span><span class="nf">mainBundle</span><span class="p">()</span>
352
+ <span class="o">.</span><span class="kt">URLForResource</span><span class="p">(</span><span class="s">"Default"</span><span class="p">,</span>
353
+ <span class="nv">withExtension</span><span class="p">:</span> <span class="s">"png"</span><span class="p">)</span>
354
+
355
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">upload</span><span class="p">(</span><span class="o">.</span><span class="kt">POST</span><span class="p">,</span> <span class="s">"http://httpbin.org/post"</span><span class="p">,</span> <span class="nv">file</span><span class="p">:</span> <span class="n">fileURL</span><span class="p">)</span>
356
+ </code></pre>
357
+ <a href='#uploading_w_progress' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='uploading_w_progress'>Uploading w/Progress</h4>
358
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">upload</span><span class="p">(</span><span class="o">.</span><span class="kt">POST</span><span class="p">,</span> <span class="s">"http://httpbin.org/post"</span><span class="p">,</span> <span class="nv">file</span><span class="p">:</span> <span class="n">fileURL</span><span class="p">)</span>
359
+ <span class="o">.</span><span class="n">progress</span> <span class="p">{</span> <span class="p">(</span><span class="n">bytesWritten</span><span class="p">,</span> <span class="n">totalBytesWritten</span><span class="p">,</span> <span class="n">totalBytesExpectedToWrite</span><span class="p">)</span> <span class="k">in</span>
360
+ <span class="nf">println</span><span class="p">(</span><span class="n">totalBytesWritten</span><span class="p">)</span>
361
+ <span class="p">}</span>
362
+ <span class="o">.</span><span class="n">responseJSON</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="kt">JSON</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
363
+ <span class="nf">println</span><span class="p">(</span><span class="kt">JSON</span><span class="p">)</span>
364
+ <span class="p">}</span>
365
+ </code></pre>
366
+ <a href='#downloading' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='downloading'>Downloading</h3>
367
+ <p class="para"><strong>Supported Download Types</strong></p>
368
+ <ul>
369
+ <li>Request</li>
370
+ <li>Resume Data</li>
371
+ </ul>
372
+ <a href='#downloading_a_file' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='downloading_a_file'>Downloading a File</h4>
373
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">download</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/stream/100"</span><span class="p">,</span> <span class="nv">destination</span><span class="p">:</span> <span class="p">{</span> <span class="p">(</span><span class="n">temporaryURL</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span> <span class="k">in</span>
374
+ <span class="k">if</span> <span class="k">let</span> <span class="nv">directoryURL</span> <span class="o">=</span> <span class="kt">NSFileManager</span><span class="o">.</span><span class="nf">defaultManager</span><span class="p">()</span>
375
+ <span class="o">.</span><span class="kt">URLsForDirectory</span><span class="p">(</span><span class="o">.</span><span class="kt">DocumentDirectory</span><span class="p">,</span>
376
+ <span class="nv">inDomains</span><span class="p">:</span> <span class="o">.</span><span class="kt">UserDomainMask</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
377
+ <span class="k">as</span><span class="p">?</span> <span class="kt">NSURL</span> <span class="p">{</span>
378
+ <span class="k">let</span> <span class="nv">pathComponent</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">suggestedFilename</span>
379
+
380
+ <span class="k">return</span> <span class="n">directoryURL</span><span class="o">.</span><span class="kt">URLByAppendingPathComponent</span><span class="p">(</span><span class="n">pathComponent</span><span class="o">!</span><span class="p">)</span>
381
+ <span class="p">}</span>
382
+
383
+ <span class="k">return</span> <span class="n">temporaryURL</span>
384
+ <span class="p">})</span>
385
+ </code></pre>
386
+ <a href='#using_the_default_download_destination' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='using_the_default_download_destination'>Using the Default Download Destination</h4>
387
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">destination</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Request</span><span class="o">.</span><span class="nf">suggestedDownloadDestination</span><span class="p">(</span><span class="nv">directory</span><span class="p">:</span> <span class="o">.</span><span class="kt">DocumentDirectory</span><span class="p">,</span> <span class="nv">domain</span><span class="p">:</span> <span class="o">.</span><span class="kt">UserDomainMask</span><span class="p">)</span>
388
+
389
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">download</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/stream/100"</span><span class="p">,</span> <span class="nv">destination</span><span class="p">:</span> <span class="n">destination</span><span class="p">)</span>
390
+ </code></pre>
391
+ <a href='#downloading_a_file_w_progress' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='downloading_a_file_w_progress'>Downloading a File w/Progress</h4>
392
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">download</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/stream/100"</span><span class="p">,</span> <span class="nv">destination</span><span class="p">:</span> <span class="n">destination</span><span class="p">)</span>
393
+ <span class="o">.</span><span class="n">progress</span> <span class="p">{</span> <span class="p">(</span><span class="n">bytesRead</span><span class="p">,</span> <span class="n">totalBytesRead</span><span class="p">,</span> <span class="n">totalBytesExpectedToRead</span><span class="p">)</span> <span class="k">in</span>
394
+ <span class="nf">println</span><span class="p">(</span><span class="n">totalBytesRead</span><span class="p">)</span>
395
+ <span class="p">}</span>
396
+ <span class="o">.</span><span class="n">response</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
397
+ <span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
398
+ <span class="p">}</span>
399
+ </code></pre>
400
+ <a href='#authentication' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='authentication'>Authentication</h3>
401
+ <p class="para">Authentication is handled on the system framework level by <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLAuthenticationChallenge_Class/Reference/Reference.html"><code>NSURLCredential</code> and <code>NSURLAuthenticationChallenge</code></a>.</p><p class="para"><strong>Supported Authentication Schemes</strong></p>
402
+ <ul>
403
+ <li><a href="http://en.wikipedia.org/wiki/Basic_access_authentication">HTTP Basic</a></li>
404
+ <li><a href="http://en.wikipedia.org/wiki/Digest_access_authentication">HTTP Digest</a></li>
405
+ <li><a href="http://en.wikipedia.org/wiki/Kerberos_%28protocol%29">Kerberos</a></li>
406
+ <li><a href="http://en.wikipedia.org/wiki/NT_LAN_Manager">NTLM</a></li>
407
+ </ul>
408
+ <a href='#http_basic_authentication' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='http_basic_authentication'>HTTP Basic Authentication</h4>
409
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">user</span> <span class="o">=</span> <span class="s">"user"</span>
410
+ <span class="k">let</span> <span class="nv">password</span> <span class="o">=</span> <span class="s">"password"</span>
411
+
412
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"https://httpbin.org/basic-auth/</span><span class="se">\(</span><span class="n">user</span><span class="se">)</span><span class="s">/</span><span class="se">\(</span><span class="n">password</span><span class="se">)</span><span class="s">"</span><span class="p">)</span>
413
+ <span class="o">.</span><span class="nf">authenticate</span><span class="p">(</span><span class="nv">user</span><span class="p">:</span> <span class="n">user</span><span class="p">,</span> <span class="nv">password</span><span class="p">:</span> <span class="n">password</span><span class="p">)</span>
414
+ <span class="o">.</span><span class="n">response</span> <span class="p">{(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
415
+ <span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
416
+ <span class="p">}</span>
417
+ </code></pre>
418
+ <a href='#authentication_with_nsurlcredential' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='authentication_with_nsurlcredential'>Authentication with NSURLCredential</h4>
419
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">user</span> <span class="o">=</span> <span class="s">"user"</span>
420
+ <span class="k">let</span> <span class="nv">password</span> <span class="o">=</span> <span class="s">"password"</span>
421
+
422
+ <span class="k">let</span> <span class="nv">credential</span> <span class="o">=</span> <span class="kt">NSURLCredential</span><span class="p">(</span><span class="nv">user</span><span class="p">:</span> <span class="n">user</span><span class="p">,</span> <span class="nv">password</span><span class="p">:</span> <span class="n">password</span><span class="p">,</span> <span class="nv">persistence</span><span class="p">:</span> <span class="o">.</span><span class="kt">ForSession</span><span class="p">)</span>
423
+
424
+ <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"https://httpbin.org/basic-auth/</span><span class="se">\(</span><span class="n">user</span><span class="se">)</span><span class="s">/</span><span class="se">\(</span><span class="n">password</span><span class="se">)</span><span class="s">"</span><span class="p">)</span>
425
+ <span class="o">.</span><span class="nf">authenticate</span><span class="p">(</span><span class="nv">usingCredential</span><span class="p">:</span> <span class="n">credential</span><span class="p">)</span>
426
+ <span class="o">.</span><span class="n">response</span> <span class="p">{(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
427
+ <span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
428
+ <span class="p">}</span>
429
+ </code></pre>
430
+ <a href='#validation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='validation'>Validation</h3>
431
+ <p class="para">By default, Alamofire treats any completed request to be successful, regardless of the content of the response. Calling <code>validate</code> before a response handler causes an error to be generated if the response had an unacceptable status code or MIME type.</p><a href='#manual_validation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='manual_validation'>Manual Validation</h4>
432
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="p">[</span><span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">])</span>
433
+ <span class="o">.</span><span class="nf">validate</span><span class="p">(</span><span class="nv">statusCode</span><span class="p">:</span> <span class="mi">200</span><span class="o">..&lt;</span><span class="mi">300</span><span class="p">)</span>
434
+ <span class="o">.</span><span class="nf">validate</span><span class="p">(</span><span class="nv">contentType</span><span class="p">:</span> <span class="p">[</span><span class="s">"application/json"</span><span class="p">])</span>
435
+ <span class="o">.</span><span class="n">response</span> <span class="p">{</span> <span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
436
+ <span class="nf">println</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
437
+ <span class="p">}</span>
438
+ </code></pre>
439
+ <a href='#automatic_validation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='automatic_validation'>Automatic Validation</h4>
440
+ <p class="para">Automatically validates status code within <code>200...299</code> range, and that the <code>Content-Type</code> header of the response matches the <code>Accept</code> header of the request, if one is provided.</p><pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="p">[</span><span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">])</span>
441
+ <span class="o">.</span><span class="nf">validate</span><span class="p">()</span>
442
+ <span class="o">.</span><span class="n">response</span> <span class="p">{</span> <span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
443
+ <span class="nf">println</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
444
+ <span class="p">}</span>
445
+ </code></pre>
446
+ <a href='#printable' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='printable'>Printable</h3>
447
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">request</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/ip"</span><span class="p">)</span>
448
+
449
+ <span class="nf">println</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
450
+ <span class="c1">// GET http://httpbin.org/ip (200)
451
+ </span></code></pre>
452
+ <a href='#debugprintable' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='debugprintable'>DebugPrintable</h3>
453
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">request</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="p">[</span><span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">])</span>
454
+
455
+ <span class="nf">debugPrintln</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
456
+ </code></pre>
457
+ <a href='#output_curl' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='output_curl'>Output (cURL)</h4>
458
+ <pre class="highlight plaintext"><code>$ curl -i \
459
+ -H "User-Agent: Alamofire" \
460
+ -H "Accept-Encoding: Accept-Encoding: gzip;q=1.0,compress;q=0.5" \
461
+ -H "Accept-Language: en;q=1.0,fr;q=0.9,de;q=0.8,zh-Hans;q=0.7,zh-Hant;q=0.6,ja;q=0.5" \
462
+ "http://httpbin.org/get?foo=bar"
463
+ </code></pre>
464
+
465
+ <hr>
466
+ <a href='#advanced_usage' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='advanced_usage'>Advanced Usage</h2>
467
+
468
+ <blockquote>
469
+ <p class="para">Alamofire is built on <code>NSURLSession</code> and the Foundation URL Loading System. To make the most of
470
+ this framework, it is recommended that you be familiar with the concepts and capabilities of the underlying networking stack.</p></blockquote>
471
+ <p class="para"><strong>Recommended Reading</strong></p>
472
+ <ul>
473
+ <li><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html">URL Loading System Programming Guide</a></li>
474
+ <li><a href="https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/Introduction/Introduction.html#//apple_ref/occ/cl/NSURLSession">NSURLSession Class Reference</a></li>
475
+ <li><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLCache_Class/Reference/Reference.html#//apple_ref/occ/cl/NSURLCache">NSURLCache Class Reference</a></li>
476
+ <li><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLAuthenticationChallenge_Class/Reference/Reference.html">NSURLAuthenticationChallenge Class Reference</a></li>
477
+ </ul>
478
+ <a href='#manager' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='manager'>Manager</h3>
479
+ <p class="para">Top-level convenience methods like <code>Alamofire.request</code> use a shared instance of <code>Alamofire.Manager</code>, which is configured with the default <code>NSURLSessionConfiguration</code>.</p><p class="para">As such, the following two statements are equivalent:</p><pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://httpbin.org/get"</span><span class="p">)</span>
480
+ </code></pre>
481
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">manager</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Manager</span><span class="o">.</span><span class="n">sharedInstance</span>
482
+ <span class="n">manager</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="kt">NSURLRequest</span><span class="p">(</span><span class="kt">URL</span><span class="p">:</span> <span class="kt">NSURL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="s">"http://httpbin.org/get"</span><span class="p">)))</span>
483
+ </code></pre>
484
+ <p class="para">Applications can create managers for background and ephemeral sessions, as well as new managers that customize the default session configuration, such as for default headers (<code>HTTPAdditionalHeaders</code>) or timeout interval (<code>timeoutIntervalForRequest</code>).</p><a href='#creating_a_manager_with_default_configuration' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='creating_a_manager_with_default_configuration'>Creating a Manager with Default Configuration</h4>
485
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">configuration</span> <span class="o">=</span> <span class="kt">NSURLSessionConfiguration</span><span class="o">.</span><span class="nf">defaultSessionConfiguration</span><span class="p">()</span>
486
+ <span class="k">let</span> <span class="nv">manager</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Manager</span><span class="p">(</span><span class="nv">configuration</span><span class="p">:</span> <span class="n">configuration</span><span class="p">)</span>
487
+ </code></pre>
488
+ <a href='#creating_a_manager_with_background_configuration' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='creating_a_manager_with_background_configuration'>Creating a Manager with Background Configuration</h4>
489
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">configuration</span> <span class="o">=</span> <span class="kt">NSURLSessionConfiguration</span><span class="o">.</span><span class="nf">backgroundSessionConfiguration</span><span class="p">(</span><span class="s">"com.example.app.background"</span><span class="p">)</span>
490
+ <span class="k">let</span> <span class="nv">manager</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Manager</span><span class="p">(</span><span class="nv">configuration</span><span class="p">:</span> <span class="n">configuration</span><span class="p">)</span>
491
+ </code></pre>
492
+ <a href='#creating_a_manager_with_ephemeral_configuration' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='creating_a_manager_with_ephemeral_configuration'>Creating a Manager with Ephemeral Configuration</h4>
493
+ <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">configuration</span> <span class="o">=</span> <span class="kt">NSURLSessionConfiguration</span><span class="o">.</span><span class="nf">ephemeralSessionConfiguration</span><span class="p">()</span>
494
+ <span class="k">let</span> <span class="nv">manager</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Manager</span><span class="p">(</span><span class="nv">configuration</span><span class="p">:</span> <span class="n">configuration</span><span class="p">)</span>
495
+ </code></pre>
496
+ <a href='#modifying_session_configuration' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='modifying_session_configuration'>Modifying Session Configuration</h4>
497
+ <pre class="highlight swift"><code><span class="k">var</span> <span class="nv">defaultHeaders</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Manager</span><span class="o">.</span><span class="n">sharedInstance</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">configuration</span><span class="o">.</span><span class="kt">HTTPAdditionalHeaders</span> <span class="p">??</span> <span class="p">[:]</span>
498
+ <span class="n">defaultHeaders</span><span class="p">[</span><span class="s">"DNT"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"1 (Do Not Track Enabled)"</span>
499
+
500
+ <span class="k">let</span> <span class="nv">configuration</span> <span class="o">=</span> <span class="kt">NSURLSessionConfiguration</span><span class="o">.</span><span class="nf">defaultSessionConfiguration</span><span class="p">()</span>
501
+ <span class="n">configuration</span><span class="o">.</span><span class="kt">HTTPAdditionalHeaders</span> <span class="o">=</span> <span class="n">defaultHeaders</span>
502
+
503
+ <span class="k">let</span> <span class="nv">manager</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Manager</span><span class="p">(</span><span class="nv">configuration</span><span class="p">:</span> <span class="n">configuration</span><span class="p">)</span>
504
+ </code></pre>
505
+
506
+ <blockquote>
507
+ <p class="para">This is <strong>not</strong> recommended for <code>Authorization</code> or <code>Content-Type</code> headers. Instead, use <code>URLRequestConvertible</code> and <code>ParameterEncoding</code>, respectively.</p></blockquote>
508
+ <a href='#request' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='request'>Request</h3>
509
+ <p class="para">The result of a <code>request</code>, <code>upload</code>, or <code>download</code> method is an instance of <code>Alamofire.Request</code>. A request is always created using a constructor method from an owning manager, and never initialized directly.</p><p class="para">Methods like <code>authenticate</code>, <code>validate</code>, and <code>response</code> return the caller in order to facilitate chaining.</p><p class="para">Requests can be suspended, resumed, and cancelled:</p>
510
+ <ul>
511
+ <li><code>suspend()</code>: Suspends the underlying task and dispatch queue</li>
512
+ <li><code>resume()</code>: Resumes the underlying task and dispatch queue. If the owning manager does not have <code>startRequestsImmediately</code> set to <code>true</code>, the request must call <code>resume()</code> in order to start.</li>
513
+ <li><code>cancel()</code>: Cancels the underlying task, producing an error that is passed to any registered response handlers.</li>
514
+ </ul>
515
+ <a href='#response_serialization' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='response_serialization'>Response Serialization</h3>
516
+ <a href='#creating_a_custom_response_serializer' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='creating_a_custom_response_serializer'>Creating a Custom Response Serializer</h4>
517
+ <p class="para">Alamofire provides built-in response serialization for strings, JSON, and property lists, but others can be added in extensions on <code>Alamofire.Request</code>.</p><p class="para">For example, here&rsquo;s how a response handler using <a href="https://github.com/mattt/Ono">Ono</a> might be implemented:</p><pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">Request</span> <span class="p">{</span>
518
+ <span class="kd">class</span> <span class="kd">func</span> <span class="kt">XMLResponseSerializer</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Serializer</span> <span class="p">{</span>
519
+ <span class="k">return</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span> <span class="k">in</span>
520
+ <span class="k">if</span> <span class="n">data</span> <span class="o">==</span> <span class="kc">nil</span> <span class="p">{</span>
521
+ <span class="nf">return</span> <span class="p">(</span><span class="kc">nil</span><span class="p">,</span> <span class="kc">nil</span><span class="p">)</span>
522
+ <span class="p">}</span>
523
+
524
+ <span class="k">var</span> <span class="nv">XMLSerializationError</span><span class="p">:</span> <span class="kt">NSError</span><span class="p">?</span>
525
+ <span class="k">let</span> <span class="nv">XML</span> <span class="o">=</span> <span class="kt">ONOXMLDocument</span><span class="o">.</span><span class="kt">XMLDocumentWithData</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">&amp;</span><span class="kt">XMLSerializationError</span><span class="p">)</span>
526
+
527
+ <span class="nf">return</span> <span class="p">(</span><span class="kt">XML</span><span class="p">,</span> <span class="kt">XMLSerializationError</span><span class="p">)</span>
528
+ <span class="p">}</span>
529
+ <span class="p">}</span>
530
+
531
+ <span class="kd">func</span> <span class="nf">responseXMLDocument</span><span class="p">(</span><span class="nv">completionHandler</span><span class="p">:</span> <span class="p">(</span><span class="kt">NSURLRequest</span><span class="p">,</span> <span class="kt">NSHTTPURLResponse</span><span class="p">?,</span> <span class="kt">OnoXMLDocument</span><span class="p">?,</span> <span class="kt">NSError</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="k">Self</span> <span class="p">{</span>
532
+ <span class="k">return</span> <span class="nf">response</span><span class="p">(</span><span class="nv">serializer</span><span class="p">:</span> <span class="kt">Request</span><span class="o">.</span><span class="kt">XMLResponseSerializer</span><span class="p">(),</span> <span class="nv">completionHandler</span><span class="p">:</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="kt">XML</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
533
+ <span class="nf">completionHandler</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="kt">XML</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span>
534
+ <span class="p">})</span>
535
+ <span class="p">}</span>
536
+ <span class="p">}</span>
537
+ </code></pre>
538
+ <a href='#generic_response_object_serialization' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='generic_response_object_serialization'>Generic Response Object Serialization</h4>
539
+ <p class="para">Generics can be used to provide automatic, type-safe response object serialization.</p><pre class="highlight swift"><code><span class="k">@objc</span> <span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">ResponseObjectSerializable</span> <span class="p">{</span>
540
+ <span class="nf">init</span><span class="p">(</span><span class="nv">response</span><span class="p">:</span> <span class="kt">NSHTTPURLResponse</span><span class="p">,</span> <span class="nv">representation</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">)</span>
541
+ <span class="p">}</span>
542
+
543
+ <span class="kd">extension</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Request</span> <span class="p">{</span>
544
+ <span class="kd">public</span> <span class="kd">func</span> <span class="n">responseObject</span><span class="o">&lt;</span><span class="kt">T</span><span class="p">:</span> <span class="kt">ResponseObjectSerializable</span><span class="o">&gt;</span><span class="p">(</span><span class="nv">completionHandler</span><span class="p">:</span> <span class="p">(</span><span class="kt">NSURLRequest</span><span class="p">,</span> <span class="kt">NSHTTPURLResponse</span><span class="p">?,</span> <span class="kt">T</span><span class="p">?,</span> <span class="kt">NSError</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="k">Self</span> <span class="p">{</span>
545
+ <span class="k">let</span> <span class="nv">serializer</span><span class="p">:</span> <span class="kt">Serializer</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span> <span class="k">in</span>
546
+ <span class="k">let</span> <span class="nv">JSONSerializer</span> <span class="o">=</span> <span class="kt">Request</span><span class="o">.</span><span class="kt">JSONResponseSerializer</span><span class="p">(</span><span class="nv">options</span><span class="p">:</span> <span class="o">.</span><span class="kt">AllowFragments</span><span class="p">)</span>
547
+ <span class="nf">let</span> <span class="p">(</span><span class="kt">JSON</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">?,</span> <span class="n">serializationError</span><span class="p">)</span> <span class="o">=</span> <span class="kt">JSONSerializer</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
548
+ <span class="k">if</span> <span class="n">response</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="o">&amp;&amp;</span> <span class="kt">JSON</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
549
+ <span class="nf">return</span> <span class="p">(</span><span class="kt">T</span><span class="p">(</span><span class="nv">response</span><span class="p">:</span> <span class="n">response</span><span class="o">!</span><span class="p">,</span> <span class="nv">representation</span><span class="p">:</span> <span class="kt">JSON</span><span class="o">!</span><span class="p">),</span> <span class="kc">nil</span><span class="p">)</span>
550
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
551
+ <span class="nf">return</span> <span class="p">(</span><span class="kc">nil</span><span class="p">,</span> <span class="n">serializationError</span><span class="p">)</span>
552
+ <span class="p">}</span>
553
+ <span class="p">}</span>
554
+
555
+ <span class="k">return</span> <span class="nf">response</span><span class="p">(</span><span class="nv">serializer</span><span class="p">:</span> <span class="n">serializer</span><span class="p">,</span> <span class="nv">completionHandler</span><span class="p">:</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">object</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
556
+ <span class="nf">completionHandler</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">object</span> <span class="k">as</span><span class="p">?</span> <span class="kt">T</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span>
557
+ <span class="p">})</span>
558
+ <span class="p">}</span>
559
+ <span class="p">}</span>
560
+ </code></pre>
561
+ <pre class="highlight swift"><code><span class="kd">final</span> <span class="kd">class</span> <span class="kt">User</span><span class="p">:</span> <span class="kt">ResponseObjectSerializable</span> <span class="p">{</span>
562
+ <span class="k">let</span> <span class="nv">username</span><span class="p">:</span> <span class="kt">String</span>
563
+ <span class="k">let</span> <span class="nv">name</span><span class="p">:</span> <span class="kt">String</span>
564
+
565
+ <span class="kd">required</span> <span class="nf">init</span><span class="p">(</span><span class="nv">response</span><span class="p">:</span> <span class="kt">NSHTTPURLResponse</span><span class="p">,</span> <span class="nv">representation</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">)</span> <span class="p">{</span>
566
+ <span class="k">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="kt">URL</span><span class="o">!.</span><span class="n">lastPathComponent</span>
567
+ <span class="k">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">representation</span><span class="o">.</span><span class="nf">valueForKeyPath</span><span class="p">(</span><span class="s">"name"</span><span class="p">)</span> <span class="k">as</span> <span class="kt">String</span>
568
+ <span class="p">}</span>
569
+ <span class="p">}</span>
570
+ </code></pre>
571
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="s">"http://example.com/users/mattt"</span><span class="p">)</span>
572
+ <span class="o">.</span><span class="n">responseObject</span> <span class="p">{</span> <span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="nv">user</span><span class="p">:</span> <span class="kt">User</span><span class="p">?,</span> <span class="n">_</span><span class="p">)</span> <span class="k">in</span>
573
+ <span class="nf">println</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
574
+ <span class="p">}</span>
575
+ </code></pre>
576
+ <p class="para">The same approach can also be used to handle endpoints that return a representation of a collection of objects:</p><pre class="highlight swift"><code><span class="k">@objc</span> <span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">ResponseCollectionSerializable</span> <span class="p">{</span>
577
+ <span class="kd">class</span> <span class="kd">func</span> <span class="nf">collection</span><span class="p">(</span><span class="nv">#response</span><span class="p">:</span> <span class="kt">NSHTTPURLResponse</span><span class="p">,</span> <span class="nv">representation</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">[</span><span class="k">Self</span><span class="p">]</span>
578
+ <span class="p">}</span>
579
+
580
+ <span class="kd">extension</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Request</span> <span class="p">{</span>
581
+ <span class="kd">public</span> <span class="kd">func</span> <span class="n">responseCollection</span><span class="o">&lt;</span><span class="kt">T</span><span class="p">:</span> <span class="kt">ResponseCollectionSerializable</span><span class="o">&gt;</span><span class="p">(</span><span class="nv">completionHandler</span><span class="p">:</span> <span class="p">(</span><span class="kt">NSURLRequest</span><span class="p">,</span> <span class="kt">NSHTTPURLResponse</span><span class="p">?,</span> <span class="p">[</span><span class="kt">T</span><span class="p">]?,</span> <span class="kt">NSError</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="k">Self</span> <span class="p">{</span>
582
+ <span class="k">let</span> <span class="nv">serializer</span><span class="p">:</span> <span class="kt">Serializer</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span> <span class="k">in</span>
583
+ <span class="k">let</span> <span class="nv">JSONSerializer</span> <span class="o">=</span> <span class="kt">Request</span><span class="o">.</span><span class="kt">JSONResponseSerializer</span><span class="p">(</span><span class="nv">options</span><span class="p">:</span> <span class="o">.</span><span class="kt">AllowFragments</span><span class="p">)</span>
584
+ <span class="nf">let</span> <span class="p">(</span><span class="kt">JSON</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">?,</span> <span class="n">serializationError</span><span class="p">)</span> <span class="o">=</span> <span class="kt">JSONSerializer</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
585
+ <span class="k">if</span> <span class="n">response</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="o">&amp;&amp;</span> <span class="kt">JSON</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
586
+ <span class="nf">return</span> <span class="p">(</span><span class="kt">T</span><span class="o">.</span><span class="nf">collection</span><span class="p">(</span><span class="nv">response</span><span class="p">:</span> <span class="n">response</span><span class="o">!</span><span class="p">,</span> <span class="nv">representation</span><span class="p">:</span> <span class="kt">JSON</span><span class="o">!</span><span class="p">),</span> <span class="kc">nil</span><span class="p">)</span>
587
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
588
+ <span class="nf">return</span> <span class="p">(</span><span class="kc">nil</span><span class="p">,</span> <span class="n">serializationError</span><span class="p">)</span>
589
+ <span class="p">}</span>
590
+ <span class="p">}</span>
591
+
592
+ <span class="k">return</span> <span class="nf">response</span><span class="p">(</span><span class="nv">serializer</span><span class="p">:</span> <span class="n">serializer</span><span class="p">,</span> <span class="nv">completionHandler</span><span class="p">:</span> <span class="p">{</span> <span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">object</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="k">in</span>
593
+ <span class="nf">completionHandler</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">object</span> <span class="k">as</span><span class="p">?</span> <span class="p">[</span><span class="kt">T</span><span class="p">],</span> <span class="n">error</span><span class="p">)</span>
594
+ <span class="p">})</span>
595
+ <span class="p">}</span>
596
+ <span class="p">}</span>
597
+ </code></pre>
598
+ <a href='#urlstringconvertible' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='urlstringconvertible'>URLStringConvertible</h3>
599
+ <p class="para">Types adopting the <code>URLStringConvertible</code> protocol can be used to construct URL strings, which are then used to construct URL requests. Top-level convenience methods taking a <code>URLStringConvertible</code> argument are provided to allow for type-safe routing behavior.</p><p class="para">Applications interacting with web applications in a significant manner are encouraged to adopt either <code>URLStringConvertible</code> or <code>URLRequestConvertible</code> as a way to ensure consistency of requested endpoints.</p><a href='#type_safe_routing' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='type_safe_routing'>Type-Safe Routing</h4>
600
+ <pre class="highlight swift"><code><span class="kd">enum</span> <span class="kt">Router</span><span class="p">:</span> <span class="kt">URLStringConvertible</span> <span class="p">{</span>
601
+ <span class="kd">static</span> <span class="k">let</span> <span class="nv">baseURLString</span> <span class="o">=</span> <span class="s">"http://example.com"</span>
602
+
603
+ <span class="k">case</span> <span class="kt">Root</span>
604
+ <span class="k">case</span> <span class="kt">User</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span>
605
+ <span class="k">case</span> <span class="kt">Post</span><span class="p">(</span><span class="kt">Int</span><span class="p">,</span> <span class="kt">Int</span><span class="p">,</span> <span class="kt">String</span><span class="p">)</span>
606
+
607
+ <span class="c1">// MARK: URLStringConvertible
608
+ </span>
609
+ <span class="k">var</span> <span class="nv">URLString</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span>
610
+ <span class="k">let</span> <span class="nv">path</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="p">{</span>
611
+ <span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
612
+ <span class="k">case</span> <span class="o">.</span><span class="kt">Root</span><span class="p">:</span>
613
+ <span class="k">return</span> <span class="s">"/"</span>
614
+ <span class="k">case</span> <span class="o">.</span><span class="kt">User</span><span class="p">(</span><span class="k">let</span> <span class="nv">username</span><span class="p">):</span>
615
+ <span class="k">return</span> <span class="s">"/users/</span><span class="se">\(</span><span class="n">username</span><span class="se">)</span><span class="s">"</span>
616
+ <span class="k">case</span> <span class="o">.</span><span class="kt">Post</span><span class="p">(</span><span class="k">let</span> <span class="nv">year</span><span class="p">,</span> <span class="k">let</span> <span class="nv">month</span><span class="p">,</span> <span class="k">let</span> <span class="nv">title</span><span class="p">):</span>
617
+ <span class="k">let</span> <span class="nv">slug</span> <span class="o">=</span> <span class="n">title</span><span class="o">.</span><span class="nf">stringByReplacingOccurrencesOfString</span><span class="p">(</span><span class="s">" "</span><span class="p">,</span> <span class="nv">withString</span><span class="p">:</span> <span class="s">"-"</span><span class="p">)</span><span class="o">.</span><span class="n">lowercaseString</span>
618
+ <span class="k">return</span> <span class="s">"/</span><span class="se">\(</span><span class="n">year</span><span class="se">)</span><span class="s">/</span><span class="se">\(</span><span class="n">month</span><span class="se">)</span><span class="s">/</span><span class="se">\(</span><span class="n">slug</span><span class="se">)</span><span class="s">"</span>
619
+ <span class="p">}</span>
620
+ <span class="p">}()</span>
621
+
622
+ <span class="k">return</span> <span class="kt">Router</span><span class="o">.</span><span class="n">baseURLString</span> <span class="o">+</span> <span class="n">path</span>
623
+ <span class="p">}</span>
624
+ <span class="p">}</span>
625
+ </code></pre>
626
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="o">.</span><span class="kt">GET</span><span class="p">,</span> <span class="kt">Router</span><span class="o">.</span><span class="kt">User</span><span class="p">(</span><span class="s">"mattt"</span><span class="p">))</span>
627
+ </code></pre>
628
+ <a href='#urlrequestconvertible' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='urlrequestconvertible'>URLRequestConvertible</h3>
629
+ <p class="para">Types adopting the <code>URLRequestConvertible</code> protocol can be used to construct URL requests. Like <code>URLStringConvertible</code>, this is recommended for applications with any significant interactions between client and server.</p><p class="para">Top-level and instance methods on <code>Manager</code> taking <code>URLRequestConvertible</code> arguments are provided as a way to provide type-safe routing. Such an approach can be used to abstract away server-side inconsistencies, as well as manage authentication credentials and other state.</p><a href='#api_parameter_abstraction' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='api_parameter_abstraction'>API Parameter Abstraction</h4>
630
+ <pre class="highlight swift"><code><span class="kd">enum</span> <span class="kt">Router</span><span class="p">:</span> <span class="kt">URLRequestConvertible</span> <span class="p">{</span>
631
+ <span class="kd">static</span> <span class="k">let</span> <span class="nv">baseURLString</span> <span class="o">=</span> <span class="s">"http://example.com"</span>
632
+ <span class="kd">static</span> <span class="k">let</span> <span class="nv">perPage</span> <span class="o">=</span> <span class="mi">50</span>
633
+
634
+ <span class="k">case</span> <span class="kt">Search</span><span class="p">(</span><span class="nv">query</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">page</span><span class="p">:</span> <span class="kt">Int</span><span class="p">)</span>
635
+
636
+ <span class="c1">// MARK: URLRequestConvertible
637
+ </span>
638
+ <span class="k">var</span> <span class="nv">URLRequest</span><span class="p">:</span> <span class="kt">NSURLRequest</span> <span class="p">{</span>
639
+ <span class="nf">let</span> <span class="p">(</span><span class="nv">path</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="p">[</span><span class="kt">String</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">]?)</span> <span class="o">=</span> <span class="p">{</span>
640
+ <span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
641
+ <span class="k">case</span> <span class="o">.</span><span class="kt">Search</span><span class="p">(</span><span class="k">let</span> <span class="nv">query</span><span class="p">,</span> <span class="k">let</span> <span class="nv">page</span><span class="p">)</span> <span class="k">where</span> <span class="n">page</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
642
+ <span class="nf">return</span> <span class="p">(</span><span class="s">"/search"</span><span class="p">,</span> <span class="p">[</span><span class="s">"q"</span><span class="p">:</span> <span class="n">query</span><span class="p">,</span> <span class="s">"offset"</span><span class="p">:</span> <span class="kt">Router</span><span class="o">.</span><span class="n">perPage</span> <span class="o">*</span> <span class="n">page</span><span class="p">])</span>
643
+ <span class="k">case</span> <span class="o">.</span><span class="kt">Search</span><span class="p">(</span><span class="k">let</span> <span class="nv">query</span><span class="p">,</span> <span class="n">_</span><span class="p">):</span>
644
+ <span class="nf">return</span> <span class="p">(</span><span class="s">"/search"</span><span class="p">,</span> <span class="p">[</span><span class="s">"q"</span><span class="p">:</span> <span class="n">query</span><span class="p">])</span>
645
+ <span class="p">}</span>
646
+ <span class="p">}()</span>
647
+
648
+ <span class="k">let</span> <span class="nv">URL</span> <span class="o">=</span> <span class="kt">NSURL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="kt">Router</span><span class="o">.</span><span class="n">baseURLString</span><span class="p">)</span>
649
+ <span class="k">let</span> <span class="nv">URLRequest</span> <span class="o">=</span> <span class="kt">NSURLRequest</span><span class="p">(</span><span class="kt">URL</span><span class="p">:</span> <span class="kt">URL</span><span class="o">.</span><span class="kt">URLByAppendingPathComponent</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
650
+ <span class="k">let</span> <span class="nv">encoding</span> <span class="o">=</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">ParameterEncoding</span><span class="o">.</span><span class="kt">URL</span>
651
+
652
+ <span class="k">return</span> <span class="n">encoding</span><span class="o">.</span><span class="nf">encode</span><span class="p">(</span><span class="kt">URLRequest</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="n">parameters</span><span class="p">)</span><span class="o">.</span><span class="mi">0</span>
653
+ <span class="p">}</span>
654
+ <span class="p">}</span>
655
+ </code></pre>
656
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="kt">Router</span><span class="o">.</span><span class="kt">Search</span><span class="p">(</span><span class="nv">query</span><span class="p">:</span> <span class="s">"foo bar"</span><span class="p">,</span> <span class="nv">page</span><span class="p">:</span> <span class="mi">1</span><span class="p">))</span> <span class="c1">// ?q=foo+bar&amp;offset=50
657
+ </span></code></pre>
658
+ <a href='#crud_amp_authorization' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='crud_amp_authorization'>CRUD &amp; Authorization</h4>
659
+ <pre class="highlight swift"><code><span class="kd">enum</span> <span class="kt">Router</span><span class="p">:</span> <span class="kt">URLRequestConvertible</span> <span class="p">{</span>
660
+ <span class="kd">static</span> <span class="k">let</span> <span class="nv">baseURLString</span> <span class="o">=</span> <span class="s">"http://example.com"</span>
661
+ <span class="kd">static</span> <span class="k">var</span> <span class="nv">OAuthToken</span><span class="p">:</span> <span class="kt">String</span><span class="p">?</span>
662
+
663
+ <span class="k">case</span> <span class="kt">CreateUser</span><span class="p">([</span><span class="kt">String</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">])</span>
664
+ <span class="k">case</span> <span class="kt">ReadUser</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span>
665
+ <span class="k">case</span> <span class="kt">UpdateUser</span><span class="p">(</span><span class="kt">String</span><span class="p">,</span> <span class="p">[</span><span class="kt">String</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">])</span>
666
+ <span class="k">case</span> <span class="kt">DestroyUser</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span>
667
+
668
+ <span class="k">var</span> <span class="nv">method</span><span class="p">:</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Method</span> <span class="p">{</span>
669
+ <span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
670
+ <span class="k">case</span> <span class="o">.</span><span class="kt">CreateUser</span><span class="p">:</span>
671
+ <span class="k">return</span> <span class="o">.</span><span class="kt">POST</span>
672
+ <span class="k">case</span> <span class="o">.</span><span class="kt">ReadUser</span><span class="p">:</span>
673
+ <span class="k">return</span> <span class="o">.</span><span class="kt">GET</span>
674
+ <span class="k">case</span> <span class="o">.</span><span class="kt">UpdateUser</span><span class="p">:</span>
675
+ <span class="k">return</span> <span class="o">.</span><span class="kt">PUT</span>
676
+ <span class="k">case</span> <span class="o">.</span><span class="kt">DestroyUser</span><span class="p">:</span>
677
+ <span class="k">return</span> <span class="o">.</span><span class="kt">DELETE</span>
678
+ <span class="p">}</span>
679
+ <span class="p">}</span>
680
+
681
+ <span class="k">var</span> <span class="nv">path</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span>
682
+ <span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
683
+ <span class="k">case</span> <span class="o">.</span><span class="kt">CreateUser</span><span class="p">:</span>
684
+ <span class="k">return</span> <span class="s">"/users"</span>
685
+ <span class="k">case</span> <span class="o">.</span><span class="kt">ReadUser</span><span class="p">(</span><span class="k">let</span> <span class="nv">username</span><span class="p">):</span>
686
+ <span class="k">return</span> <span class="s">"/users/</span><span class="se">\(</span><span class="n">username</span><span class="se">)</span><span class="s">"</span>
687
+ <span class="k">case</span> <span class="o">.</span><span class="kt">UpdateUser</span><span class="p">(</span><span class="k">let</span> <span class="nv">username</span><span class="p">,</span> <span class="n">_</span><span class="p">):</span>
688
+ <span class="k">return</span> <span class="s">"/users/</span><span class="se">\(</span><span class="n">username</span><span class="se">)</span><span class="s">"</span>
689
+ <span class="k">case</span> <span class="o">.</span><span class="kt">DestroyUser</span><span class="p">(</span><span class="k">let</span> <span class="nv">username</span><span class="p">):</span>
690
+ <span class="k">return</span> <span class="s">"/users/</span><span class="se">\(</span><span class="n">username</span><span class="se">)</span><span class="s">"</span>
691
+ <span class="p">}</span>
692
+ <span class="p">}</span>
693
+
694
+ <span class="c1">// MARK: URLRequestConvertible
695
+ </span>
696
+ <span class="k">var</span> <span class="nv">URLRequest</span><span class="p">:</span> <span class="kt">NSURLRequest</span> <span class="p">{</span>
697
+ <span class="k">let</span> <span class="nv">URL</span> <span class="o">=</span> <span class="kt">NSURL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="kt">Router</span><span class="o">.</span><span class="n">baseURLString</span><span class="p">)</span>
698
+ <span class="k">let</span> <span class="nv">mutableURLRequest</span> <span class="o">=</span> <span class="kt">NSMutableURLRequest</span><span class="p">(</span><span class="kt">URL</span><span class="p">:</span> <span class="kt">URL</span><span class="o">.</span><span class="kt">URLByAppendingPathComponent</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
699
+ <span class="n">mutableURLRequest</span><span class="o">.</span><span class="kt">HTTPMethod</span> <span class="o">=</span> <span class="n">method</span><span class="o">.</span><span class="nf">toRaw</span><span class="p">()</span>
700
+
701
+ <span class="k">if</span> <span class="k">let</span> <span class="nv">token</span> <span class="o">=</span> <span class="kt">Router</span><span class="o">.</span><span class="kt">OAuthToken</span> <span class="p">{</span>
702
+ <span class="n">mutableURLRequest</span><span class="o">.</span><span class="nf">setValue</span><span class="p">(</span><span class="s">"Bearer </span><span class="se">\(</span><span class="n">token</span><span class="se">)</span><span class="s">"</span><span class="p">,</span> <span class="nv">forHTTPHeaderField</span><span class="p">:</span> <span class="s">"Authorization"</span><span class="p">)</span>
703
+ <span class="p">}</span>
704
+
705
+ <span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
706
+ <span class="k">case</span> <span class="o">.</span><span class="kt">CreateUser</span><span class="p">(</span><span class="k">let</span> <span class="nv">parameters</span><span class="p">):</span>
707
+ <span class="k">return</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">ParameterEncoding</span><span class="o">.</span><span class="kt">JSON</span><span class="o">.</span><span class="nf">encode</span><span class="p">(</span><span class="n">mutableURLRequest</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="n">parameters</span><span class="p">)</span><span class="o">.</span><span class="mi">0</span>
708
+ <span class="k">case</span> <span class="o">.</span><span class="kt">UpdateUser</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="k">let</span> <span class="nv">parameters</span><span class="p">):</span>
709
+ <span class="k">return</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">ParameterEncoding</span><span class="o">.</span><span class="kt">URL</span><span class="o">.</span><span class="nf">encode</span><span class="p">(</span><span class="n">mutableURLRequest</span><span class="p">,</span> <span class="nv">parameters</span><span class="p">:</span> <span class="n">parameters</span><span class="p">)</span><span class="o">.</span><span class="mi">0</span>
710
+ <span class="k">default</span><span class="p">:</span>
711
+ <span class="k">return</span> <span class="n">mutableURLRequest</span>
712
+ <span class="p">}</span>
713
+ <span class="p">}</span>
714
+ <span class="p">}</span>
715
+ </code></pre>
716
+ <pre class="highlight swift"><code><span class="kt">Alamofire</span><span class="o">.</span><span class="nf">request</span><span class="p">(</span><span class="kt">Router</span><span class="o">.</span><span class="kt">ReadUser</span><span class="p">(</span><span class="s">"mattt"</span><span class="p">))</span> <span class="c1">// GET /users/mattt
717
+ </span></code></pre>
718
+
719
+ <hr>
720
+ <a href='#faq' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='faq'>FAQ</h2>
721
+ <a href='#when_should_i_use_alamofire' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='when_should_i_use_alamofire'>When should I use Alamofire?</h3>
722
+ <p class="para">If you&rsquo;re starting a new project in Swift, and want to take full advantage of its conventions and language features, Alamofire is a great choice. Although not as fully-featured as AFNetworking, Alamofire is much nicer to work with, and should satisfy the vast majority of networking use cases.</p>
723
+ <blockquote>
724
+ <p class="para">It&rsquo;s important to note that two libraries aren&rsquo;t mutually exclusive: AFNetworking and Alamofire can peacefully exist in the same code base.</p></blockquote>
725
+ <a href='#when_should_i_use_afnetworking' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='when_should_i_use_afnetworking'>When should I use AFNetworking?</h3>
726
+ <p class="para">AFNetworking remains the premiere networking library available for OS X and iOS, and can easily be used in Swift, just like any other Objective-C code. AFNetworking is stable and reliable, and isn&rsquo;t going anywhere.</p><p class="para">Use AFNetworking for any of the following:</p>
727
+ <ul>
728
+ <li>UIKit extensions, such as asynchronously loading images to <code>UIImageView</code></li>
729
+ <li>TLS verification, using <code>AFSecurityManager</code></li>
730
+ <li>Situations requiring <code>NSOperation</code> or <code>NSURLConnection</code>, using <code>AFURLConnectionOperation</code></li>
731
+ <li>Network reachability monitoring, using <code>AFNetworkReachabilityManager</code></li>
732
+ <li>Multipart HTTP request construction, using <code>AFHTTPRequestSerializer</code></li>
733
+ </ul>
734
+ <a href='#what_39_s_the_origin_of_the_name_alamofire' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='what_39_s_the_origin_of_the_name_alamofire'>What&rsquo;s the origin of the name Alamofire?</h3>
735
+ <p class="para">Alamofire is named after the <a href="https://aggie-horticulture.tamu.edu/wildseed/alamofire.html">Alamo Fire flower</a>, a hybrid variant of the Bluebonnet, the official state flower of Texas.</p>
736
+ <hr>
737
+ <a href='#contact' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='contact'>Contact</h2>
738
+ <p class="para">Follow AFNetworking on Twitter (<a href="https://twitter.com/AFNetworking">@AFNetworking</a>)</p><a href='#creator' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='creator'>Creator</h3>
739
+
740
+ <ul>
741
+ <li><a href="http://github.com/mattt">Mattt Thompson</a> (<a href="https://twitter.com/mattt">@mattt</a>)</li>
742
+ </ul>
743
+ <a href='#license' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='license'>License</h2>
744
+ <p class="para">Alamofire is released under the MIT license. See LICENSE for details.</p></div>
745
+ </section>
746
+ </section>
747
+ <section id="footer">
748
+ <p class="copyright">&copy; YYYY <a class="link" href="https://nshipster.com/alamofire" target="_blank" rel="external">Alamofire</a>. All rights reserved. (Last updated: YYYY-MM-DD)</p>
749
+ <p class="copyright">Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ vX.X.X</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
750
+ </section>
751
+ </article>
752
+ </div>
753
+ </body>
754
+ </div>
755
+ </html>