jazzy 0.0.20 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +6 -3
- data/.travis.yml +1 -1
- data/CHANGELOG.md +23 -1
- data/Gemfile.lock +41 -5
- data/Rakefile +21 -0
- data/jazzy.gemspec +1 -0
- data/lib/jazzy/assets/css/jazzy.css.scss +26 -0
- data/lib/jazzy/config.rb +29 -0
- data/lib/jazzy/doc_builder.rb +17 -9
- data/lib/jazzy/docset_builder.rb +13 -4
- data/lib/jazzy/gem_version.rb +1 -1
- data/lib/jazzy/jazzy_markdown.rb +2 -1
- data/lib/jazzy/podspec_documenter.rb +109 -0
- data/lib/jazzy/readme_generator.rb +33 -6
- data/lib/jazzy/sourcekitten.rb +15 -2
- data/lib/jazzy/sourcekitten/Commandant.framework/Commandant +0 -0
- data/lib/jazzy/sourcekitten/Commandant.framework/Versions/A/Commandant +0 -0
- data/lib/jazzy/sourcekitten/Commandant.framework/Versions/A/Modules/Commandant.swiftmodule/x86_64.swiftdoc +0 -0
- data/lib/jazzy/sourcekitten/Commandant.framework/Versions/A/Modules/Commandant.swiftmodule/x86_64.swiftmodule +0 -0
- data/lib/jazzy/sourcekitten/Commandant.framework/Versions/A/Modules/module.modulemap +10 -0
- data/{spec/integration_specs/misc_jazzy_features/before/MiscJazzyFeatures → lib/jazzy/sourcekitten/Commandant.framework/Versions/A/Resources}/Info.plist +21 -7
- data/lib/jazzy/sourcekitten/LlamaKit.framework/LlamaKit +0 -0
- data/lib/jazzy/sourcekitten/LlamaKit.framework/Versions/A/LlamaKit +0 -0
- data/lib/jazzy/sourcekitten/LlamaKit.framework/Versions/A/Modules/LlamaKit.swiftmodule/x86_64.swiftdoc +0 -0
- data/lib/jazzy/sourcekitten/LlamaKit.framework/Versions/A/Modules/LlamaKit.swiftmodule/x86_64.swiftmodule +0 -0
- data/lib/jazzy/sourcekitten/LlamaKit.framework/Versions/A/Modules/module.modulemap +10 -0
- data/lib/jazzy/sourcekitten/LlamaKit.framework/Versions/A/Resources/Info.plist +47 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/SourceKittenFramework +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/SwiftXPC.framework/SwiftXPC +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/SwiftXPC.framework/Versions/A/Modules/SwiftXPC.swiftmodule/x86_64.swiftdoc +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/SwiftXPC.framework/Versions/A/Modules/SwiftXPC.swiftmodule/x86_64.swiftmodule +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/SwiftXPC.framework/Versions/A/Modules/module.modulemap +10 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/SwiftXPC.framework/Versions/A/Resources/Info.plist +42 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/SwiftXPC.framework/Versions/A/SwiftXPC +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/libswiftCore.dylib +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/libswiftCoreGraphics.dylib +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/libswiftDarwin.dylib +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/libswiftDispatch.dylib +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/libswiftFoundation.dylib +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/libswiftObjectiveC.dylib +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Frameworks/libswiftSecurity.dylib +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Modules/SourceKittenFramework.swiftmodule/x86_64.swiftdoc +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Modules/SourceKittenFramework.swiftmodule/x86_64.swiftmodule +0 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Modules/module.modulemap +10 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/Resources/Info.plist +42 -0
- data/lib/jazzy/sourcekitten/SourceKittenFramework.framework/Versions/A/SourceKittenFramework +0 -0
- data/lib/jazzy/sourcekitten/sourcekitten +0 -0
- data/spec/integration_spec.rb +6 -0
- metadata +50 -122
- data/bin/sourcekitten +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/Classes.html +0 -268
- data/spec/integration_specs/document_alamofire/after/docs/Classes/Manager.html +0 -488
- data/spec/integration_specs/document_alamofire/after/docs/Classes/Request.html +0 -842
- data/spec/integration_specs/document_alamofire/after/docs/Enums.html +0 -258
- data/spec/integration_specs/document_alamofire/after/docs/Enums/ParameterEncoding.html +0 -383
- data/spec/integration_specs/document_alamofire/after/docs/Extensions.html +0 -703
- data/spec/integration_specs/document_alamofire/after/docs/Extensions/Manager.html +0 -345
- data/spec/integration_specs/document_alamofire/after/docs/Extensions/Request.html +0 -369
- data/spec/integration_specs/document_alamofire/after/docs/Functions.html +0 -1041
- data/spec/integration_specs/document_alamofire/after/docs/Global Variables.html +0 -227
- data/spec/integration_specs/document_alamofire/after/docs/Protocols.html +0 -276
- data/spec/integration_specs/document_alamofire/after/docs/Protocols/URLRequestConvertible.html +0 -228
- data/spec/integration_specs/document_alamofire/after/docs/Protocols/URLStringConvertible.html +0 -228
- data/spec/integration_specs/document_alamofire/after/docs/css/highlight.css +0 -202
- data/spec/integration_specs/document_alamofire/after/docs/css/jazzy.css +0 -708
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Info.plist +0 -20
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Classes.html +0 -268
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Classes/Manager.html +0 -488
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Classes/Request.html +0 -842
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Enums.html +0 -258
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Enums/ParameterEncoding.html +0 -383
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Extensions.html +0 -703
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Extensions/Manager.html +0 -345
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Extensions/Request.html +0 -369
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Functions.html +0 -1041
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Global Variables.html +0 -227
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Manager.html +0 -345
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/ParameterEncoding.html +0 -383
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Protocols.html +0 -276
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Protocols/URLRequestConvertible.html +0 -228
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Protocols/URLStringConvertible.html +0 -228
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/Request.html +0 -369
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/URLRequestConvertible.html +0 -228
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/URLStringConvertible.html +0 -228
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/carat.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/css/highlight.css +0 -202
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/css/jazzy.css +0 -708
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/dash.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/gh.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/highlight.css +0 -202
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/img/carat.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/img/dash.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/img/gh.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/index.html +0 -756
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/jazzy.css +0 -708
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/jazzy.js +0 -21
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/jquery.min.js +0 -4
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/js/jazzy.js +0 -21
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/js/jquery.min.js +0 -4
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/Documents/undocumented.txt +0 -18
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.docset/Contents/Resources/docSet.dsidx.csv +0 -80
- data/spec/integration_specs/document_alamofire/after/docs/docsets/Alamofire.xml +0 -1
- data/spec/integration_specs/document_alamofire/after/docs/img/carat.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/img/dash.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/img/gh.png +0 -0
- data/spec/integration_specs/document_alamofire/after/docs/index.html +0 -756
- data/spec/integration_specs/document_alamofire/after/docs/js/jazzy.js +0 -21
- data/spec/integration_specs/document_alamofire/after/docs/js/jquery.min.js +0 -4
- data/spec/integration_specs/document_alamofire/after/docs/undocumented.txt +0 -18
- data/spec/integration_specs/document_alamofire/after/execution_output.txt +0 -5
- data/spec/integration_specs/misc_jazzy_features/after/docs/Classes.html +0 -333
- data/spec/integration_specs/misc_jazzy_features/after/docs/Classes/ImplicitlyInternalTopLevelClass.html +0 -149
- data/spec/integration_specs/misc_jazzy_features/after/docs/Enums.html +0 -171
- data/spec/integration_specs/misc_jazzy_features/after/docs/Enums/DocumentedEnum.html +0 -149
- data/spec/integration_specs/misc_jazzy_features/after/docs/Global Variables.html +0 -152
- data/spec/integration_specs/misc_jazzy_features/after/docs/css/highlight.css +0 -202
- data/spec/integration_specs/misc_jazzy_features/after/docs/css/jazzy.css +0 -708
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Info.plist +0 -20
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/Classes.html +0 -333
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/Classes/ImplicitlyInternalTopLevelClass.html +0 -149
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/DocumentedEnum.html +0 -149
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/Enums.html +0 -171
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/Enums/DocumentedEnum.html +0 -149
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/Global Variables.html +0 -152
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/ImplicitlyInternalTopLevelClass.html +0 -149
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/carat.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/css/highlight.css +0 -202
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/css/jazzy.css +0 -708
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/dash.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/gh.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/highlight.css +0 -202
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/img/carat.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/img/dash.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/img/gh.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/index.html +0 -112
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/jazzy.css +0 -708
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/jazzy.js +0 -21
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/jquery.min.js +0 -4
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/js/jazzy.js +0 -21
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/js/jquery.min.js +0 -4
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/Documents/undocumented.txt +0 -3
- data/spec/integration_specs/misc_jazzy_features/after/docs/docsets/MiscJazzyFeatures.docset/Contents/Resources/docSet.dsidx.csv +0 -17
- data/spec/integration_specs/misc_jazzy_features/after/docs/img/carat.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/img/dash.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/img/gh.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/after/docs/index.html +0 -112
- data/spec/integration_specs/misc_jazzy_features/after/docs/js/jazzy.js +0 -21
- data/spec/integration_specs/misc_jazzy_features/after/docs/js/jquery.min.js +0 -4
- data/spec/integration_specs/misc_jazzy_features/after/docs/undocumented.txt +0 -3
- data/spec/integration_specs/misc_jazzy_features/after/execution_output.txt +0 -5
- data/spec/integration_specs/misc_jazzy_features/before/MiscJazzyFeatures.xcodeproj/project.pbxproj +0 -293
- data/spec/integration_specs/misc_jazzy_features/before/MiscJazzyFeatures.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- data/spec/integration_specs/misc_jazzy_features/before/MiscJazzyFeatures/Classes.swift +0 -60
- data/spec/integration_specs/misc_jazzy_features/before/MiscJazzyFeatures/MiscJazzyFeatures.h +0 -10
- data/spec/integration_specs/misc_jazzy_features/before/docs/Classes.html +0 -317
- data/spec/integration_specs/misc_jazzy_features/before/docs/Classes/ImplicitlyInternalTopLevelClass.html +0 -138
- data/spec/integration_specs/misc_jazzy_features/before/docs/Enums.html +0 -155
- data/spec/integration_specs/misc_jazzy_features/before/docs/Enums/DocumentedEnum.html +0 -128
- data/spec/integration_specs/misc_jazzy_features/before/docs/Global Variables.html +0 -138
- data/spec/integration_specs/misc_jazzy_features/before/docs/css/jazzy.css +0 -609
- data/spec/integration_specs/misc_jazzy_features/before/docs/img/carat.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/before/docs/img/dash.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/before/docs/img/gh.png +0 -0
- data/spec/integration_specs/misc_jazzy_features/before/docs/index.html +0 -99
- data/spec/integration_specs/misc_jazzy_features/before/docs/js/jazzy.js +0 -15
- data/spec/integration_specs/misc_jazzy_features/before/docs/js/jquery.min.js +0 -4
Binary file
|
Binary file
|
@@ -1,202 +0,0 @@
|
|
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; }
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,756 +0,0 @@
|
|
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> (83% 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
|
-
<p id="header-links"><a href="dash-feed://http%3A%2F%2Fstatic%2Erealm%2Eio%2Fjazzy_demo%2FAlamofire%2Fdocsets%2FAlamofire%2Exml"><img id="header-icon" src="img/dash.png" height="16px" width="16px" />Install in Dash</a></p>
|
29
|
-
</div>
|
30
|
-
</header>
|
31
|
-
<section id="valence">
|
32
|
-
<div class="content-wrapper">
|
33
|
-
<p id="hierarchial_navigation">
|
34
|
-
<a href="index.html" id="design_resources_link">Alamofire Reference</a>
|
35
|
-
<img id="carat" src="img/carat.png" height="10px" width="6px" />
|
36
|
-
Alamofire Reference
|
37
|
-
</p>
|
38
|
-
</div>
|
39
|
-
</section>
|
40
|
-
<div class="content-wrapper">
|
41
|
-
<nav class="book-parts">
|
42
|
-
<ul class="nav-parts">
|
43
|
-
<li class="part-name tasks">
|
44
|
-
<a href="Classes.html">Classes</a>
|
45
|
-
<ul class="nav-chapters">
|
46
|
-
<li class="nav-chapter">
|
47
|
-
<a href="Classes/Manager.html">Manager</a>
|
48
|
-
</li>
|
49
|
-
<li class="nav-chapter">
|
50
|
-
<a href="Classes/Request.html">Request</a>
|
51
|
-
</li>
|
52
|
-
</ul>
|
53
|
-
</li>
|
54
|
-
<li class="part-name tasks">
|
55
|
-
<a href="Global Variables.html">Global Variables</a>
|
56
|
-
<ul class="nav-chapters">
|
57
|
-
<li class="nav-chapter">
|
58
|
-
<a href="Global Variables.html#/s:v9Alamofire20AlamofireErrorDomainSS">AlamofireErrorDomain</a>
|
59
|
-
</li>
|
60
|
-
</ul>
|
61
|
-
</li>
|
62
|
-
<li class="part-name tasks">
|
63
|
-
<a href="Enums.html">Enums</a>
|
64
|
-
<ul class="nav-chapters">
|
65
|
-
<li class="nav-chapter">
|
66
|
-
<a href="Enums.html#/s:O9Alamofire6Method">Method</a>
|
67
|
-
</li>
|
68
|
-
<li class="nav-chapter">
|
69
|
-
<a href="Enums/ParameterEncoding.html">ParameterEncoding</a>
|
70
|
-
</li>
|
71
|
-
</ul>
|
72
|
-
</li>
|
73
|
-
<li class="part-name tasks">
|
74
|
-
<a href="Extensions.html">Extensions</a>
|
75
|
-
<ul class="nav-chapters">
|
76
|
-
<li class="nav-chapter">
|
77
|
-
<a href="Extensions/Manager.html">Manager</a>
|
78
|
-
</li>
|
79
|
-
<li class="nav-chapter">
|
80
|
-
<a href="Extensions/Manager.html">Manager</a>
|
81
|
-
</li>
|
82
|
-
<li class="nav-chapter">
|
83
|
-
<a href="Extensions.html#/c:objc(cs)NSURLRequest">NSURLRequest</a>
|
84
|
-
</li>
|
85
|
-
<li class="nav-chapter">
|
86
|
-
<a href="Extensions.html#/c:objc(cs)NSURLRequest">NSURLRequest</a>
|
87
|
-
</li>
|
88
|
-
<li class="nav-chapter">
|
89
|
-
<a href="Extensions.html#/s:C9Alamofire7Request">Request</a>
|
90
|
-
</li>
|
91
|
-
<li class="nav-chapter">
|
92
|
-
<a href="Extensions/Request.html">Request</a>
|
93
|
-
</li>
|
94
|
-
<li class="nav-chapter">
|
95
|
-
<a href="Extensions/Request.html">Request</a>
|
96
|
-
</li>
|
97
|
-
<li class="nav-chapter">
|
98
|
-
<a href="Extensions/Request.html">Request</a>
|
99
|
-
</li>
|
100
|
-
<li class="nav-chapter">
|
101
|
-
<a href="Extensions/Request.html">Request</a>
|
102
|
-
</li>
|
103
|
-
<li class="nav-chapter">
|
104
|
-
<a href="Extensions/Request.html">Request</a>
|
105
|
-
</li>
|
106
|
-
<li class="nav-chapter">
|
107
|
-
<a href="Extensions/Request.html">Request</a>
|
108
|
-
</li>
|
109
|
-
<li class="nav-chapter">
|
110
|
-
<a href="Extensions/Request.html">Request</a>
|
111
|
-
</li>
|
112
|
-
<li class="nav-chapter">
|
113
|
-
<a href="Extensions.html#/s:SS">String</a>
|
114
|
-
</li>
|
115
|
-
</ul>
|
116
|
-
</li>
|
117
|
-
<li class="part-name tasks">
|
118
|
-
<a href="Functions.html">Functions</a>
|
119
|
-
<ul class="nav-chapters">
|
120
|
-
<li class="nav-chapter">
|
121
|
-
<a href="Functions.html#/s:F9Alamofire8downloadFTPS_21URLRequestConvertible_FTCSo5NSURLCSo17NSHTTPURLResponse_S1__CS_7Request">download(_:_:)</a>
|
122
|
-
</li>
|
123
|
-
<li class="nav-chapter">
|
124
|
-
<a href="Functions.html#/s:F9Alamofire8downloadFTOS_6MethodPS_20URLStringConvertible_FTCSo5NSURLCSo17NSHTTPURLResponse_S2__CS_7Request">download(_:_:_:)</a>
|
125
|
-
</li>
|
126
|
-
<li class="nav-chapter">
|
127
|
-
<a href="Functions.html#/s:F9Alamofire8downloadFT10resumeDataCSo6NSDataFTCSo5NSURLCSo17NSHTTPURLResponse_S1__CS_7Request">download(resumeData:_:)</a>
|
128
|
-
</li>
|
129
|
-
<li class="nav-chapter">
|
130
|
-
<a href="Functions.html#/s:F9Alamofire7requestFPS_21URLRequestConvertible_CS_7Request">request(_:)</a>
|
131
|
-
</li>
|
132
|
-
<li class="nav-chapter">
|
133
|
-
<a href="Functions.html#/s:F9Alamofire7requestFTOS_6MethodPS_20URLStringConvertible_10parametersGSqGVSs10DictionarySSPSs9AnyObject___8encodingOS_17ParameterEncoding_CS_7Request">request(_:_:parameters:encoding:)</a>
|
134
|
-
</li>
|
135
|
-
<li class="nav-chapter">
|
136
|
-
<a href="Functions.html#/s:F9Alamofire6uploadFTPS_21URLRequestConvertible_CSo6NSData_CS_7Request">upload(_:_:)</a>
|
137
|
-
</li>
|
138
|
-
<li class="nav-chapter">
|
139
|
-
<a href="Functions.html#/s:F9Alamofire6uploadFTPS_21URLRequestConvertible_CSo13NSInputStream_CS_7Request">upload(_:_:)</a>
|
140
|
-
</li>
|
141
|
-
<li class="nav-chapter">
|
142
|
-
<a href="Functions.html#/s:F9Alamofire6uploadFTPS_21URLRequestConvertible_CSo5NSURL_CS_7Request">upload(_:_:)</a>
|
143
|
-
</li>
|
144
|
-
<li class="nav-chapter">
|
145
|
-
<a href="Functions.html#/s:F9Alamofire6uploadFTOS_6MethodPS_20URLStringConvertible_CSo13NSInputStream_CS_7Request">upload(_:_:_:)</a>
|
146
|
-
</li>
|
147
|
-
<li class="nav-chapter">
|
148
|
-
<a href="Functions.html#/s:F9Alamofire6uploadFTOS_6MethodPS_20URLStringConvertible_CSo5NSURL_CS_7Request">upload(_:_:_:)</a>
|
149
|
-
</li>
|
150
|
-
<li class="nav-chapter">
|
151
|
-
<a href="Functions.html#/s:F9Alamofire6uploadFTOS_6MethodPS_20URLStringConvertible_CSo6NSData_CS_7Request">upload(_:_:_:)</a>
|
152
|
-
</li>
|
153
|
-
</ul>
|
154
|
-
</li>
|
155
|
-
<li class="part-name tasks">
|
156
|
-
<a href="Protocols.html">Protocols</a>
|
157
|
-
<ul class="nav-chapters">
|
158
|
-
<li class="nav-chapter">
|
159
|
-
<a href="Protocols/URLRequestConvertible.html">URLRequestConvertible</a>
|
160
|
-
</li>
|
161
|
-
<li class="nav-chapter">
|
162
|
-
<a href="Protocols/URLStringConvertible.html">URLStringConvertible</a>
|
163
|
-
</li>
|
164
|
-
</ul>
|
165
|
-
</li>
|
166
|
-
</ul>
|
167
|
-
</nav>
|
168
|
-
<div class="pixel-line"></div>
|
169
|
-
<div class="rubber-band-gap"></div>
|
170
|
-
<article class="chapter">
|
171
|
-
<a name="/"></a>
|
172
|
-
<h1 class="chapter-name">Alamofire</h1>
|
173
|
-
<section>
|
174
|
-
<section class="section">
|
175
|
-
<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>
|
176
|
-
|
177
|
-
<ul>
|
178
|
-
<li>[x] Chainable Request / Response methods</li>
|
179
|
-
<li>[x] URL / JSON / plist Parameter Encoding</li>
|
180
|
-
<li>[x] Upload File / Data / Stream</li>
|
181
|
-
<li>[x] Download using Request or Resume data</li>
|
182
|
-
<li>[x] Authentication with NSURLCredential</li>
|
183
|
-
<li>[x] HTTP Response Validation</li>
|
184
|
-
<li>[x] Progress Closure & NSProgress</li>
|
185
|
-
<li>[x] cURL Debug Output</li>
|
186
|
-
<li>[x] Comprehensive Unit Test Coverage</li>
|
187
|
-
<li>[x] Complete Documentation</li>
|
188
|
-
</ul>
|
189
|
-
<a href='#requirements' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='requirements'>Requirements</h2>
|
190
|
-
|
191
|
-
<ul>
|
192
|
-
<li>iOS 7.0+ / Mac OS X 10.9+</li>
|
193
|
-
<li>Xcode 6.1</li>
|
194
|
-
</ul>
|
195
|
-
<a href='#communication' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='communication'>Communication</h2>
|
196
|
-
|
197
|
-
<ul>
|
198
|
-
<li>If you <strong>need help</strong>, use <a href="http://stackoverflow.com/questions/tagged/alamofire">Stack Overflow</a>. (Tag ‘alamofire’)</li>
|
199
|
-
<li>If you’d like to <strong>ask a general question</strong>, use <a href="http://stackoverflow.com/questions/tagged/alamofire">Stack Overflow</a>.</li>
|
200
|
-
<li>If you <strong>found a bug</strong>, open an issue.</li>
|
201
|
-
<li>If you <strong>have a feature request</strong>, open an issue.</li>
|
202
|
-
<li>If you <strong>want to contribute</strong>, submit a pull request.</li>
|
203
|
-
</ul>
|
204
|
-
<a href='#installation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='installation'>Installation</h2>
|
205
|
-
|
206
|
-
<blockquote>
|
207
|
-
<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>
|
208
|
-
<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>
|
209
|
-
<ol>
|
210
|
-
<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>
|
211
|
-
<li>Open the <code>Alamofire</code> folder, and drag <code>Alamofire.xcodeproj</code> into the file navigator of your app project.</li>
|
212
|
-
<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>
|
213
|
-
<li>Ensure that the deployment target of Alamofire.framework matches that of the application target.</li>
|
214
|
-
<li>In the tab bar at the top of that window, open the <q>Build Phases</q> panel.</li>
|
215
|
-
<li>Expand the <q>Target Dependencies</q> group, and add <code>Alamofire.framework</code>.</li>
|
216
|
-
<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>
|
217
|
-
</ol>
|
218
|
-
|
219
|
-
<hr>
|
220
|
-
<a href='#usage' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='usage'>Usage</h2>
|
221
|
-
<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>
|
222
|
-
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Alamofire</span>
|
223
|
-
|
224
|
-
<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>
|
225
|
-
</code></pre>
|
226
|
-
<a href='#response_handling' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='response_handling'>Response Handling</h3>
|
227
|
-
<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>
|
228
|
-
<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>
|
229
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
|
230
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
|
231
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
|
232
|
-
<span class="p">}</span>
|
233
|
-
</code></pre>
|
234
|
-
|
235
|
-
<blockquote>
|
236
|
-
<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’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>
|
237
|
-
<a href='#response_serialization' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='response_serialization'>Response Serialization</h3>
|
238
|
-
<p class="para"><strong>Built-in Response Methods</strong></p>
|
239
|
-
<ul>
|
240
|
-
<li><code>response()</code></li>
|
241
|
-
<li><code>responseString(encoding: NSStringEncoding)</code></li>
|
242
|
-
<li><code>responseJSON(options: NSJSONReadingOptions)</code></li>
|
243
|
-
<li><code>responsePropertyList(options: NSPropertyListReadOptions)</code></li>
|
244
|
-
</ul>
|
245
|
-
<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>
|
246
|
-
<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>
|
247
|
-
<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>
|
248
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
|
249
|
-
<span class="p">}</span>
|
250
|
-
</code></pre>
|
251
|
-
<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>
|
252
|
-
<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>
|
253
|
-
<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>
|
254
|
-
<span class="nf">println</span><span class="p">(</span><span class="kt">JSON</span><span class="p">)</span>
|
255
|
-
<span class="p">}</span>
|
256
|
-
</code></pre>
|
257
|
-
<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>
|
258
|
-
<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>
|
259
|
-
<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>
|
260
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
|
261
|
-
<span class="p">}</span>
|
262
|
-
<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>
|
263
|
-
<span class="nf">println</span><span class="p">(</span><span class="kt">JSON</span><span class="p">)</span>
|
264
|
-
<span class="p">}</span>
|
265
|
-
</code></pre>
|
266
|
-
<a href='#http_methods' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='http_methods'>HTTP Methods</h3>
|
267
|
-
<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>
|
268
|
-
<span class="k">case</span> <span class="kt">OPTIONS</span> <span class="o">=</span> <span class="s">"OPTIONS"</span>
|
269
|
-
<span class="k">case</span> <span class="kt">GET</span> <span class="o">=</span> <span class="s">"GET"</span>
|
270
|
-
<span class="k">case</span> <span class="kt">HEAD</span> <span class="o">=</span> <span class="s">"HEAD"</span>
|
271
|
-
<span class="k">case</span> <span class="kt">POST</span> <span class="o">=</span> <span class="s">"POST"</span>
|
272
|
-
<span class="k">case</span> <span class="kt">PUT</span> <span class="o">=</span> <span class="s">"PUT"</span>
|
273
|
-
<span class="k">case</span> <span class="kt">PATCH</span> <span class="o">=</span> <span class="s">"PATCH"</span>
|
274
|
-
<span class="k">case</span> <span class="kt">DELETE</span> <span class="o">=</span> <span class="s">"DELETE"</span>
|
275
|
-
<span class="k">case</span> <span class="kt">TRACE</span> <span class="o">=</span> <span class="s">"TRACE"</span>
|
276
|
-
<span class="k">case</span> <span class="kt">CONNECT</span> <span class="o">=</span> <span class="s">"CONNECT"</span>
|
277
|
-
<span class="p">}</span>
|
278
|
-
</code></pre>
|
279
|
-
<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>
|
280
|
-
|
281
|
-
<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>
|
282
|
-
|
283
|
-
<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>
|
284
|
-
</code></pre>
|
285
|
-
<a href='#parameters' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='parameters'>Parameters</h3>
|
286
|
-
<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>
|
287
|
-
<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>
|
288
|
-
<span class="c1">// http://httpbin.org/get?foo=bar
|
289
|
-
</span></code></pre>
|
290
|
-
<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>
|
291
|
-
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">parameters</span> <span class="o">=</span> <span class="p">[</span>
|
292
|
-
<span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">,</span>
|
293
|
-
<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>
|
294
|
-
<span class="s">"qux"</span><span class="p">:</span> <span class="p">[</span>
|
295
|
-
<span class="s">"x"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
|
296
|
-
<span class="s">"y"</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
|
297
|
-
<span class="s">"z"</span><span class="p">:</span> <span class="mi">3</span>
|
298
|
-
<span class="p">]</span>
|
299
|
-
<span class="p">]</span>
|
300
|
-
|
301
|
-
<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>
|
302
|
-
<span class="c1">// HTTP body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3
|
303
|
-
</span></code></pre>
|
304
|
-
<a href='#parameter_encoding' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='parameter_encoding'>Parameter Encoding</h3>
|
305
|
-
<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>
|
306
|
-
<span class="k">case</span> <span class="kt">URL</span>
|
307
|
-
<span class="k">case</span> <span class="kt">JSON</span>
|
308
|
-
<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>
|
309
|
-
<span class="nv">options</span><span class="p">:</span> <span class="kt">NSPropertyListWriteOptions</span><span class="p">)</span>
|
310
|
-
|
311
|
-
<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>
|
312
|
-
<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>
|
313
|
-
<span class="p">(</span><span class="kt">NSURLRequest</span><span class="p">,</span> <span class="kt">NSError</span><span class="p">?)</span>
|
314
|
-
<span class="p">{</span> <span class="o">...</span> <span class="p">}</span>
|
315
|
-
<span class="p">}</span>
|
316
|
-
</code></pre>
|
317
|
-
|
318
|
-
<ul>
|
319
|
-
<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&foo[]=2</code>), and appending the key surrounded by square brackets for nested dictionary values (<code>foo[bar]=baz</code>).</em></li>
|
320
|
-
<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>
|
321
|
-
<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>
|
322
|
-
<li><code>Custom</code>: Uses the associated closure value to construct a new request given an existing request and parameters.</li>
|
323
|
-
</ul>
|
324
|
-
<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>
|
325
|
-
<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>
|
326
|
-
<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>
|
327
|
-
|
328
|
-
<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>
|
329
|
-
<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>
|
330
|
-
<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>
|
331
|
-
</code></pre>
|
332
|
-
<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>
|
333
|
-
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">parameters</span> <span class="o">=</span> <span class="p">[</span>
|
334
|
-
<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>
|
335
|
-
<span class="s">"bar"</span><span class="p">:</span> <span class="p">[</span>
|
336
|
-
<span class="s">"baz"</span><span class="p">:</span> <span class="s">"qux"</span>
|
337
|
-
<span class="p">]</span>
|
338
|
-
<span class="p">]</span>
|
339
|
-
|
340
|
-
<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>
|
341
|
-
<span class="c1">// HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}
|
342
|
-
</span></code></pre>
|
343
|
-
<a href='#caching' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='caching'>Caching</h3>
|
344
|
-
<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>
|
345
|
-
<p class="para"><strong>Supported Upload Types</strong></p>
|
346
|
-
<ul>
|
347
|
-
<li>File</li>
|
348
|
-
<li>Data</li>
|
349
|
-
<li>Stream</li>
|
350
|
-
</ul>
|
351
|
-
<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>
|
352
|
-
<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>
|
353
|
-
<span class="o">.</span><span class="kt">URLForResource</span><span class="p">(</span><span class="s">"Default"</span><span class="p">,</span>
|
354
|
-
<span class="nv">withExtension</span><span class="p">:</span> <span class="s">"png"</span><span class="p">)</span>
|
355
|
-
|
356
|
-
<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>
|
357
|
-
</code></pre>
|
358
|
-
<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>
|
359
|
-
<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>
|
360
|
-
<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>
|
361
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">totalBytesWritten</span><span class="p">)</span>
|
362
|
-
<span class="p">}</span>
|
363
|
-
<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>
|
364
|
-
<span class="nf">println</span><span class="p">(</span><span class="kt">JSON</span><span class="p">)</span>
|
365
|
-
<span class="p">}</span>
|
366
|
-
</code></pre>
|
367
|
-
<a href='#downloading' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='downloading'>Downloading</h3>
|
368
|
-
<p class="para"><strong>Supported Download Types</strong></p>
|
369
|
-
<ul>
|
370
|
-
<li>Request</li>
|
371
|
-
<li>Resume Data</li>
|
372
|
-
</ul>
|
373
|
-
<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>
|
374
|
-
<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>
|
375
|
-
<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>
|
376
|
-
<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>
|
377
|
-
<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>
|
378
|
-
<span class="k">as</span><span class="p">?</span> <span class="kt">NSURL</span> <span class="p">{</span>
|
379
|
-
<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>
|
380
|
-
|
381
|
-
<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>
|
382
|
-
<span class="p">}</span>
|
383
|
-
|
384
|
-
<span class="k">return</span> <span class="n">temporaryURL</span>
|
385
|
-
<span class="p">})</span>
|
386
|
-
</code></pre>
|
387
|
-
<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>
|
388
|
-
<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>
|
389
|
-
|
390
|
-
<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>
|
391
|
-
</code></pre>
|
392
|
-
<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>
|
393
|
-
<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>
|
394
|
-
<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>
|
395
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">totalBytesRead</span><span class="p">)</span>
|
396
|
-
<span class="p">}</span>
|
397
|
-
<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>
|
398
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
|
399
|
-
<span class="p">}</span>
|
400
|
-
</code></pre>
|
401
|
-
<a href='#authentication' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='authentication'>Authentication</h3>
|
402
|
-
<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>
|
403
|
-
<ul>
|
404
|
-
<li><a href="http://en.wikipedia.org/wiki/Basic_access_authentication">HTTP Basic</a></li>
|
405
|
-
<li><a href="http://en.wikipedia.org/wiki/Digest_access_authentication">HTTP Digest</a></li>
|
406
|
-
<li><a href="http://en.wikipedia.org/wiki/Kerberos_%28protocol%29">Kerberos</a></li>
|
407
|
-
<li><a href="http://en.wikipedia.org/wiki/NT_LAN_Manager">NTLM</a></li>
|
408
|
-
</ul>
|
409
|
-
<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>
|
410
|
-
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">user</span> <span class="o">=</span> <span class="s">"user"</span>
|
411
|
-
<span class="k">let</span> <span class="nv">password</span> <span class="o">=</span> <span class="s">"password"</span>
|
412
|
-
|
413
|
-
<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>
|
414
|
-
<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>
|
415
|
-
<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>
|
416
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
|
417
|
-
<span class="p">}</span>
|
418
|
-
</code></pre>
|
419
|
-
<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>
|
420
|
-
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">user</span> <span class="o">=</span> <span class="s">"user"</span>
|
421
|
-
<span class="k">let</span> <span class="nv">password</span> <span class="o">=</span> <span class="s">"password"</span>
|
422
|
-
|
423
|
-
<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>
|
424
|
-
|
425
|
-
<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>
|
426
|
-
<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>
|
427
|
-
<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>
|
428
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
|
429
|
-
<span class="p">}</span>
|
430
|
-
</code></pre>
|
431
|
-
<a href='#validation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='validation'>Validation</h3>
|
432
|
-
<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>
|
433
|
-
<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>
|
434
|
-
<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">..<</span><span class="mi">300</span><span class="p">)</span>
|
435
|
-
<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>
|
436
|
-
<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>
|
437
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
|
438
|
-
<span class="p">}</span>
|
439
|
-
</code></pre>
|
440
|
-
<a href='#automatic_validation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='automatic_validation'>Automatic Validation</h4>
|
441
|
-
<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>
|
442
|
-
<span class="o">.</span><span class="nf">validate</span><span class="p">()</span>
|
443
|
-
<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>
|
444
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
|
445
|
-
<span class="p">}</span>
|
446
|
-
</code></pre>
|
447
|
-
<a href='#printable' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='printable'>Printable</h3>
|
448
|
-
<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>
|
449
|
-
|
450
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
|
451
|
-
<span class="c1">// GET http://httpbin.org/ip (200)
|
452
|
-
</span></code></pre>
|
453
|
-
<a href='#debugprintable' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='debugprintable'>DebugPrintable</h3>
|
454
|
-
<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>
|
455
|
-
|
456
|
-
<span class="nf">debugPrintln</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
|
457
|
-
</code></pre>
|
458
|
-
<a href='#output_curl' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='output_curl'>Output (cURL)</h4>
|
459
|
-
<pre class="highlight plaintext"><code>$ curl -i \
|
460
|
-
-H "User-Agent: Alamofire" \
|
461
|
-
-H "Accept-Encoding: Accept-Encoding: gzip;q=1.0,compress;q=0.5" \
|
462
|
-
-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" \
|
463
|
-
"http://httpbin.org/get?foo=bar"
|
464
|
-
</code></pre>
|
465
|
-
|
466
|
-
<hr>
|
467
|
-
<a href='#advanced_usage' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='advanced_usage'>Advanced Usage</h2>
|
468
|
-
|
469
|
-
<blockquote>
|
470
|
-
<p class="para">Alamofire is built on <code>NSURLSession</code> and the Foundation URL Loading System. To make the most of
|
471
|
-
this framework, it is recommended that you be familiar with the concepts and capabilities of the underlying networking stack.</p></blockquote>
|
472
|
-
<p class="para"><strong>Recommended Reading</strong></p>
|
473
|
-
<ul>
|
474
|
-
<li><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html">URL Loading System Programming Guide</a></li>
|
475
|
-
<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>
|
476
|
-
<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>
|
477
|
-
<li><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLAuthenticationChallenge_Class/Reference/Reference.html">NSURLAuthenticationChallenge Class Reference</a></li>
|
478
|
-
</ul>
|
479
|
-
<a href='#manager' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='manager'>Manager</h3>
|
480
|
-
<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>
|
481
|
-
</code></pre>
|
482
|
-
<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>
|
483
|
-
<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>
|
484
|
-
</code></pre>
|
485
|
-
<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>
|
486
|
-
<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>
|
487
|
-
<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>
|
488
|
-
</code></pre>
|
489
|
-
<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>
|
490
|
-
<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>
|
491
|
-
<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>
|
492
|
-
</code></pre>
|
493
|
-
<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>
|
494
|
-
<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>
|
495
|
-
<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>
|
496
|
-
</code></pre>
|
497
|
-
<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>
|
498
|
-
<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>
|
499
|
-
<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>
|
500
|
-
|
501
|
-
<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>
|
502
|
-
<span class="n">configuration</span><span class="o">.</span><span class="kt">HTTPAdditionalHeaders</span> <span class="o">=</span> <span class="n">defaultHeaders</span>
|
503
|
-
|
504
|
-
<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>
|
505
|
-
</code></pre>
|
506
|
-
|
507
|
-
<blockquote>
|
508
|
-
<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>
|
509
|
-
<a href='#request' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='request'>Request</h3>
|
510
|
-
<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>
|
511
|
-
<ul>
|
512
|
-
<li><code>suspend()</code>: Suspends the underlying task and dispatch queue</li>
|
513
|
-
<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>
|
514
|
-
<li><code>cancel()</code>: Cancels the underlying task, producing an error that is passed to any registered response handlers.</li>
|
515
|
-
</ul>
|
516
|
-
<a href='#response_serialization' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='response_serialization'>Response Serialization</h3>
|
517
|
-
<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>
|
518
|
-
<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’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>
|
519
|
-
<span class="kd">class</span> <span class="kd">func</span> <span class="kt">XMLResponseSerializer</span><span class="p">()</span> <span class="o">-></span> <span class="kt">Serializer</span> <span class="p">{</span>
|
520
|
-
<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>
|
521
|
-
<span class="k">if</span> <span class="n">data</span> <span class="o">==</span> <span class="kc">nil</span> <span class="p">{</span>
|
522
|
-
<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>
|
523
|
-
<span class="p">}</span>
|
524
|
-
|
525
|
-
<span class="k">var</span> <span class="nv">XMLSerializationError</span><span class="p">:</span> <span class="kt">NSError</span><span class="p">?</span>
|
526
|
-
<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">&</span><span class="kt">XMLSerializationError</span><span class="p">)</span>
|
527
|
-
|
528
|
-
<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>
|
529
|
-
<span class="p">}</span>
|
530
|
-
<span class="p">}</span>
|
531
|
-
|
532
|
-
<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">-></span> <span class="kt">Void</span><span class="p">)</span> <span class="o">-></span> <span class="k">Self</span> <span class="p">{</span>
|
533
|
-
<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>
|
534
|
-
<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>
|
535
|
-
<span class="p">})</span>
|
536
|
-
<span class="p">}</span>
|
537
|
-
<span class="p">}</span>
|
538
|
-
</code></pre>
|
539
|
-
<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>
|
540
|
-
<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>
|
541
|
-
<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>
|
542
|
-
<span class="p">}</span>
|
543
|
-
|
544
|
-
<span class="kd">extension</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Request</span> <span class="p">{</span>
|
545
|
-
<span class="kd">public</span> <span class="kd">func</span> <span class="n">responseObject</span><span class="o"><</span><span class="kt">T</span><span class="p">:</span> <span class="kt">ResponseObjectSerializable</span><span class="o">></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">-></span> <span class="kt">Void</span><span class="p">)</span> <span class="o">-></span> <span class="k">Self</span> <span class="p">{</span>
|
546
|
-
<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>
|
547
|
-
<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>
|
548
|
-
<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>
|
549
|
-
<span class="k">if</span> <span class="n">response</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="o">&&</span> <span class="kt">JSON</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
|
550
|
-
<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>
|
551
|
-
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
552
|
-
<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>
|
553
|
-
<span class="p">}</span>
|
554
|
-
<span class="p">}</span>
|
555
|
-
|
556
|
-
<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>
|
557
|
-
<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>
|
558
|
-
<span class="p">})</span>
|
559
|
-
<span class="p">}</span>
|
560
|
-
<span class="p">}</span>
|
561
|
-
</code></pre>
|
562
|
-
<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>
|
563
|
-
<span class="k">let</span> <span class="nv">username</span><span class="p">:</span> <span class="kt">String</span>
|
564
|
-
<span class="k">let</span> <span class="nv">name</span><span class="p">:</span> <span class="kt">String</span>
|
565
|
-
|
566
|
-
<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>
|
567
|
-
<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>
|
568
|
-
<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>
|
569
|
-
<span class="p">}</span>
|
570
|
-
<span class="p">}</span>
|
571
|
-
</code></pre>
|
572
|
-
<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>
|
573
|
-
<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>
|
574
|
-
<span class="nf">println</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
|
575
|
-
<span class="p">}</span>
|
576
|
-
</code></pre>
|
577
|
-
<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>
|
578
|
-
<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">-></span> <span class="p">[</span><span class="k">Self</span><span class="p">]</span>
|
579
|
-
<span class="p">}</span>
|
580
|
-
|
581
|
-
<span class="kd">extension</span> <span class="kt">Alamofire</span><span class="o">.</span><span class="kt">Request</span> <span class="p">{</span>
|
582
|
-
<span class="kd">public</span> <span class="kd">func</span> <span class="n">responseCollection</span><span class="o"><</span><span class="kt">T</span><span class="p">:</span> <span class="kt">ResponseCollectionSerializable</span><span class="o">></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">-></span> <span class="kt">Void</span><span class="p">)</span> <span class="o">-></span> <span class="k">Self</span> <span class="p">{</span>
|
583
|
-
<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>
|
584
|
-
<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>
|
585
|
-
<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>
|
586
|
-
<span class="k">if</span> <span class="n">response</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="o">&&</span> <span class="kt">JSON</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
|
587
|
-
<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>
|
588
|
-
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
589
|
-
<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>
|
590
|
-
<span class="p">}</span>
|
591
|
-
<span class="p">}</span>
|
592
|
-
|
593
|
-
<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>
|
594
|
-
<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>
|
595
|
-
<span class="p">})</span>
|
596
|
-
<span class="p">}</span>
|
597
|
-
<span class="p">}</span>
|
598
|
-
</code></pre>
|
599
|
-
<a href='#urlstringconvertible' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='urlstringconvertible'>URLStringConvertible</h3>
|
600
|
-
<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>
|
601
|
-
<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>
|
602
|
-
<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>
|
603
|
-
|
604
|
-
<span class="k">case</span> <span class="kt">Root</span>
|
605
|
-
<span class="k">case</span> <span class="kt">User</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span>
|
606
|
-
<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>
|
607
|
-
|
608
|
-
<span class="c1">// MARK: URLStringConvertible
|
609
|
-
</span>
|
610
|
-
<span class="k">var</span> <span class="nv">URLString</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span>
|
611
|
-
<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>
|
612
|
-
<span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
|
613
|
-
<span class="k">case</span> <span class="o">.</span><span class="kt">Root</span><span class="p">:</span>
|
614
|
-
<span class="k">return</span> <span class="s">"/"</span>
|
615
|
-
<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>
|
616
|
-
<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>
|
617
|
-
<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>
|
618
|
-
<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>
|
619
|
-
<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>
|
620
|
-
<span class="p">}</span>
|
621
|
-
<span class="p">}()</span>
|
622
|
-
|
623
|
-
<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>
|
624
|
-
<span class="p">}</span>
|
625
|
-
<span class="p">}</span>
|
626
|
-
</code></pre>
|
627
|
-
<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>
|
628
|
-
</code></pre>
|
629
|
-
<a href='#urlrequestconvertible' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='urlrequestconvertible'>URLRequestConvertible</h3>
|
630
|
-
<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>
|
631
|
-
<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>
|
632
|
-
<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>
|
633
|
-
<span class="kd">static</span> <span class="k">let</span> <span class="nv">perPage</span> <span class="o">=</span> <span class="mi">50</span>
|
634
|
-
|
635
|
-
<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>
|
636
|
-
|
637
|
-
<span class="c1">// MARK: URLRequestConvertible
|
638
|
-
</span>
|
639
|
-
<span class="k">var</span> <span class="nv">URLRequest</span><span class="p">:</span> <span class="kt">NSURLRequest</span> <span class="p">{</span>
|
640
|
-
<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>
|
641
|
-
<span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
|
642
|
-
<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">></span> <span class="mi">1</span><span class="p">:</span>
|
643
|
-
<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>
|
644
|
-
<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>
|
645
|
-
<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>
|
646
|
-
<span class="p">}</span>
|
647
|
-
<span class="p">}()</span>
|
648
|
-
|
649
|
-
<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>
|
650
|
-
<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>
|
651
|
-
<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>
|
652
|
-
|
653
|
-
<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>
|
654
|
-
<span class="p">}</span>
|
655
|
-
<span class="p">}</span>
|
656
|
-
</code></pre>
|
657
|
-
<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&offset=50
|
658
|
-
</span></code></pre>
|
659
|
-
<a href='#crud_amp_authorization' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='crud_amp_authorization'>CRUD & Authorization</h4>
|
660
|
-
<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>
|
661
|
-
<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>
|
662
|
-
<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>
|
663
|
-
|
664
|
-
<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>
|
665
|
-
<span class="k">case</span> <span class="kt">ReadUser</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span>
|
666
|
-
<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>
|
667
|
-
<span class="k">case</span> <span class="kt">DestroyUser</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span>
|
668
|
-
|
669
|
-
<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>
|
670
|
-
<span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
|
671
|
-
<span class="k">case</span> <span class="o">.</span><span class="kt">CreateUser</span><span class="p">:</span>
|
672
|
-
<span class="k">return</span> <span class="o">.</span><span class="kt">POST</span>
|
673
|
-
<span class="k">case</span> <span class="o">.</span><span class="kt">ReadUser</span><span class="p">:</span>
|
674
|
-
<span class="k">return</span> <span class="o">.</span><span class="kt">GET</span>
|
675
|
-
<span class="k">case</span> <span class="o">.</span><span class="kt">UpdateUser</span><span class="p">:</span>
|
676
|
-
<span class="k">return</span> <span class="o">.</span><span class="kt">PUT</span>
|
677
|
-
<span class="k">case</span> <span class="o">.</span><span class="kt">DestroyUser</span><span class="p">:</span>
|
678
|
-
<span class="k">return</span> <span class="o">.</span><span class="kt">DELETE</span>
|
679
|
-
<span class="p">}</span>
|
680
|
-
<span class="p">}</span>
|
681
|
-
|
682
|
-
<span class="k">var</span> <span class="nv">path</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span>
|
683
|
-
<span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
|
684
|
-
<span class="k">case</span> <span class="o">.</span><span class="kt">CreateUser</span><span class="p">:</span>
|
685
|
-
<span class="k">return</span> <span class="s">"/users"</span>
|
686
|
-
<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>
|
687
|
-
<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>
|
688
|
-
<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>
|
689
|
-
<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>
|
690
|
-
<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>
|
691
|
-
<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>
|
692
|
-
<span class="p">}</span>
|
693
|
-
<span class="p">}</span>
|
694
|
-
|
695
|
-
<span class="c1">// MARK: URLRequestConvertible
|
696
|
-
</span>
|
697
|
-
<span class="k">var</span> <span class="nv">URLRequest</span><span class="p">:</span> <span class="kt">NSURLRequest</span> <span class="p">{</span>
|
698
|
-
<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>
|
699
|
-
<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>
|
700
|
-
<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>
|
701
|
-
|
702
|
-
<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>
|
703
|
-
<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>
|
704
|
-
<span class="p">}</span>
|
705
|
-
|
706
|
-
<span class="k">switch</span> <span class="k">self</span> <span class="p">{</span>
|
707
|
-
<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>
|
708
|
-
<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>
|
709
|
-
<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>
|
710
|
-
<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>
|
711
|
-
<span class="k">default</span><span class="p">:</span>
|
712
|
-
<span class="k">return</span> <span class="n">mutableURLRequest</span>
|
713
|
-
<span class="p">}</span>
|
714
|
-
<span class="p">}</span>
|
715
|
-
<span class="p">}</span>
|
716
|
-
</code></pre>
|
717
|
-
<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
|
718
|
-
</span></code></pre>
|
719
|
-
|
720
|
-
<hr>
|
721
|
-
<a href='#faq' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='faq'>FAQ</h2>
|
722
|
-
<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>
|
723
|
-
<p class="para">If you’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>
|
724
|
-
<blockquote>
|
725
|
-
<p class="para">It’s important to note that two libraries aren’t mutually exclusive: AFNetworking and Alamofire can peacefully exist in the same code base.</p></blockquote>
|
726
|
-
<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>
|
727
|
-
<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’t going anywhere.</p><p class="para">Use AFNetworking for any of the following:</p>
|
728
|
-
<ul>
|
729
|
-
<li>UIKit extensions, such as asynchronously loading images to <code>UIImageView</code></li>
|
730
|
-
<li>TLS verification, using <code>AFSecurityManager</code></li>
|
731
|
-
<li>Situations requiring <code>NSOperation</code> or <code>NSURLConnection</code>, using <code>AFURLConnectionOperation</code></li>
|
732
|
-
<li>Network reachability monitoring, using <code>AFNetworkReachabilityManager</code></li>
|
733
|
-
<li>Multipart HTTP request construction, using <code>AFHTTPRequestSerializer</code></li>
|
734
|
-
</ul>
|
735
|
-
<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’s the origin of the name Alamofire?</h3>
|
736
|
-
<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>
|
737
|
-
<hr>
|
738
|
-
<a href='#contact' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='contact'>Contact</h2>
|
739
|
-
<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>
|
740
|
-
|
741
|
-
<ul>
|
742
|
-
<li><a href="http://github.com/mattt">Mattt Thompson</a> (<a href="https://twitter.com/mattt">@mattt</a>)</li>
|
743
|
-
</ul>
|
744
|
-
<a href='#license' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='license'>License</h2>
|
745
|
-
<p class="para">Alamofire is released under the MIT license. See LICENSE for details.</p></div>
|
746
|
-
</section>
|
747
|
-
</section>
|
748
|
-
<section id="footer">
|
749
|
-
<p class="copyright">© YYYY <a class="link" href="https://nshipster.com/alamofire" target="_blank" rel="external">Alamofire</a>. All rights reserved. (Last updated: YYYY-MM-DD)</p>
|
750
|
-
<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>
|
751
|
-
</section>
|
752
|
-
</article>
|
753
|
-
</div>
|
754
|
-
</body>
|
755
|
-
</div>
|
756
|
-
</html>
|