├── data ├── stdlib │ ├── swift-master-8fb4dee.txt │ ├── swift-master-c6df1cd.txt │ └── swift-master-fcd5b92.txt ├── addenda │ ├── 1.2 │ │ ├── ArrayType.txt │ │ └── foundation.txt │ ├── 2.0 │ │ └── foundation.txt │ └── 3.0 │ │ └── foundation.txt └── svg-logo.txt ├── .gitattributes ├── .gitignore ├── templates ├── func.html ├── var-list.html ├── generic.html ├── param-short.html ├── index-global.html ├── param.html ├── alias-list.html ├── index-func.html ├── index-type.html ├── operator.html ├── index-operator.html ├── case.html ├── protocol-implementations.html ├── var.html ├── init.html ├── subscript-include.html ├── func-include.html ├── index-home.html ├── sidebar.html ├── type.html └── swifter-header.svg ├── swift2.0-config.json ├── swift1.2-config.json ├── swift2.1-config.json ├── swift2.2-config.json ├── swift3.0-config.json ├── swift3.1-config.json ├── swift4.2-config.json ├── swift-nightly-config.json ├── test ├── data │ ├── simple.txt │ └── ok.txt ├── test-simple-parse.js └── test-parse.js ├── package.json ├── lib ├── type-extensions.js ├── swiftdoc-grapher.js └── swiftdoc-builder.js ├── LICENSE ├── README.md └── index.js /data/stdlib/swift-master-8fb4dee.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/stdlib/swift-master-c6df1cd.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/stdlib/swift-master-fcd5b92.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | data/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | output-dir 3 | output 4 | 5 | preparse-data.txt 6 | -------------------------------------------------------------------------------- /templates/func.html: -------------------------------------------------------------------------------- 1 | {% for func in functions %}{% include 'func-include.html' %}{% endfor %} 2 | -------------------------------------------------------------------------------- /templates/var-list.html: -------------------------------------------------------------------------------- 1 | {% for var in vars %} 2 | {% include 'var.html' %} 3 | {% endfor %} 4 | -------------------------------------------------------------------------------- /templates/generic.html: -------------------------------------------------------------------------------- 1 | {% spaceless %} 2 | {% set line = func.generic.line | escape %} 3 | {% if line %} 4 | <{{ line }}> 5 | {% endif %} 6 | {% endspaceless %} -------------------------------------------------------------------------------- /templates/param-short.html: -------------------------------------------------------------------------------- 1 | {% spaceless %} 2 | {% if param.note is not empty %}{{ param.note }}{% elseif loop.index > 1 %}{{ param.name }}{% else %}_{% endif %}: 3 | {% endspaceless %} -------------------------------------------------------------------------------- /templates/index-global.html: -------------------------------------------------------------------------------- 1 | 4 | 5 |

Functions

6 | 7 | {% include 'index-func.html' %} -------------------------------------------------------------------------------- /swift2.0-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/v2.0", 3 | "url-prefix": "/v2.0/", 4 | "source-files": [ 5 | "data/stdlib/swiftlang-700.0.59.txt", 6 | "data/addenda/2.0/foundation.txt" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /swift1.2-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/v1.2", 3 | "url-prefix": "/v1.2/", 4 | "source-files": [ 5 | "data/stdlib/swiftlang-602.0.49.6.txt", 6 | "data/addenda/1.2/foundation.txt" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /swift2.1-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/v2.1", 3 | "url-prefix": "/v2.1/", 4 | "source-files": [ 5 | "data/stdlib/swiftlang-700.1.101.19.txt", 6 | "data/addenda/2.0/foundation.txt" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /swift2.2-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/v2.2", 3 | "url-prefix": "/v2.2/", 4 | "source-files": [ 5 | "data/stdlib/swiftlang-703.0.18.1.txt", 6 | "data/addenda/2.0/foundation.txt" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /templates/param.html: -------------------------------------------------------------------------------- 1 | {% spaceless %} 2 | {% set type = param.type | escape %} 3 | {% if param.note is not empty %}{{ param.note }} {% endif %}{{ param.name }}: {{ type }}{% if param.default %} = {{ param.default }}{% endif %} 4 | 5 | {% endspaceless %} -------------------------------------------------------------------------------- /swift3.0-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/v3.0", 3 | "url-prefix": "/v3.0/", 4 | "swift-api": "3.0", 5 | "source-files": [ 6 | "data/stdlib/swiftlang-800.0.63.txt", 7 | "data/addenda/3.0/foundation.txt" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /swift3.1-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/v3.1", 3 | "url-prefix": "/v3.1/", 4 | "swift-api": "3.1", 5 | "source-files": [ 6 | "data/stdlib/swiftlang-802.0.31.3.txt", 7 | "data/addenda/3.0/foundation.txt" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /swift4.2-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/v4.2", 3 | "url-prefix": "/v4.2/", 4 | "swift-api": "4.2", 5 | "source-files": [ 6 | "data/stdlib/swiftlang-1000.0.16.7.txt", 7 | "data/addenda/3.0/foundation.txt" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /swift-nightly-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "output-dir": "output-dir/nightly", 3 | "url-prefix": "/nightly/", 4 | "swift-api": "3.0", 5 | "source-files": [ 6 | "data/stdlib/swift-master-1466a5e.txt", 7 | "data/addenda/3.0/foundation.txt" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /templates/alias-list.html: -------------------------------------------------------------------------------- 1 | {% for alias in aliases %} 2 |
3 | typealias {{ alias.name | escape }}{% if alias.type %} = {{ alias.type | escape }}{% endif %} 4 | {% if alias.comment %} 5 |
6 | {{ alias.comment | rst }} 7 |
8 | {% endif %} 9 |
10 | {% endfor %} 11 | -------------------------------------------------------------------------------- /templates/index-func.html: -------------------------------------------------------------------------------- 1 | {% set groups = 2 %} 2 | {% set size = (functions|length + 1) // groups %} 3 |
4 | {% for i in 1..groups %} 5 |
6 | 11 |
12 | {% endfor %} 13 |
14 | -------------------------------------------------------------------------------- /templates/index-type.html: -------------------------------------------------------------------------------- 1 | {% set groups = 2 %} 2 | {% set size = (items|length + 1) // groups %} 3 |
4 | {% for i in 1..groups %} 5 |
6 | 11 |
12 | {% endfor %} 13 |
14 | -------------------------------------------------------------------------------- /templates/operator.html: -------------------------------------------------------------------------------- 1 | {{ operator.place }} operator {{ operator.name | escape }} { 2 | associativity {{ operator.associativity }} 3 | precedence {{ operator.precedence }} 4 | {% if operator.assignment %} assignment 5 | {% endif %} 6 | } 7 | 8 |

Declarations

9 | 10 | {% for func in operator.functions %} 11 | {% include 'func-include.html' %} 12 | {% endfor %} 13 | -------------------------------------------------------------------------------- /templates/index-operator.html: -------------------------------------------------------------------------------- 1 | {% set groups = 4 %} 2 | {% set size = (operators|length + 1) // groups %} 3 |
4 | {% for i in 1..groups %} 5 |
6 | 11 |
12 | {% endfor %} 13 |
14 | -------------------------------------------------------------------------------- /templates/case.html: -------------------------------------------------------------------------------- 1 |
2 | case {{ case.name }}{% if case.associated %}({{ case.associated }}){% endif %} 3 | {% if case.comment %} 4 |
5 | {{ case.comment | rst }} 6 | 7 |

Declaration

8 | {{ case.declaration | escape }} 9 |
10 | {% endif %} 11 |
12 | -------------------------------------------------------------------------------- /templates/protocol-implementations.html: -------------------------------------------------------------------------------- 1 | {% if imp.inits or imp.properties or imp.subscripts or imp.functions %} 2 | 3 | {% set urlprefix = imp.urlprefix %} 4 | 5 | {% if imp.conforming != '*' %} 6 |

Where {{ imp.conforming }}

7 | {% endif %} 8 | 9 | {% for init in imp.inits %} 10 | {% include 'init.html' %} 11 | {% endfor %} 12 | 13 | {% for var in imp.properties %} 14 | {% include 'var.html' %} 15 | {% endfor %} 16 | 17 | {% for sub in imp.subscripts %} 18 | {% include 'subscript-include.html' %} 19 | {% endfor %} 20 | 21 | {% for func in imp.functions %} 22 | {% include 'func-include.html' %} 23 | {% endfor %} 24 | 25 | {% endif %} 26 | -------------------------------------------------------------------------------- /data/addenda/1.2/ArrayType.txt: -------------------------------------------------------------------------------- 1 | 2 | /// This protocol is an implementation detail of `Array` and `Slice`. It is *internal* to the Swift standard library and is included here only to link `Array` and `Slice` to other protocols. 3 | protocol _ArrayType : CollectionType { 4 | } 5 | 6 | /// This protocol is an implementation detail of `Array` and `Slice`. It is *internal* to the Swift standard library and is included here only to link `Array` and `Slice` to other protocols. 7 | protocol ArrayType : _ArrayType, RangeReplaceableCollectionType, MutableSliceable, ArrayLiteralConvertible { 8 | } 9 | 10 | extension ContiguousArray : ArrayType { 11 | } 12 | 13 | extension Slice : ArrayType { 14 | } 15 | 16 | extension Array : ArrayType { 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/data/simple.txt: -------------------------------------------------------------------------------- 1 | precedencegroup AdditionPrecedence { 2 | associativity: left 3 | higherThan: RangeFormationPrecedence 4 | } 5 | 6 | infix operator + : AdditionPrecedence 7 | infix operator - : AdditionPrecedence 8 | 9 | protocol FixedWidthInteger { 10 | static func + (lhs: Int, rhs: Int) -> Int 11 | 12 | var bitWidth: Int { get } 13 | } 14 | 15 | struct Int : FixedWidthInteger { 16 | static func + (lhs: Int, rhs: Int) -> Int 17 | static func - (lhs: Int, rhs: Int) -> Int 18 | 19 | init() 20 | init(bitPattern: UInt) 21 | init(_ value: Int8) 22 | } 23 | 24 | public typealias UnsafeBufferPointerIterator = UnsafeBufferPointer.Iterator 25 | 26 | public struct UnsafeMutableBufferPointer { 27 | } 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swiftdoc-parser", 3 | "version": "0.1.0", 4 | "description": "A parser for Swift source files.", 5 | "main": "lib/index.js", 6 | "author": { 7 | "name": "Nate Cook", 8 | "email": "nate@natecook.com" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/SwiftDocOrg/swiftdoc-parser.git" 13 | }, 14 | "license": "MIT", 15 | "devDependencies": { 16 | "chai": "*", 17 | "mocha": "*" 18 | }, 19 | "dependencies": { 20 | "async": "^0.9.0", 21 | "bluebird": "^2.3.11", 22 | "execsyncs": "^0.1.1", 23 | "markdown": "^0.5.0", 24 | "mkdirp": "^0.5.0", 25 | "natural-compare-lite": "^1.4.0", 26 | "node-sass": "1.2.2", 27 | "pcre": "0.0.6", 28 | "twig": "^0.7.2", 29 | "wrench": "^1.5.8", 30 | "yargs": "^1.3.3" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /templates/var.html: -------------------------------------------------------------------------------- 1 |
2 | {{ var.uniqueSignature | escape }}{% if var.defaultImplementation == false %} Required{% endif %} 3 |
4 | {{ var.comment | rst }} 5 | 6 |

Declaration

7 | {{ var.declaration | escape }} 8 | 9 | {% if var.implementationSource %} 10 |

Declared In

11 | {% for source in var.implementationSource %} 12 | {% if loop.index != 1 %},{% endif %} 13 | {{ source }} 14 | {% endfor %} 15 | {% endif %} 16 |
17 |
18 | -------------------------------------------------------------------------------- /lib/type-extensions.js: -------------------------------------------------------------------------------- 1 | 2 | // get substring of string, using start and end indices from a two-element array parameter 3 | // useful for getting the matched substring from PCRE match result 4 | String.prototype.ss = function (indices) { 5 | return this.substring(indices[0], indices[1]); 6 | }; 7 | 8 | // get urlified version of string 9 | String.prototype.urlify = function () { 10 | return this.toLowerCase().replace(/[^a-z0-9:]+/g, '-').replace(/-$/, '').replace(/-?:/g, '_'); 11 | }; 12 | 13 | // returns a new array with only unique elements of the array 14 | Array.prototype.unique = function() { 15 | return this.reduce(function(p, c) { 16 | if (p.indexOf(c) < 0) p.push(c); 17 | return p; 18 | }, []); 19 | } 20 | 21 | // returns a new array with the elements of `arr` appended to the array 22 | Array.prototype.extend = function(arr) { 23 | this.push.apply(this, arr); 24 | return this; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /templates/init.html: -------------------------------------------------------------------------------- 1 |
2 | {{ init.uniqueSignature | escape | addSoftBreaks }}{% if init.defaultImplementation == false %} Required{% endif %} 3 |
4 | {{ init.comment | rst }} 5 | 6 |

Declaration

7 | {{ init.declaration | escape }} 8 | 9 | {% if init.implementationSource %} 10 |

Declared In

11 | {% for source in init.implementationSource %} 12 | {% if loop.index != 1 %},{% endif %} 13 | {{ source }} 14 | {% endfor %} 15 | {% endif %} 16 |
17 |
18 | -------------------------------------------------------------------------------- /templates/subscript-include.html: -------------------------------------------------------------------------------- 1 |
2 | {{ sub.uniqueSignature | escape }}{% if sub.defaultImplementation == false %} Required{% endif %} 3 | 4 |
5 | {{ sub.comment | rst }} 6 | 7 |

Declaration

8 | {{ sub.declaration | escape }} 9 | 10 | {% if sub.implementationSource %} 11 |

Declared In

12 | {% for source in sub.implementationSource %}{% if loop.index != 1 %},{% endif %} 13 | {{ source }}{% endfor %} 14 | {% endif %} 15 | 16 |
17 |
18 | -------------------------------------------------------------------------------- /templates/func-include.html: -------------------------------------------------------------------------------- 1 |
2 | {{ func.attr | withSpaceAfter }}{{ func.note | withSpaceAfter }}{{ func.place | withSpaceAfter }}func {{ func.uniqueSignature | escape | addSoftBreaks }} 3 | {% if func.defaultImplementation == false %} Required{% endif %} 4 | 5 |
6 | {{ func.comment | rst }} 7 | 8 |

Declaration

9 | {{ func.declaration | escape }} 10 | 11 | {% if func.implementationSource %} 12 |

Declared In

13 | {% for source in func.implementationSource %}{% if loop.index != 1 %},{% endif %} 14 | {{ source }}{% endfor %} 15 | {% endif %} 16 | 17 |
18 |
19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Nate Cook 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /test/test-simple-parse.js: -------------------------------------------------------------------------------- 1 | // includes 2 | var fs = require('fs'), 3 | expect = require('chai').expect, 4 | parser = require('../lib/swiftdoc-parser'); 5 | 6 | var dataFilename = 'test/data/simple.txt'; 7 | var data = fs.readFileSync(dataFilename, 'utf8'); 8 | var parsedData = parser.parse(data, null); 9 | parsedData = parser.finalize(parsedData); 10 | 11 | Array.prototype.firstElementNamed = function(name) { 12 | var result = this.filter(function(e) { return e.name == name }); 13 | return result.length == 0 ? null : result[0]; 14 | } 15 | 16 | describe('Parser', function() { 17 | describe('operators', function() { 18 | 19 | var plus = parsedData.operators[0]; 20 | 21 | it('count', function() { 22 | expect(parsedData.operators.length).to.equal(2); 23 | }); 24 | 25 | it('+ functions', function() { 26 | expect(plus.functions.length).to.equal(1); 27 | }); 28 | 29 | }); 30 | 31 | describe('types + protocols', function() { 32 | 33 | it('count', function() { 34 | // Int, FixedWidthInteger, UnsafeMutableBufferPointer 35 | expect(Object.keys(parsedData.types).length).to.equal(3); 36 | }); 37 | 38 | describe('`Int`', function() { 39 | 40 | var intData = parsedData.types['Int']; 41 | 42 | it('type', function() { 43 | expect(intData.kind).to.equal('struct'); 44 | }); 45 | 46 | it('init count', function() { 47 | expect(intData.inits.length).to.equal(3); 48 | }); 49 | }); 50 | }); 51 | 52 | }); 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swiftdoc-parser 2 | 3 | > This project is no longer maintained. 4 | > We're now using [swift-doc](https://github.com/SwiftDocOrg/swift-doc) to generate the SwiftDoc.org website. 5 | 6 | --- 7 | 8 | ## Installation 9 | 10 | These utilities are built on [Node.js](http://nodejs.org) and use [Graphviz](http://www.graphviz.org) for creating inheritance graphs. To install and run the utilities with these prerequisites: 11 | 12 | 1. Clone or download the project. 13 | 2. Install dependencies with `npm install`. 14 | 3. Use the parser to convert a Swift header to JSON with `./index.js --json-only `. 15 | 16 | **Other options:** 17 | 18 | ``` 19 | $ ./index.js --help 20 | Usage: node ./index.js [options] [file names...] 21 | 22 | Options: 23 | --json-only Output parsed headers as JSON only 24 | --config Location of a configuration file 25 | --output-dir Output directory [default: "./output"] 26 | --url-prefix URL prefix for generated links [default: "/"] 27 | ``` 28 | 29 | ## Contributions 30 | 31 | Issues and pull requests should be filed in this repository for problems relating to: 32 | 33 | - incorrect or missing declarations 34 | - truncated or missing comments 35 | - errors in hierarchy graphs 36 | 37 | For errors in the SwiftDoc.org site itself, see [the site's repository](http://github.com/SwiftDocOrg/SwiftDoc.org) instead. 38 | 39 | ## Contact 40 | 41 | Follow [@SwiftDocOrg](http://twitter.com/SwiftDocOrg) on Twitter. 42 | 43 | 44 | ## License 45 | 46 | All code is available under the MIT License. Autogenerated documentation is © 2015 Apple, Inc. All other content is released under the [Creative Commons BY-NC License](http://creativecommons.org/licenses/by-nc/4.0/). 47 | -------------------------------------------------------------------------------- /templates/index-home.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 |
7 |

Types

8 | 9 | {% include 'index-type.html' with { items: types, path : 'type' } %} 10 |
11 | 12 |
13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 |
21 | 22 |
23 |

Protocols

24 | 25 | {% include 'index-type.html' with { items : protocols, path : 'protocol' } %} 26 |
27 | 28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |
37 | 38 |
39 |

Operators

40 | 41 | {% include 'index-operator.html' %} 42 |
43 | 44 |
45 |
46 |
47 |
48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 |

Globals

56 | 57 | {% include 'index-global.html' %} 58 |
59 | 60 |
61 |
62 |
63 |
64 | -------------------------------------------------------------------------------- /templates/sidebar.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 |
5 |

6 | 7 | Types 8 | 9 |

10 |
11 |
12 |
13 | {% for item in items.type %} 14 | {{ item.name }} 15 | {% endfor %} 16 |
17 |
18 |
19 | 20 |
21 |
22 |

23 | 24 | Protocols 25 | 26 |

27 |
28 |
29 |
30 | {% for item in items.protocol %} 31 | {{ item.name }} 32 | {% endfor %} 33 |
34 |
35 |
36 | 37 |
38 |
39 |

40 | 41 | Operators 42 | 43 |

44 |
45 |
46 |
47 | {% for item in items.operator %} 48 | {{ item.name }} 49 | {% endfor %} 50 |
51 |
52 |
53 | 54 |
55 |
56 |

57 | 58 | Globals 59 | 60 |

61 |
62 |
63 |
64 | Variables 65 | Type Aliases 66 | Functions 67 | {% for item in functions %} 68 | {{ item }} 69 | {% endfor %} 70 |
71 |
72 |
73 |
74 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // includes 4 | var fs = require('fs'), 5 | parser = require('./lib/swiftdoc-parser'), 6 | builder = require('./lib/swiftdoc-builder'), 7 | execsyncs = require("execsyncs"), 8 | path = require('path'); 9 | 10 | var appRoot = path.join(__dirname, './'); 11 | 12 | // command-line options 13 | var yargs = require('yargs') 14 | .usage('Usage: $0 [options] [file names...]') 15 | .help('help') 16 | .alias('?', 'help') 17 | .alias('h', 'help') 18 | .options('json-only', { 19 | type: 'boolean', 20 | describe: 'Output parsed headers as JSON only', 21 | }) 22 | .options('skip-graphs', { 23 | type: 'boolean', 24 | describe: 'Suppress graph generation', 25 | }) 26 | .options('config', { 27 | type: 'string', 28 | describe: 'Location of a configuration file', 29 | }) 30 | .options('output-dir', { 31 | type: 'string', 32 | describe: 'Output directory', 33 | default : './output', 34 | }) 35 | .options('url-prefix', { 36 | type: 'string', 37 | describe: 'URL prefix for generated links', 38 | default : '/', 39 | }), 40 | argv = yargs.argv; 41 | 42 | // read config file if one was given 43 | var config = { }; 44 | if (argv['config']) { 45 | config = JSON.parse(fs.readFileSync(argv.config)); 46 | } 47 | 48 | // find list of source files either in config file or as command line params 49 | var sources = config['source-files'] || argv._ || []; 50 | if (sources.length == 0) { 51 | console.log('No input files given!\nPlease list input files in a configuration file or on the command line.\n'); 52 | console.log(yargs.help()); 53 | return; 54 | } 55 | 56 | // toggle Swift 3 API parsing 57 | if (config['swift-api'] == '3.0') { 58 | parser.useSwift3APIs(); 59 | } 60 | 61 | // parse each source file, building up a parsed data object 62 | var parsedData = sources.reduce(function(previous, current) { 63 | var data = fs.readFileSync(appRoot + current, 'utf8'); 64 | return parser.parse(data, previous); 65 | }, null); 66 | 67 | // finalize the parsing; this hoists nested types up to the top level and builds reverse-inheritance 68 | parsedData = parser.finalize(parsedData); 69 | 70 | // output JSON blob and stop if that's the request 71 | if (argv['json-only']) { 72 | console.log(JSON.stringify(parsedData, null, 4)); 73 | return; 74 | } 75 | 76 | // set output-related configuration items 77 | builder.setOutputDir(config['output-dir'] || argv['output-dir']); 78 | builder.setURLPrefix(config['url-prefix'] || argv['url-prefix']); 79 | if (argv['skip-graphs']) { 80 | builder.setOutputGraphs(false); 81 | } 82 | 83 | // build output and notify 84 | builder.build(parsedData) 85 | execsyncs('osascript -e \'display notification "Finished build!" with title "swiftdoc-parser"\''); 86 | 87 | -------------------------------------------------------------------------------- /templates/type.html: -------------------------------------------------------------------------------- 1 |
{{ type.kind }} {{ type.name }}{% include 'generic.html' with { func: type } only %}
2 | 3 | {% if type.comment is not empty %} 4 |
5 | {{ type.comment | rst }} 6 |
7 | {% endif %} 8 | 9 | 10 | {% if type.inherits is not empty or hasHierarchy %} 11 | 12 | 13 | 21 | 22 | {% endif %} 23 | 24 | {% if type.aliases is not empty %} 25 | 26 | 27 | 40 | 41 | {% endif %} 42 | 43 | {% if type.types is not empty %} 44 | 45 | 46 | 47 | 48 | {% endif %} 49 | 50 | 51 | 52 | 53 | 54 | 55 |
Inheritance 14 | {% if type.allInherits is not empty %} 15 | {% for inh in type.allInherits %}{{ inh }}{% if true != loop.last %}, {% endif %}{% endfor %} 16 | {% endif %} 17 | {% if hasHierarchy %} 18 | View Protocol Hierarchy → 19 | {% endif %} 20 |
Associated Types 28 | 29 | {% for alias in type.aliases %} 30 |
31 | {{ alias.name | escape }}{% if alias.proto %} : {{ alias.proto | escape }}{% endif %}{% if alias.type %} = {{ alias.type | escape }}{% endif %} 32 | {% if alias.comment %} 33 |
34 | {{ alias.comment | rst }} 35 |
36 | {% endif %} 37 |
38 | {% endfor %} 39 |
Nested Types{% for nested in type.types %}{{ nested }}{% if true != loop.last %}, {% endif %}{% endfor %}
Importimport Swift
56 | 57 | {% if type.cases is not empty %} 58 |

Cases

59 | {% for case in type.cases %} 60 | {% include 'case.html' %} 61 | {% endfor %} 62 | {% endif %} 63 | 64 | {% if type.inits is not empty %} 65 |

Initializers

66 | {% for init in type.inits %} 67 | {% include 'init.html' %} 68 | {% endfor %} 69 | {% endif %} 70 | 71 | {% if type.properties | static is not empty %} 72 |

Static Variables

73 | {% for var in type.properties | static %} 74 | {% include 'var.html' %} 75 | {% endfor %} 76 | {% endif %} 77 | 78 | {% if type.properties | instance is not empty %} 79 |

Instance Variables

80 | {% for var in type.properties | instance %} 81 | {% include 'var.html' %} 82 | {% endfor %} 83 | {% endif %} 84 | 85 | {% if type.subscripts is not empty %} 86 |

Subscripts

87 | {% for sub in type.subscripts %} 88 | {% include 'subscript-include.html' %} 89 | {% endfor %} 90 | {% endif %} 91 | 92 | {% if type.functions | static is not empty %} 93 |

Static Methods

94 | {% for func in type.functions | static %} 95 | {% include 'func-include.html' %} 96 | {% endfor %} 97 | {% endif %} 98 | 99 | {% if type.functions | instance is not empty %} 100 |

Instance Methods

101 | {% for func in type.functions | instance %} 102 | {% include 'func-include.html' %} 103 | {% endfor %} 104 | {% endif %} 105 | 106 | {% if type.operators is not empty %} 107 |

Operators

108 | {% for op in type.operators %} 109 | {% for func in op.declarations %} 110 | {% include 'func-include.html' %} 111 | {% endfor %} 112 | {% endfor %} 113 | {% endif %} 114 | 115 | {% if type.imp is not empty %} 116 | {% if type.kind == 'protocol' %} 117 |

Default Implementations

118 | {% else %} 119 |

Conditionally Inherited Items

120 | 121 |

The initializers, methods, and properties listed below may be available on this type under certain conditions (such as methods that are available on Array when its elements are Equatable) or may not ever be available if that determination is beyond SwiftDoc.org's capabilities. Please open an issue on GitHub if you see something out of place!

122 | {% endif %} 123 | 124 | {% include 'protocol-implementations.html' with { 'imp': type.imp["*"] } %} 125 | 126 | {% for imp_key in type.imp|keys|sort %} 127 | {% set imp = type.imp[imp_key] %} 128 | 129 | {% if imp.conforming != '*' %} 130 | {% include 'protocol-implementations.html' %} 131 | {% endif %} 132 | 133 | {% endfor %} 134 | 135 | {% endif %} 136 | -------------------------------------------------------------------------------- /test/test-parse.js: -------------------------------------------------------------------------------- 1 | // includes 2 | var fs = require('fs'), 3 | expect = require('chai').expect, 4 | parser = require('../lib/swiftdoc-parser'); 5 | 6 | // 'data/swift-lang-6.2b1.txt' 7 | var dataFilename = 'test/data/ok.txt'; 8 | var data = fs.readFileSync(dataFilename, 'utf8'); 9 | var parsedData = parser.parse(data, null); 10 | parsedData = parser.finalize(parsedData); 11 | 12 | Array.prototype.firstElementNamed = function(name) { 13 | var result = this.filter(function(e) { return e.name == name }); 14 | return result.length == 0 ? null : result[0]; 15 | } 16 | 17 | describe('Parser', function() { 18 | describe('operators', function() { 19 | 20 | var plus = parsedData.operators[0]; 21 | var equality = parsedData.operators[1]; 22 | var increment = parsedData.operators[2]; 23 | 24 | it('count', function() { 25 | expect(parsedData.operators.length).to.equal(3); 26 | }); 27 | 28 | it('+ functions', function() { 29 | expect(plus.functions.length).to.equal(4); 30 | }); 31 | 32 | it('names', function() { 33 | expect(plus.name).to.equal('+'); 34 | expect(increment.name).to.equal('prefix ++'); 35 | expect(equality.name).to.equal('=='); 36 | }); 37 | 38 | }); 39 | 40 | describe('type aliases', function() { 41 | 42 | it('count', function() { 43 | expect(parsedData.aliases.length).to.equal(7); 44 | }); 45 | 46 | it('typing', function() { 47 | expect(parsedData.aliases.firstElementNamed('CLong').type).to.equal('Int'); 48 | }); 49 | 50 | }); 51 | 52 | describe('properties', function() { 53 | 54 | it('count', function() { 55 | expect(parsedData.properties.length).to.equal(1); 56 | }); 57 | 58 | }); 59 | 60 | describe('functions', function() { 61 | 62 | it('count', function() { 63 | expect(parsedData.functions.length).to.equal(11); 64 | }); 65 | 66 | var partitionFunction = parsedData.functions.firstElementNamed('partition'); 67 | it('`partition` parameters', function() { 68 | expect(partitionFunction).to.exist; 69 | 70 | expect(partitionFunction.params.length).to.equal(3); 71 | 72 | expect(partitionFunction.params[2].name).to.equal('isOrderedBefore'); 73 | expect(partitionFunction.params[2].types).to.contain('Bool'); 74 | expect(partitionFunction.params[2].types).to.contain('Element'); 75 | expect(partitionFunction.params[2].types).to.contain('Generator'); 76 | }); 77 | 78 | var withUnsafeFunction = parsedData.functions.firstElementNamed('withUnsafeMutablePointers'); 79 | it('`withUnsafeMutablePointers` function', function() { 80 | expect(withUnsafeFunction).to.exist; 81 | 82 | expect(withUnsafeFunction.generic.line).to.equal('A0, A1, A2, Result'); 83 | expect(withUnsafeFunction.params.length).to.equal(4); 84 | expect(withUnsafeFunction.params[3].type).to.equal('(UnsafeMutablePointer, UnsafeMutablePointer, UnsafeMutablePointer) -> Result'); 85 | }); 86 | }); 87 | 88 | describe('types + protocols', function() { 89 | 90 | it('count', function() { 91 | expect(Object.keys(parsedData.types).length).to.equal(42); 92 | }); 93 | 94 | describe('`Array`', function() { 95 | 96 | var arrayData = parsedData.types['Array']; 97 | 98 | it('type', function() { 99 | expect(arrayData.kind).to.equal('struct'); 100 | }); 101 | 102 | it('init count', function() { 103 | expect(arrayData.inits.length).to.equal(5); 104 | }); 105 | 106 | it('property count', function() { 107 | expect(arrayData.properties.length).to.equal(7); 108 | }); 109 | 110 | it('function count', function() { 111 | expect(arrayData.functions.length).to.equal(15); 112 | }); 113 | 114 | it('subscript count', function() { 115 | expect(arrayData.subscripts.length).to.equal(2); 116 | }); 117 | 118 | it('alias count', function() { 119 | expect(arrayData.aliases.length).to.equal(2); 120 | }); 121 | 122 | it('inheritance', function() { 123 | expect(arrayData.inherits).to.contain('ArrayLiteralConvertible'); 124 | expect(arrayData.inherits).to.contain('MutableCollectionType'); 125 | expect(arrayData.inherits).to.contain('Sliceable'); 126 | }); 127 | 128 | it('comments', function() { 129 | expect(arrayData.comment).to.contain('is deferred until the\nfirst element access'); 130 | expect(arrayData.comment).to.contain(' var b = a'); 131 | }); 132 | }); 133 | 134 | describe('`_CollectionType`', function() { 135 | 136 | var collectionTypeData = parsedData.types['_CollectionType']; 137 | 138 | it('type', function() { 139 | expect(collectionTypeData.kind).to.equal('protocol'); 140 | }); 141 | 142 | it('init count', function() { 143 | expect(collectionTypeData.inits.length).to.equal(0); 144 | }); 145 | 146 | it('property count', function() { 147 | expect(collectionTypeData.properties.length).to.equal(2); 148 | }); 149 | 150 | it('function count', function() { 151 | expect(collectionTypeData.functions.length).to.equal(0); 152 | }); 153 | 154 | it('subscript count', function() { 155 | expect(collectionTypeData.subscripts.length).to.equal(1); 156 | }); 157 | 158 | it('alias count', function() { 159 | expect(collectionTypeData.aliases.length).to.equal(2); 160 | }); 161 | 162 | it('inheritance', function() { 163 | expect(collectionTypeData.inherits).to.contain('_SequenceType'); 164 | expect(collectionTypeData.inherited).to.contain('CollectionType'); 165 | }); 166 | 167 | }); 168 | 169 | describe('`Range`', function() { 170 | var rangeData = parsedData.types['Range']; 171 | 172 | it('type', function() { 173 | expect(rangeData.kind).to.equal('struct'); 174 | }); 175 | 176 | it('property count', function() { 177 | expect(rangeData.properties.length).to.equal(5); 178 | }); 179 | 180 | it('property mutability', function() { 181 | expect(rangeData.properties.firstElementNamed('isEmpty').readonly).to.equal(true); 182 | expect(rangeData.properties.firstElementNamed('startIndex').readonly).to.equal(false); 183 | }); 184 | }); 185 | 186 | }); 187 | }); 188 | -------------------------------------------------------------------------------- /lib/swiftdoc-grapher.js: -------------------------------------------------------------------------------- 1 | require('./type-extensions'); 2 | 3 | var DEBUG = false; 4 | 5 | // name to show in the dot graph 6 | // include generic type: Array 7 | function dotNameForType(type, currentTypeName) { 8 | if (currentTypeName && (currentTypeName != type.name)) { 9 | return type.name; 10 | } 11 | return type.name + (!((type.generic) && (type.generic.line)) ? '' : '<' + type.generic.line + '>'); 12 | } 13 | 14 | function dotPrefix(title) { 15 | return 'strict digraph "' + title + ' - SwiftDoc.org" {\n\ 16 | pad="0.1,0.8"\n\ 17 | node [shape=box, style="filled,rounded", color="#999999", fillcolor="#999999", fontcolor=white, fontname=Helvetica, fontnames="Helvetica,sansserif", fontsize=12, margin="0.07,0.05", height="0.3"]\n\ 18 | edge [color="#cccccc"]\n'; 19 | } 20 | 21 | // beginning of DOT 22 | function dotPrefixForType(type) { 23 | return dotPrefix(dotNameForType(type, null) + ' - Type Hierarchy'); 24 | } 25 | 26 | // beginning of DOT 27 | function dotPrefixForStdLib() { 28 | return dotPrefix('Standard Library Type Hierarchy'); 29 | } 30 | 31 | // end of DOT - includes subgraph for all the (non-protocol) types so they end up on one line 32 | function dotPostfixWithTypes(typeNames) { 33 | var str = typeNames.map(function(el) { return '"' + el + '";' }).join(' '); 34 | return '\n\ 35 | subgraph Types {\n\ 36 | rank = max; ' + str + '\n\ 37 | }\n}'; 38 | } 39 | 40 | // return array of "tuples" (2-element arrays in this case) with all inheritance 41 | // relationships above type given in `typeName` 42 | function collectInherits(typeName, types) { 43 | if (!(types[typeName])) return []; 44 | 45 | var tuples = types[typeName].inherits.map(function(el) { return [el, typeName] }); 46 | types[typeName].inherits.forEach(function(el) { 47 | tuples.extend(collectInherits(el, types)); 48 | }); 49 | 50 | return tuples; 51 | } 52 | 53 | // return array of "tuples" (two-member arrays in this case) with all inheritance 54 | // relationships below type given in `typeName` 55 | function collectInherited(typeName, types) { 56 | if (!(types[typeName])) return []; 57 | 58 | var tuples = types[typeName].inherited.map(function(el) { return [typeName, el] }); 59 | types[typeName].inherited.forEach(function(el) { 60 | tuples.extend(collectInherited(el, types)); 61 | }); 62 | 63 | return tuples; 64 | } 65 | 66 | function buildTypeDOT(typeName, types) { 67 | // build an array of tuples (2-element arrays, here) with 68 | // start and endpoints for paths of inheritance 69 | var paths = collectInherited(typeName, types) 70 | .extend(collectInherits(typeName, types)); 71 | 72 | // map tuples onto DOT edge syntax 73 | // e.g., "_CollectionType" -> "CollectionType" 74 | var dotPaths = paths.map(function(el) { 75 | var nameFrom = (types[el[0]]) ? dotNameForType(types[el[0]], typeName) : el[0]; 76 | var nameTo = (types[el[1]]) ? dotNameForType(types[el[1]], typeName) : el[1]; 77 | return ' "' + nameFrom + '" -> "' + nameTo + '"'; 78 | }); 79 | 80 | // build list of names of types (struct, class, enum) only 81 | var typeNames = paths.reduce(function(p, c) { return p.extend(c); }, []) 82 | .unique() 83 | .filter(function(el) { return (types[el] != null); }) 84 | .filter(function(el) { return (types[el].kind != 'protocol'); }) 85 | .map(function (el) { return dotNameForType(types[el], typeName); 86 | }); 87 | 88 | // map flattened, uniqued tuples to DOT node syntax 89 | // e.g. "CollectionType" [URL="/protocol/CollectionType/"] 90 | var dotNodes = paths.reduce(function(p, c) { return p.extend(c); }, []) 91 | .unique() 92 | .sort() 93 | .filter(function(el) { return (types[el] != null); }) 94 | .map(function(el) { 95 | var kind = (types[el].kind == 'protocol') ? 'protocol' : 'type'; 96 | 97 | if (el == typeName) { 98 | return ' "' + dotNameForType(types[el], typeName) + 99 | '" [URL="/' + kind + '/' + el + '/",' + 100 | ' style="filled' + 101 | ((kind == 'protocol') ? ',rounded' : '') + 102 | '", fillcolor="#ee543d", color="#ee543d"]'; 103 | } 104 | 105 | if (kind == 'protocol') { 106 | return ' "' + types[el].name + 107 | '" [URL="/protocol/' + el + '/hierarchy/"]'; 108 | } 109 | 110 | return ' "' + types[el].name + 111 | '" [URL="/type/' + el + '/hierarchy/", style=filled]'; 112 | }); 113 | 114 | return dotPrefixForType(types[typeName]) + 115 | dotNodes.join('\n') + 116 | dotPaths.join('\n') + 117 | dotPostfixWithTypes(typeNames); 118 | } 119 | 120 | function buildStdLibDOT(types) { 121 | // build an array of tuples (2-element arrays, here) with 122 | // start and endpoints for paths of inheritance 123 | var paths = Object.keys(types).reduce(function(p, typeName) { 124 | // var inheritsTuples = types[typeName].inherits.map(function(el) { return [el, typeName] }); 125 | var inheritedTuples = types[typeName].inherited.map(function(el) { return [typeName, el] }); 126 | return p.extend(inheritedTuples); 127 | }, []); 128 | 129 | // map tuples onto DOT edge syntax 130 | // e.g., "_CollectionType" -> "CollectionType" 131 | var dotPaths = paths.map(function(el) { 132 | var nameFrom = (types[el[0]]) ? types[el[0]].name : el[0]; 133 | var nameTo = (types[el[1]]) ? types[el[1]].name : el[1]; 134 | return ' "' + nameFrom + '" -> "' + nameTo + '"'; 135 | }); 136 | 137 | // build list of names of types (struct, class, enum) only 138 | var typeNames = paths.reduce(function(p, c) { return p.extend(c); }, []) 139 | .unique() 140 | .filter(function(el) { return (types[el] != null); }) 141 | .filter(function(el) { return (types[el].kind != 'protocol'); }) 142 | .map(function (el) { return types[el].name; 143 | }); 144 | 145 | // map flattened, uniqued tuples to DOT node syntax 146 | // e.g. "CollectionType" [URL="/protocol/CollectionType/"] 147 | var dotNodes = paths.reduce(function(p, c) { return p.extend(c); }, []) 148 | .unique() 149 | .sort() 150 | .filter(function(el) { return (types[el] != null); }) 151 | .map(function(el) { 152 | var kind = (types[el].kind == 'protocol') ? 'protocol' : 'type'; 153 | 154 | if (kind == 'protocol') { 155 | return ' "' + types[el].name + 156 | '" [URL="/protocol/' + el + '/"]'; 157 | } 158 | 159 | return ' "' + types[el].name + 160 | '" [URL="/type/' + el + '/", style=filled]'; 161 | }); 162 | 163 | return dotPrefixForStdLib() + 164 | dotNodes.join('\n') + 165 | dotPaths.join('\n') + 166 | dotPostfixWithTypes(typeNames); 167 | } 168 | 169 | // ---------------------------------------------------------------------------- 170 | // Export 171 | 172 | var Grapher = function() { }; 173 | 174 | Grapher.prototype.getTypeDOT = function(typeName, context) { 175 | return buildTypeDOT(typeName, context.types); 176 | } 177 | 178 | Grapher.prototype.getAllTypesDOT = function(context) { 179 | var rslt = {}; 180 | for (var typeName in context.types) { 181 | rslt[typeName] = buildTypeDOT(typeName, context.types); 182 | } 183 | return rslt; 184 | } 185 | 186 | Grapher.prototype.getStdLibDOT = function(context) { 187 | return buildStdLibDOT(context.types); 188 | } 189 | 190 | module.exports = new Grapher(); 191 | 192 | -------------------------------------------------------------------------------- /data/svg-logo.txt: -------------------------------------------------------------------------------- 1 | 2 | 15 | 17 | 20 | 25 | 29 | 35 | 46 | 54 | 57 | 68 | 73 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /templates/swifter-header.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 10 | 12 | 14 | 18 | 21 | 23 | 24 | 25 | 27 | 30 | 33 | 37 | 40 | 41 | 42 | 47 | 49 | 51 | 54 | 57 | 61 | 64 | 66 | 69 | 74 | 77 | 81 | 84 | 87 | 90 | 92 | 94 | 97 | 100 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /lib/swiftdoc-builder.js: -------------------------------------------------------------------------------- 1 | var Twig = require('twig'), 2 | mkdirp = require('mkdirp'), 3 | fs = require('fs'), 4 | execsyncs = require("execsyncs"), 5 | grapher = require('./swiftdoc-grapher'), 6 | ext = require('./type-extensions'), 7 | markdown = require('markdown').markdown, 8 | PCRE = require('pcre').PCRE, 9 | path = require('path'), 10 | twig = Twig.twig; 11 | 12 | var DEBUG = false; 13 | var appRoot = path.join(__dirname, '../'); 14 | var svgLogo = fs.readFileSync(appRoot + 'data/svg-logo.txt', 'utf8'); 15 | var outputDir = ''; 16 | var urlPrefix = ''; 17 | var dotPath = '/usr/local/bin/dot'; 18 | var outputGraphs = true; 19 | 20 | // ---------------------------------------------------------------------------- 21 | // Page titles and descriptions 22 | 23 | var pageInfo = { 24 | home: { 25 | title: 'Home', 26 | }, 27 | var_list: { 28 | title: 'Global Variables', 29 | description: 'Documentation for global variables in the Swift language.', 30 | }, 31 | alias_list: { 32 | title: 'Type Aliases', 33 | description: 'Documentation for global type aliases in the Swift language.', 34 | }, 35 | index_type: { 36 | title: 'Types', 37 | description: 'Documentation for all classes, structs and enums in the Swift language.', 38 | }, 39 | index_protocol: { 40 | title: 'Protocols', 41 | description: 'Documentation for all protocols in the Swift language.', 42 | }, 43 | index_operator: { 44 | title: 'Operators', 45 | description: 'Documentation for all operators in the Swift language.', 46 | }, 47 | index_global: { 48 | title: 'Globals', 49 | description: 'Documentation for all global variables, type aliases, and functions in the Swift language.', 50 | }, 51 | index_func: { 52 | title: 'Global Functions', 53 | description: 'Documentation for all top-level, global functions in the Swift language.', 54 | }, 55 | }; 56 | 57 | // ---------------------------------------------------------------------------- 58 | // Twig templates 59 | 60 | var templates = { 61 | var_list : Twig.twig({ path: appRoot + 'templates/var-list.html', async: false }), 62 | alias_list : Twig.twig({ path: appRoot + 'templates/alias-list.html', async: false }), 63 | 64 | operator : Twig.twig({ path: appRoot + 'templates/operator.html', async: false }), 65 | func : Twig.twig({ path: appRoot + 'templates/func.html', async: false }), 66 | type : Twig.twig({ path: appRoot + 'templates/type.html', async: false }), 67 | 68 | index_func : Twig.twig({ path: appRoot + 'templates/index-func.html', async: false }), 69 | index_global : Twig.twig({ path: appRoot + 'templates/index-global.html', async: false }), 70 | index_home : Twig.twig({ path: appRoot + 'templates/index-home.html', async: false }), 71 | index_operator : Twig.twig({ path: appRoot + 'templates/index-operator.html', async: false }), 72 | index_type : Twig.twig({ path: appRoot + 'templates/index-type.html', async: false }), 73 | }; 74 | 75 | // ---------------------------------------------------------------------------- 76 | // Twig filters 77 | 78 | // returns true if item (can be a property or a method) is static/class 79 | function isStatic(item) { 80 | return ((item['stat'] == 'static') || (item['stat'] == 'class') || (item['note'] == 'static') || (item['note'] == 'class')); 81 | } 82 | 83 | // ReStructuredText code blocks use fewer spaces than markdown - fix that 84 | function convertCodeBlocks(value) { 85 | // if (value.indexOf('Instances of conforming types can be compared') == -1) return value; 86 | 87 | var codeBlockStart = new PCRE('::[ \\t]*$', PCRE.PCRE_EXTENDED | PCRE.PCRE_MULTILINE); 88 | var codeBlockEnd = new PCRE('^\\S', PCRE.PCRE_EXTENDED | PCRE.PCRE_MULTILINE); 89 | var match, endMatch; 90 | while (match = codeBlockStart.exec(value)) { 91 | if (endMatch = codeBlockEnd.exec(value, match[1])) { 92 | value = value.substring(0, match[0] + 1) + 93 | value.substring(match[1], endMatch[0]).replace(/^ /gm, ' ') + 94 | value.substring(endMatch[0]); 95 | } else { 96 | value = value.substring(0, match[0] + 1) + 97 | value.substring(match[1]).replace(/^ /gm, ' '); 98 | } 99 | } 100 | return value; 101 | } 102 | 103 | // convert comment from quote-unquote-ReStructuredText to html 104 | function convertComment(value) { 105 | value = value.replace(/\\\\ ?'/g, '\'') // weird characters 106 | .replace(/`([^`]+)\n?<(https?:\/\/[^>]+)>`_*/mgi, '[$1]($2)') // convert RST link syntax to MD 107 | .replace(/\.\. parsed-literal::?/g, '::') // convert funky syntax to code block 108 | .replace(/\.\. ([^:\n]+)::/g, '**$1:**') // incorrect format for inline header? 109 | .replace(/:param: ([^ ,]+)/g, '**$1**') // parameter 110 | .replace(/:returns: /g, '**Returns:** ') // return value 111 | .replace(/_,/g, ',') // Array has a weird internal link 112 | .replace(/\.\. _.+?:/g, '') 113 | 114 | // Swift 2.0 special notations 115 | 116 | .replace(/- parameter +([^ ,]+):/gi, // parameter 117 | '\r**`$1`:** ') 118 | .replace(/- See ?Also: (.+)/gi, // see also 119 | '**See Also:** $1') 120 | .replace(/- see ?also:/g, // see also 121 | '**See Also:**\n\n') 122 | .replace(/- ([^:\s]+):/g, '**$1:**') // special notes 123 | ; 124 | 125 | value = convertCodeBlocks(value); 126 | var html = markdown.toHTML(value); 127 | html = html 128 | /* 129 | .replace(/&lt;/g, '<') // fix doubly escaped < 130 | .replace(/&gt;/g, '>') // > 131 | .replace(/&quot;/g, '"') // quotes 132 | .replace(/&amp;/g, '&') // & 133 | */ 134 | .replace(/&#039;/g, '\'') // ' 135 | .replace(/([^<]+?) *<(http.+?)><\/code>_+/g, '$1') // links get screwed up 136 | .replace(/<(http.+?)>/g, '$1') // more linking 137 | .replace(/\s+<\/a>/g, '') // more linking 138 | .replace(/\\\\ /g, '') // get rid of extraneous double-backslashes 139 | .replace(/\\ /g, '') // and extraneous single-backslashes 140 | .replace(/

:<\/p>\n?\n?/, '') // leftovers from '::' on own line 141 | .replace(/

/g, '
'); // add language class to pre/code blocks
142 | 
143 |     return html;
144 | }
145 | 
146 | Twig.extendFilter('rst', convertComment);
147 | 
148 | Twig.extendFilter('withSpaceAfter', function(value) {
149 |     return (value) ? value + ' ' : '';
150 | });
151 | 
152 | Twig.extendFilter('static', function(values) {
153 |     return values.filter(function(val) { 
154 |         return isStatic(val);
155 |     });
156 | })
157 | 
158 | Twig.extendFilter('instance', function(values) {
159 |     return values.filter(function(val) { 
160 |         return !isStatic(val);
161 |     });
162 | })
163 | 
164 | Twig.extendFilter('addSoftBreaks', function(value) {
165 |     return value.replace(/([^(:]+?:)/g, '$1');
166 | });
167 | 
168 | // ----------------------------------------------------------------------------
169 | // Output to files
170 | 
171 | function outputHTML(path, template, obj, info) {
172 |     info.root = urlPrefix;
173 |     obj.root = urlPrefix;
174 | 
175 |     var yaml = buildYAML(info);
176 |     var output = template.render(obj);
177 | 
178 |     mkdirp.sync(outputDir + path);
179 |     fs.writeFileSync(outputDir + path + '/index.html', yaml + output);
180 | }
181 | 
182 | function addLogo(svgData) {
183 |     return svgData.replace(/(]+translate\([0-9.]+ ([0-9.]+)\)">)/, 
184 |                             '$1\n\n' + svgLogo + '\n');
185 | 
186 | }
187 | 
188 | function customizeGraph(svgData) {
189 |     return svgData.replace(/[^<]+<\/title>/g, '')                    // get rid of titles
190 |                   .replace(/ xlink:title="[^"]+"/g, ' target="_top"')       // and title attributes
191 |                   .replace(/<polygon fill=\"white\"[^>]+>/g, '')            // clear background
192 |                   .replace(/\/(type|protocol)\//g, urlPrefix + '/$1/')       // add root url 
193 | }
194 | 
195 | function setMinimumWidth(svgData) {
196 |     var match = /svg width=\"([^\"]+)pt\"/.exec(svgData),
197 |         width = (match) ? match[1] : null;
198 |         
199 |     if (width && (width < 320)) {
200 |         return svgData.replace(/(<svg width=\")([^\"]+)(pt\"[^>]+viewBox=\"\S+ \S+ )(\S+)/, '$01320$03320.0');
201 |     } else {
202 |         return svgData;
203 |     }
204 | }
205 | 
206 | function objectToYAML(obj) {
207 |     var yaml = '---\n';
208 |     for (key in obj) {
209 |         yaml += key + ': "' + obj[key].replace('"', '"') + '"\n';
210 |     }
211 |     yaml += '---\n\n';
212 |     return yaml;
213 | }
214 | 
215 | function getWrapperForGraph(type) {
216 |     var info =  {
217 |                     layout: 'svg_wrapper',
218 |                     title: 'Inheritance Graph for ' + type.name,
219 |                     typename: type.name,
220 |                 };
221 | 
222 |     return objectToYAML(info);
223 | }
224 | 
225 | function outputGraph(path, dot, type) {
226 |     var dotFile = outputDir + path + '/index.dot';
227 |     var svgFile = outputDir + path + '/index.svg';
228 | 
229 |     // output dot-file
230 |     mkdirp.sync(outputDir + path);
231 |     fs.writeFileSync(dotFile, dot);
232 |     
233 |     // create and write the SVG
234 |     var svgData = execsyncs('cat ' + dotFile + ' | /usr/local/bin/dot -Tsvg');
235 |     svgData = addLogo(customizeGraph(svgData));
236 |     fs.writeFileSync(svgFile, svgData);
237 | 
238 |     // create an HTML wrapper
239 |     fs.writeFileSync(outputDir + path + '/index.html', getWrapperForGraph(type));
240 | }
241 | 
242 | function generateItemInfo(item) {
243 |     function skipEmpty(el) {
244 |         return ((el != '') && (el != undefined));
245 |     }
246 | 
247 |     function getName(item) {
248 |         return item.name;
249 |     }
250 |     
251 |     // title will just be the name
252 |     var name = item.name;
253 |     
254 |     // meta description
255 |     var description = '';
256 |     if (item.comment) {
257 |         var i = item.comment.search(/[\n\r]/);
258 |         var comment = i == -1 ? item.comment : item.comment.substring(0, i);
259 |         description = convertComment(comment);
260 |     }
261 |     if (description == '') {
262 |         description = 'Swift documentation for ' + item.kind + ' \'' + name + '\'.';
263 |     } else {
264 |         description = description.replace(/<\/p>[^]*/, '')
265 |                             .replace(/<[^>]+>/ig, '')
266 |                             .replace(/\\ /g, '')
267 |                             .replace(/\\\(/, '\\\\(')
268 |                             .replace(/\.$/, '');
269 |         description = 'Swift documentation for \'' + name + '\': ' + description + '.';
270 |     }
271 |     
272 |     // meta keywords
273 |     var keywords = [name, item.kind, 'swift', 'documentation'];
274 |     if (item.functions)
275 |         keywords.push.call(keywords, item.functions.map(getName));
276 |     if (item.properties)
277 |         keywords.push.call(keywords, item.properties.map(getName));
278 |     if (item.aliases)
279 |         keywords.push.call(keywords, item.aliases.map(getName));
280 |     
281 |     return { title: name, description: description, keywords: keywords.unique().filter(skipEmpty).join(',') };
282 | }
283 | 
284 | function collectLinks(list, initial, linker, prefix) {
285 |     if (!prefix) prefix = '';
286 |     
287 |     return list.reduce(function (p, c) {
288 |         if (c.inherited == true) return p;
289 |         if (p[prefix + c.name]) return p;
290 |         p[prefix + c.name] = linker(c);
291 |         return p;    
292 |     }, initial);
293 | }
294 | 
295 | function buildYAML(info) {
296 |     // nothing to do here
297 |     if (!info) return '';
298 |     
299 |     var yamlObject = { layout: (info.title == "Home") ? 'home' : 'default' };
300 |     for (key in info) yamlObject[key] = info[key];
301 | 
302 |     // TODO: version number?
303 |     
304 |     return objectToYAML(yamlObject);
305 | }
306 | 
307 | function build(context) {    
308 |     // prepare local data
309 |     var typesAsArray = Object.keys(context.types)
310 |                              .sort()
311 |                              .map(function(el) { return context.types[el] });
312 |     var typeArray = typesAsArray.filter(function (el) { return el.kind != 'protocol' });
313 |     var protocolArray = typesAsArray.filter(function (el) { return el.kind == 'protocol' });
314 |     var functionNames = context.functions.map(function(el) { return el.name; }).unique().sort();
315 |     var linkData = {};
316 | 
317 |     // this returns a function that adds a set prefix to whatever's passed in
318 |     // handy for prepending URL paths onto type and function names below
319 |     var prefixer = function(prefix) {
320 |         return function(item) {
321 |             return prefix + (item.uniqueSignatureURL || item.name);
322 |         };
323 |     };
324 |     var functionPrefixer = function(prefix) {
325 |         return function(item) {
326 |             return prefix + item.name;
327 |         };
328 |     };
329 | 
330 |     // home page
331 |     outputHTML('', templates.index_home, { 
332 |         types: typeArray,
333 |         protocols: protocolArray,
334 |         operators: context.operators,
335 |         functions: functionNames,
336 |     }, pageInfo.home);
337 |     
338 |     // index pages
339 |     outputHTML('protocol', templates.index_type, { items: protocolArray, path: 'protocol' }, pageInfo.index_protocol);
340 |     outputHTML('type', templates.index_type, { items: typeArray, path: 'type' }, pageInfo.index_type);
341 |     outputHTML('operator', templates.index_operator, { operators: context.operators }, pageInfo.index_operator);
342 |     outputHTML('global', templates.index_global, { functions: functionNames }, pageInfo.index_global);
343 |     outputHTML('func', templates.index_func, { functions: functionNames }, pageInfo.index_func);
344 |     
345 |     // types & protocols
346 |     typesAsArray.forEach(function(el) {
347 |         var info = generateItemInfo(el);
348 |         var kind = (el.kind == 'protocol') ? el.kind : 'type';
349 | 
350 |         // get DOT for graphviz
351 |         var dot = '';
352 |         var hasHierarchy = false;
353 |         if (outputGraphs) {
354 |             dot = grapher.getTypeDOT(el.name, context);
355 |             hasHierarchy = (dot.indexOf('->') != -1);
356 |         }
357 | 
358 |         linkData = collectLinks(el.functions || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/func#func-'), el.name + '.')
359 |         linkData = collectLinks(el.properties || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/prop#'), el.name + '.')
360 |         linkData = collectLinks(el.cases || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/case#'), el.name + '.')
361 | 
362 |         if (el.imp) {
363 |             for (var impKey in el.imp) {
364 |                 var imp = el.imp[impKey];
365 |                 linkData = collectLinks(imp.functions || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/func#func-' + impKey.urlify() + '-'), el.name + '.')
366 |                 linkData = collectLinks(imp.properties || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/prop#' + impKey.urlify() + '-'), el.name + '.')
367 |                 linkData = collectLinks(imp.cases || [], linkData, prefixer(urlPrefix + '/' + kind + '/' + el.name + '/case#' + impKey.urlify() + '-'), el.name + '.')
368 |             }
369 |         }
370 | 
371 |         outputHTML('' + kind + '/' + el.name, templates.type, { type: el, hasHierarchy: hasHierarchy }, info);
372 | 
373 |         if (hasHierarchy)
374 |             outputGraph('' + kind + '/' + el.name + '/hierarchy', dot, el);
375 |     })
376 |     
377 |     // operators
378 |     context.operators.forEach(function (el) {
379 |         outputHTML('operator/' + el.slug, templates.operator, { operator: el }, {
380 |             title: 'Operator: ' + el.name, 
381 |             description: 'Swift documentation for the \'' + el.name + '\' operator.',
382 |         });
383 |     });
384 |     
385 |     // functions
386 |     functionNames.forEach(function (funcName) {
387 |         var functions = context.functions.filter(function(el) { return el.name == funcName });
388 |         var info = generateItemInfo(functions[0]);
389 |         outputHTML('func/' + funcName, templates.func, { functions: functions }, info);
390 |     });
391 | 
392 |     // type aliases
393 |     outputHTML('global/alias', templates.alias_list, { aliases: context.aliases }, pageInfo.alias_list);
394 |     
395 | 
396 |     // operators need to have names converted for URL safety
397 |     linkData = collectLinks(context.operators, linkData, function (item) { return urlPrefix + '/operator/' + item.slug; });
398 | 
399 |     // functions, types, & protocols are all simple
400 |     linkData = collectLinks(context.functions, linkData, functionPrefixer(urlPrefix + '/func/'));
401 |     linkData = collectLinks(typeArray, linkData, prefixer(urlPrefix + '/type/'));
402 |     linkData = collectLinks(protocolArray, linkData, prefixer(urlPrefix + '/protocol/'));
403 | 
404 |     // variables and type aliases have only a single page each
405 |     linkData = collectLinks(context.aliases, linkData, function() { return urlPrefix + '/global/alias/' });
406 |     
407 |     // build and write JS link data
408 |     var linkDataString = 'var linkdata = ' + JSON.stringify(linkData) + ';\n';
409 |     mkdirp.sync(outputDir + 'assets/js' );
410 |     fs.writeFile(outputDir + 'assets/js/swift-linkdata.js', linkDataString);
411 | }
412 | 
413 | // ----------------------------------------------------------------------------
414 | // Export
415 | 
416 | var Builder = function() { };
417 | 
418 | Builder.prototype.build = build;
419 | 
420 | Builder.prototype.setOutputDir = function(dir) {
421 |     outputDir = appRoot + dir.replace(/\/$/, '') + '/';
422 | };
423 | 
424 | Builder.prototype.setURLPrefix = function(prefix) {
425 |     urlPrefix = prefix.replace(/\/$/, '');
426 | };
427 | 
428 | Builder.prototype.setOutputGraphs = function(output) {
429 |     outputGraphs = output;
430 | };
431 | 
432 | module.exports = new Builder();
433 | 
434 | 
435 | 


--------------------------------------------------------------------------------
/data/addenda/1.2/foundation.txt:
--------------------------------------------------------------------------------
  1 | extension String.UTF16View.Index : RandomAccessIndexType {
  2 | 
  3 |     /// *[Foundation]* Construct from an integer offset.
  4 |     init(_ offset: Int)
  5 | 
  6 |     /// *[Foundation]* Return the minimum number of applications of `successor` or
  7 |     /// `predecessor` required to reach `other` from `self`.
  8 |     ///
  9 |     /// Complexity: O(1).
 10 |     func distanceTo(x: String.UTF16View.Index) -> Int
 11 | 
 12 |     /// *[Foundation]* Return `self` offset by `n` steps.
 13 |     ///
 14 |     /// :returns: If `n > 0`, the result of applying `successor` to
 15 |     /// `self` `n` times.  If `n < 0`, the result of applying
 16 |     /// `predecessor` to `self` `-n` times. Otherwise, `self`.
 17 |     ///
 18 |     /// Complexity: O(1)
 19 |     func advancedBy(x: Int) -> String.UTF16View.Index
 20 | }
 21 | 
 22 | extension String {
 23 | 
 24 |     /// *[Foundation]* Returns an Array of the encodings string objects support
 25 |     /// in the application’s environment.
 26 |     static func availableStringEncodings() -> [NSStringEncoding]
 27 | 
 28 |     /// *[Foundation]* Returns the C-string encoding assumed for any method accepting
 29 |     /// a C string as an argument.
 30 |     static func defaultCStringEncoding() -> NSStringEncoding
 31 | 
 32 |     /// *[Foundation]* Returns a human-readable string giving the name of a given encoding.
 33 |     static func localizedNameOfStringEncoding(encoding: NSStringEncoding) -> String
 34 | 
 35 |     /// *[Foundation]* Returns a string created by using a given format string as a
 36 |     /// template into which the remaining argument values are substituted
 37 |     /// according to the user's default locale.
 38 |     static func localizedStringWithFormat(format: String, _ arguments: CVarArgType...) -> String
 39 | 
 40 |     /// *[Foundation]* Returns a string built from the strings in a given array
 41 |     /// by concatenating them with a path separator between each pair.
 42 |     static func pathWithComponents(components: [String]) -> String
 43 | 
 44 |     /// *[Foundation]* Produces a string created by reading data from the file at a
 45 |     /// given path interpreted using a given encoding.
 46 |     init?(contentsOfFile path: String, encoding enc: NSStringEncoding, error: NSErrorPointer = default)
 47 | 
 48 |     /// *[Foundation]* Produces a string created by reading data from the file at
 49 |     /// a given path and returns by reference the encoding used to
 50 |     /// interpret the file.
 51 |     init?(contentsOfFile path: String, usedEncoding: UnsafeMutablePointer<NSStringEncoding> = default, error: NSErrorPointer = default)
 52 | 
 53 |     /// *[Foundation]* Produces a string created by reading data from a given URL
 54 |     /// interpreted using a given encoding.  Errors are written into the
 55 |     /// inout `error` argument.
 56 |     init?(contentsOfURL url: NSURL, encoding enc: NSStringEncoding, error: NSErrorPointer = default)
 57 | 
 58 |     /// *[Foundation]* Produces a string created by reading data from a given URL
 59 |     /// and returns by reference the encoding used to interpret the
 60 |     /// data.  Errors are written into the inout `error` argument.
 61 |     init?(contentsOfURL url: NSURL, usedEncoding enc: UnsafeMutablePointer<NSStringEncoding> = default, error: NSErrorPointer = default)
 62 | 
 63 |     /// *[Foundation]* Produces a string containing the bytes in a given C array,
 64 |     /// interpreted according to a given encoding.
 65 |     init?(CString: UnsafePointer<CChar>, encoding enc: NSStringEncoding)
 66 | 
 67 |     /// *[Foundation]* Produces a string created by copying the data from a given
 68 |     /// C array of UTF8-encoded bytes.
 69 |     init?(UTF8String bytes: UnsafePointer<CChar>)
 70 | 
 71 |     /// *[Foundation]* Returns a Boolean value that indicates whether the
 72 |     /// `String` can be converted to a given encoding without loss of
 73 |     /// information.
 74 |     func canBeConvertedToEncoding(encoding: NSStringEncoding) -> Bool
 75 | 
 76 |     /// *[Foundation]* Produce a string with the first character from each word changed
 77 |     /// to the corresponding uppercase value.
 78 |     var capitalizedString: String { get }
 79 | 
 80 |     /// *[Foundation]* Returns a capitalized representation of the `String`
 81 |     /// using the specified locale.
 82 |     func capitalizedStringWithLocale(locale: NSLocale?) -> String
 83 | 
 84 |     /// *[Foundation]* Returns the result of invoking `compare:options:` with
 85 |     /// `NSCaseInsensitiveSearch` as the only option.
 86 |     func caseInsensitiveCompare(aString: String) -> NSComparisonResult
 87 | 
 88 |     /// *[Foundation]* Returns a string containing characters the `String` and a
 89 |     /// given string have in common, starting from the beginning of each
 90 |     /// up to the first characters that aren’t equivalent.
 91 |     func commonPrefixWithString(aString: String, options: NSStringCompareOptions) -> String
 92 | 
 93 |     /// *[Foundation]* Compares the string using the specified options and
 94 |     /// returns the lexical ordering for the range.
 95 |     func compare(aString: String, options mask: NSStringCompareOptions = default, range: Range<String.Index>? = default, locale: NSLocale? = default) -> NSComparisonResult
 96 | 
 97 |     /// *[Foundation]* Interprets the `String` as a path in the file system and
 98 |     /// attempts to perform filename completion, returning a numeric
 99 |     /// value that indicates whether a match was possible, and by
100 |     /// reference the longest path that matches the `String`.
101 |     /// Returns the actual number of matching paths.
102 |     func completePathIntoString(_ outputName: UnsafeMutablePointer<String> = default, caseSensitive: Bool, matchesIntoArray: UnsafeMutablePointer<[String]> = default, filterTypes: [String]? = default) -> Int
103 | 
104 |     /// *[Foundation]* Returns an array containing substrings from the `String`
105 |     /// that have been divided by characters in a given set.
106 |     func componentsSeparatedByCharactersInSet(separator: NSCharacterSet) -> [String]
107 | 
108 |     /// *[Foundation]* Returns an array containing substrings from the `String`
109 |     /// that have been divided by a given separator.
110 |     func componentsSeparatedByString(separator: String) -> [String]
111 | 
112 |     /// *[Foundation]* Returns a representation of the `String` as a C string
113 |     /// using a given encoding.
114 |     func cStringUsingEncoding(encoding: NSStringEncoding) -> [CChar]?
115 | 
116 |     /// *[Foundation]* Returns an `NSData` object containing a representation of
117 |     /// the `String` encoded using a given encoding.
118 |     func dataUsingEncoding(encoding: NSStringEncoding, allowLossyConversion: Bool = default) -> NSData?
119 | 
120 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
121 |     /// contents using Form D.
122 |     var decomposedStringWithCanonicalMapping: String { get }
123 | 
124 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
125 |     /// contents using Form KD.
126 |     var decomposedStringWithCompatibilityMapping: String { get }
127 | 
128 |     /// *[Foundation]* Enumerates all the lines in a string.
129 |     func enumerateLines(body: (line: String, inout stop: Bool) -> ())
130 | 
131 |     /// *[Foundation]* Performs linguistic analysis on the specified string by
132 |     /// enumerating the specific range of the string, providing the
133 |     /// Block with the located tags.
134 |     func enumerateLinguisticTagsInRange(range: Range<String.Index>, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions, orthography: NSOrthography?, _ body: (String, Range<String.Index>, Range<String.Index>, inout Bool) -> ())
135 | 
136 |     /// *[Foundation]* Enumerates the substrings of the specified type in the
137 |     /// specified range of the string.
138 |     func enumerateSubstringsInRange(range: Range<String.Index>, options opts: NSStringEnumerationOptions, _ body: (substring: String, substringRange: Range<String.Index>, enclosingRange: Range<String.Index>, inout Bool) -> ())
139 | 
140 |     /// *[Foundation]* Returns the fastest encoding to which the `String` may be
141 |     /// converted without loss of information.
142 |     var fastestEncoding: NSStringEncoding { get }
143 | 
144 |     /// *[Foundation]* Returns a file system-specific representation of the `String`.
145 |     func fileSystemRepresentation() -> [CChar]
146 | 
147 |     /// *[Foundation]* Gets a given range of characters as bytes in a specified encoding.
148 |     /// Note: will get a maximum of `min(buffer.count, maxLength)` bytes.
149 |     func getBytes(inout buffer: [UInt8], maxLength: Int, usedLength: UnsafeMutablePointer<Int>, encoding: NSStringEncoding, options: NSStringEncodingConversionOptions, range: Range<String.Index>, remainingRange: UnsafeMutablePointer<Range<String.Index>>) -> Bool
150 | 
151 |     /// *[Foundation]* Converts the `String`’s content to a given encoding and
152 |     /// stores them in a buffer. Note: will store a maximum of
153 |     /// `min(buffer.count, maxLength)` bytes.
154 |     func getCString(inout buffer: [CChar], maxLength: Int, encoding: NSStringEncoding) -> Bool
155 | 
156 |     /// *[Foundation]* Interprets the `String` as a system-independent path and
157 |     /// fills a buffer with a C-string in a format and encoding suitable
158 |     /// for use with file-system calls. Note: will store a maximum of
159 |     /// `min(buffer.count, maxLength)` bytes.
160 |     func getFileSystemRepresentation(inout buffer: [CChar], maxLength: Int) -> Bool
161 | 
162 |     /// *[Foundation]* Returns by reference the beginning of the first line and
163 |     /// the end of the last line touched by the given range.
164 |     func getLineStart(start: UnsafeMutablePointer<String.Index>, end: UnsafeMutablePointer<String.Index>, contentsEnd: UnsafeMutablePointer<String.Index>, forRange: Range<String.Index>)
165 | 
166 |     /// *[Foundation]* Returns by reference the beginning of the first paragraph
167 |     /// and the end of the last paragraph touched by the given range.
168 |     func getParagraphStart(start: UnsafeMutablePointer<String.Index>, end: UnsafeMutablePointer<String.Index>, contentsEnd: UnsafeMutablePointer<String.Index>, forRange: Range<String.Index>)
169 | 
170 |     /// *[Foundation]* An unsigned integer that can be used as a hash table address.
171 |     var hash: Int { get }
172 | 
173 |     /// *[Foundation]* Produces an initialized `NSString` object equivalent to the given
174 |     /// `bytes` interpreted in the given `encoding`.
175 |     init?<S : SequenceType where UInt8 == UInt8>(bytes: S, encoding: NSStringEncoding)
176 | 
177 |     /// *[Foundation]* Produces an initialized `String` object that contains a
178 |     /// given number of bytes from a given buffer of bytes interpreted
179 |     /// in a given encoding, and optionally frees the buffer.  WARNING:
180 |     /// this initializer is not memory-safe!
181 |     init?(bytesNoCopy bytes: UnsafeMutablePointer<Void>, length: Int, encoding: NSStringEncoding, freeWhenDone flag: Bool)
182 | 
183 |     /// *[Foundation]* Returns an initialized `String` object that contains a
184 |     /// given number of characters from a given array of Unicode
185 |     /// characters.
186 |     init(utf16CodeUnits: UnsafePointer<unichar>, count: Int)
187 | 
188 |     /// *[Foundation]* Returns an initialized `String` object that contains a given
189 |     /// number of characters from a given array of UTF-16 Code Units
190 |     init(utf16CodeUnitsNoCopy: UnsafePointer<unichar>, count: Int, freeWhenDone flag: Bool)
191 | 
192 |     /// *[Foundation]* Returns a `String` object initialized by using a given
193 |     /// format string as a template into which the remaining argument
194 |     /// values are substituted.
195 |     init(format: String, _ arguments: CVarArgType...)
196 | 
197 |     /// *[Foundation]* Returns a `String` object initialized by using a given
198 |     /// format string as a template into which the remaining argument
199 |     /// values are substituted according to the user’s default locale.
200 |     init(format: String, arguments: [CVarArgType])
201 | 
202 |     /// *[Foundation]* Returns a `String` object initialized by using a given
203 |     /// format string as a template into which the remaining argument
204 |     /// values are substituted according to given locale information.
205 |     init(format: String, locale: NSLocale?, _ args: CVarArgType...)
206 | 
207 |     /// *[Foundation]* Returns a `String` object initialized by using a given
208 |     /// format string as a template into which the remaining argument
209 |     /// values are substituted according to given locale information.
210 |     init(format: String, locale: NSLocale?, arguments: [CVarArgType])
211 | 
212 |     /// *[Foundation]* Returns the last path component of the `String`.
213 |     var lastPathComponent: String { get }
214 | 
215 |     /// *[Foundation]* Returns the number of Unicode characters in the `String`.
216 |     var utf16Count: Int { get }
217 | 
218 |     /// *[Foundation]* Returns the number of bytes required to store the
219 |     /// `String` in a given encoding.
220 |     func lengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
221 | 
222 |     /// *[Foundation]* Returns the range of characters representing the line or lines
223 |     /// containing a given range.
224 |     func lineRangeForRange(aRange: Range<String.Index>) -> Range<String.Index>
225 | 
226 |     /// *[Foundation]* Returns an array of linguistic tags for the specified
227 |     /// range and requested tags within the receiving string.
228 |     func linguisticTagsInRange(range: Range<String.Index>, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions = default, orthography: NSOrthography? = default, tokenRanges: UnsafeMutablePointer<[Range<String.Index>]> = default) -> [String]
229 | 
230 |     /// *[Foundation]* Compares the string and a given string using a
231 |     /// case-insensitive, localized, comparison.
232 |     func localizedCaseInsensitiveCompare(aString: String) -> NSComparisonResult
233 | 
234 |     /// *[Foundation]* Compares the string and a given string using a localized
235 |     /// comparison.
236 |     func localizedCompare(aString: String) -> NSComparisonResult
237 | 
238 |     /// *[Foundation]* Compares strings as sorted by the Finder.
239 |     func localizedStandardCompare(string: String) -> NSComparisonResult
240 | 
241 |     /// *[Foundation]* Returns a version of the string with all letters
242 |     /// converted to lowercase, taking into account the specified
243 |     /// locale.
244 |     func lowercaseStringWithLocale(locale: NSLocale) -> String
245 | 
246 |     /// *[Foundation]* Returns the maximum number of bytes needed to store the
247 |     /// `String` in a given encoding.
248 |     func maximumLengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
249 | 
250 |     /// *[Foundation]* Returns the range of characters representing the
251 |     /// paragraph or paragraphs containing a given range.
252 |     func paragraphRangeForRange(aRange: Range<String.Index>) -> Range<String.Index>
253 | 
254 |     /// *[Foundation]* Returns an array of NSString objects containing, in
255 |     /// order, each path component of the `String`.
256 |     var pathComponents: [String] { get }
257 | 
258 |     /// *[Foundation]* Interprets the `String` as a path and returns the
259 |     /// `String`’s extension, if any.
260 |     var pathExtension: String { get }
261 | 
262 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
263 |     /// contents using Form C.
264 |     var precomposedStringWithCanonicalMapping: String { get }
265 | 
266 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
267 |     /// contents using Form KC.
268 |     var precomposedStringWithCompatibilityMapping: String { get }
269 | 
270 |     /// *[Foundation]* Parses the `String` as a text representation of a
271 |     /// property list, returning an NSString, NSData, NSArray, or
272 |     /// NSDictionary object, according to the topmost element.
273 |     func propertyList() -> AnyObject
274 | 
275 |     /// *[Foundation]* Returns a dictionary object initialized with the keys and
276 |     /// values found in the `String`.
277 |     func propertyListFromStringsFileFormat() -> [String : String]
278 | 
279 |     /// *[Foundation]* Finds and returns the range in the `String` of the first
280 |     /// character from a given character set found in a given range with
281 |     /// given options.
282 |     func rangeOfCharacterFromSet(aSet: NSCharacterSet, options mask: NSStringCompareOptions = default, range aRange: Range<String.Index>? = default) -> Range<String.Index>?
283 | 
284 |     /// *[Foundation]* Returns the range in the `String` of the composed
285 |     /// character sequence located at a given index.
286 |     func rangeOfComposedCharacterSequenceAtIndex(anIndex: String.Index) -> Range<String.Index>
287 | 
288 |     /// *[Foundation]* Returns the range in the string of the composed character
289 |     /// sequences for a given range.
290 |     func rangeOfComposedCharacterSequencesForRange(range: Range<String.Index>) -> Range<String.Index>
291 | 
292 |     /// *[Foundation]* Finds and returns the range of the first occurrence of a
293 |     /// given string within a given range of the `String`, subject to
294 |     /// given options, using the specified locale, if any.
295 |     func rangeOfString(aString: String, options mask: NSStringCompareOptions = default, range searchRange: Range<String.Index>? = default, locale: NSLocale? = default) -> Range<String.Index>?
296 | 
297 |     /// *[Foundation]* Returns the smallest encoding to which the `String` can
298 |     /// be converted without loss of information.
299 |     var smallestEncoding: NSStringEncoding { get }
300 | 
301 |     /// *[Foundation]* Returns a new string that replaces the current home
302 |     /// directory portion of the current path with a tilde (`~`)
303 |     /// character.
304 |     var stringByAbbreviatingWithTildeInPath: String { get }
305 | 
306 |     /// *[Foundation]* Returns a new string made from the `String` by replacing
307 |     /// all characters not in the specified set with percent encoded
308 |     /// characters.
309 |     func stringByAddingPercentEncodingWithAllowedCharacters(allowedCharacters: NSCharacterSet) -> String?
310 | 
311 |     /// *[Foundation]* Returns a representation of the `String` using a given
312 |     /// encoding to determine the percent escapes necessary to convert
313 |     /// the `String` into a legal URL string.
314 |     func stringByAddingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
315 | 
316 |     /// *[Foundation]* Returns a string made by appending to the `String` a
317 |     /// string constructed from a given format string and the following
318 |     /// arguments.
319 |     func stringByAppendingFormat(format: String, _ arguments: CVarArgType...) -> String
320 | 
321 |     /// *[Foundation]* Returns a new string made by appending to the `String` a given string.
322 |     func stringByAppendingPathComponent(aString: String) -> String
323 | 
324 |     /// *[Foundation]* Returns a new string made by appending to the `String` an
325 |     /// extension separator followed by a given extension.
326 |     func stringByAppendingPathExtension(ext: String) -> String?
327 | 
328 |     /// *[Foundation]* Returns a new string made by appending a given string to
329 |     /// the `String`.
330 |     func stringByAppendingString(aString: String) -> String
331 | 
332 |     /// *[Foundation]* Returns a new string made by deleting the last path
333 |     /// component from the `String`, along with any final path
334 |     /// separator.
335 |     var stringByDeletingLastPathComponent: String { get }
336 | 
337 |     /// *[Foundation]* Returns a new string made by deleting the extension (if
338 |     /// any, and only the last) from the `String`.
339 |     var stringByDeletingPathExtension: String { get }
340 | 
341 |     /// *[Foundation]* Returns a new string made by expanding the initial
342 |     /// component of the `String` to its full path value.
343 |     var stringByExpandingTildeInPath: String { get }
344 | 
345 |     /// *[Foundation]* Returns a string with the given character folding options
346 |     /// applied.
347 |     func stringByFoldingWithOptions(options: NSStringCompareOptions, locale: NSLocale) -> String
348 | 
349 |     /// *[Foundation]* Returns a new string formed from the `String` by either
350 |     /// removing characters from the end, or by appending as many
351 |     /// occurrences as necessary of a given pad string.
352 |     func stringByPaddingToLength(newLength: Int, withString padString: String, startingAtIndex padIndex: Int) -> String
353 | 
354 |     /// *[Foundation]* Returns a new string made from the `String` by replacing
355 |     /// all percent encoded sequences with the matching UTF-8
356 |     /// characters.
357 |     var stringByRemovingPercentEncoding: String? { get }
358 | 
359 |     /// *[Foundation]* Returns a new string in which the characters in a
360 |     /// specified range of the `String` are replaced by a given string.
361 |     func stringByReplacingCharactersInRange(range: Range<String.Index>, withString replacement: String) -> String
362 | 
363 |     /// *[Foundation]* Returns a new string in which all occurrences of a target
364 |     /// string in a specified range of the `String` are replaced by
365 |     /// another given string.
366 |     func stringByReplacingOccurrencesOfString(target: String, withString replacement: String, options: NSStringCompareOptions = default, range searchRange: Range<String.Index>? = default) -> String
367 | 
368 |     /// *[Foundation]* Returns a new string made by replacing in the `String`
369 |     /// all percent escapes with the matching characters as determined
370 |     /// by a given encoding.
371 |     func stringByReplacingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
372 | 
373 |     /// *[Foundation]* Returns a new string made from the `String` by resolving
374 |     /// all symbolic links and standardizing path.
375 |     var stringByResolvingSymlinksInPath: String { get }
376 | 
377 |     /// *[Foundation]* Returns a new string made by removing extraneous path
378 |     /// components from the `String`.
379 |     var stringByStandardizingPath: String { get }
380 | 
381 |     /// *[Foundation]* Returns a new string made by removing from both ends of
382 |     /// the `String` characters contained in a given character set.
383 |     func stringByTrimmingCharactersInSet(set: NSCharacterSet) -> String
384 | 
385 |     /// *[Foundation]* Returns an array of strings made by separately appending
386 |     /// to the `String` each string in in a given array.
387 |     func stringsByAppendingPaths(paths: [String]) -> [String]
388 | 
389 |     /// *[Foundation]* Returns a new string containing the characters of the
390 |     /// `String` from the one at a given index to the end.
391 |     func substringFromIndex(index: String.Index) -> String
392 | 
393 |     /// *[Foundation]* Returns a new string containing the characters of the
394 |     /// `String` up to, but not including, the one at a given index.
395 |     func substringToIndex(index: String.Index) -> String
396 | 
397 |     /// *[Foundation]* Returns a string object containing the characters of the
398 |     /// `String` that lie within a given range.
399 |     func substringWithRange(aRange: Range<String.Index>) -> String
400 | 
401 |     /// *[Foundation]* Returns a version of the string with all letters
402 |     /// converted to uppercase, taking into account the specified
403 |     /// locale.
404 |     func uppercaseStringWithLocale(locale: NSLocale) -> String
405 | 
406 |     /// *[Foundation]* Writes the contents of the `String` to a file at a given
407 |     /// path using a given encoding.
408 |     func writeToFile(path: String, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding, error: NSErrorPointer = default) -> Bool
409 | 
410 |     /// *[Foundation]* Writes the contents of the `String` to the URL specified
411 |     /// by url using the specified encoding.
412 |     func writeToURL(url: NSURL, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding, error: NSErrorPointer = default) -> Bool
413 | }
414 | 


--------------------------------------------------------------------------------
/data/addenda/2.0/foundation.txt:
--------------------------------------------------------------------------------
  1 | extension String {
  2 |     /// *[Foundation]* Returns an Array of the encodings string objects support
  3 |     /// in the application’s environment.
  4 |     @warn_unused_result
  5 |     public static func availableStringEncodings() -> [NSStringEncoding]
  6 |     /// *[Foundation]* Returns the C-string encoding assumed for any method accepting
  7 |     /// a C string as an argument.
  8 |     @warn_unused_result
  9 |     public static func defaultCStringEncoding() -> NSStringEncoding
 10 |     /// Returns a human-readable string giving the name of a given encoding.
 11 |     @warn_unused_result
 12 |     public static func localizedNameOfStringEncoding(encoding: NSStringEncoding) -> String
 13 |     /// *[Foundation]* Returns a string created by using a given format string as a
 14 |     /// template into which the remaining argument values are substituted
 15 |     /// according to the user's default locale.
 16 |     @warn_unused_result
 17 |     public static func localizedStringWithFormat(format: String, _ arguments: CVarArgType...) -> String
 18 |     /// *[Foundation]* Produces a string created by copying the data from a given
 19 |     /// C array of UTF8-encoded bytes.
 20 |     public init?(UTF8String bytes: UnsafePointer<CChar>)
 21 |     /// *[Foundation]* Returns a Boolean value that indicates whether the
 22 |     /// `String` can be converted to a given encoding without loss of
 23 |     /// information.
 24 |     @warn_unused_result
 25 |     public func canBeConvertedToEncoding(encoding: NSStringEncoding) -> Bool
 26 |     /// *[Foundation]* Produce a string with the first character from each word changed
 27 |     /// to the corresponding uppercase value.
 28 |     public var capitalizedString: String { get }
 29 |     /// *[Foundation]* A capitalized representation of the `String` that is produced
 30 |     /// using the current locale.
 31 |     public var localizedCapitalizedString: String { get }
 32 |     /// *[Foundation]* Returns a capitalized representation of the `String`
 33 |     /// using the specified locale.
 34 |     @warn_unused_result
 35 |     public func capitalizedStringWithLocale(locale: NSLocale?) -> String
 36 |     /// *[Foundation]* Returns the result of invoking `compare:options:` with
 37 |     /// `NSCaseInsensitiveSearch` as the only option.
 38 |     @warn_unused_result
 39 |     public func caseInsensitiveCompare(aString: String) -> NSComparisonResult
 40 |     /// *[Foundation]* Returns a string containing characters the `String` and a
 41 |     /// given string have in common, starting from the beginning of each
 42 |     /// up to the first characters that aren’t equivalent.
 43 |     @warn_unused_result
 44 |     public func commonPrefixWithString(aString: String, options: NSStringCompareOptions) -> String
 45 |     /// *[Foundation]* Compares the string using the specified options and
 46 |     /// returns the lexical ordering for the range.
 47 |     @warn_unused_result
 48 |     public func compare(aString: String, options mask: NSStringCompareOptions = default, range: Range<Index>? = default, locale: NSLocale? = default) -> NSComparisonResult
 49 |     /// *[Foundation]* Interprets the `String` as a path in the file system and
 50 |     /// attempts to perform filename completion, returning a numeric
 51 |     /// value that indicates whether a match was possible, and by
 52 |     /// reference the longest path that matches the `String`.
 53 |     /// Returns the actual number of matching paths.
 54 |     @warn_unused_result
 55 |     public func completePathIntoString(outputName: UnsafeMutablePointer<String> = default, caseSensitive: Bool, matchesIntoArray: UnsafeMutablePointer<[String]> = default, filterTypes: [String]? = default) -> Int
 56 |     /// *[Foundation]* Returns an array containing substrings from the `String`
 57 |     /// that have been divided by characters in a given set.
 58 |     @warn_unused_result
 59 |     public func componentsSeparatedByCharactersInSet(separator: NSCharacterSet) -> [String]
 60 |     /// *[Foundation]* Returns an array containing substrings from the `String`
 61 |     /// that have been divided by a given separator.
 62 |     public func componentsSeparatedByString(separator: String) -> [String]
 63 |     /// *[Foundation]* Returns a representation of the `String` as a C string
 64 |     /// using a given encoding.
 65 |     @warn_unused_result
 66 |     public func cStringUsingEncoding(encoding: NSStringEncoding) -> [CChar]?
 67 |     /// *[Foundation]* Returns an `NSData` object containing a representation of
 68 |     /// the `String` encoded using a given encoding.
 69 |     @warn_unused_result
 70 |     public func dataUsingEncoding(encoding: NSStringEncoding, allowLossyConversion: Bool = default) -> NSData?
 71 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
 72 |     /// contents using Form D.
 73 |     public var decomposedStringWithCanonicalMapping: String { get }
 74 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
 75 |     /// contents using Form KD.
 76 |     public var decomposedStringWithCompatibilityMapping: String { get }
 77 |     /// *[Foundation]* Enumerates all the lines in a string.
 78 |     public func enumerateLines(body: (line: String, inout stop: Bool) -> ())
 79 |     /// *[Foundation]* Performs linguistic analysis on the specified string by
 80 |     /// enumerating the specific range of the string, providing the
 81 |     /// Block with the located tags.
 82 |     public func enumerateLinguisticTagsInRange(range: Range<Index>, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions, orthography: NSOrthography?, _ body: (String, Range<Index>, Range<Index>, inout Bool) -> ())
 83 |     /// *[Foundation]* Enumerates the substrings of the specified type in the
 84 |     /// specified range of the string.
 85 |     public func enumerateSubstringsInRange(range: Range<Index>, options opts: NSStringEnumerationOptions, _ body: (substring: String?, substringRange: Range<Index>, enclosingRange: Range<Index>, inout Bool) -> ())
 86 |     /// *[Foundation]* Returns the fastest encoding to which the `String` may be
 87 |     /// converted without loss of information.
 88 |     public var fastestEncoding: NSStringEncoding { get }
 89 |     /// *[Foundation]* Writes the given `range` of characters into `buffer` in a given
 90 |     /// `encoding`, without any allocations.  Does not NULL-terminate.
 91 |     ///
 92 |     /// - Parameter buffer: A buffer into which to store the bytes from
 93 |     ///   the receiver. The returned bytes are not NUL-terminated.
 94 |     ///
 95 |     /// - Parameter maxBufferCount: The maximum number of bytes to write
 96 |     ///   to buffer.
 97 |     ///
 98 |     /// - Parameter usedBufferCount: The number of bytes used from
 99 |     ///   buffer. Pass `nil` if you do not need this value.
100 |     ///
101 |     /// - Parameter encoding: The encoding to use for the returned bytes.
102 |     ///
103 |     /// - Parameter options: A mask to specify options to use for
104 |     ///   converting the receiver’s contents to `encoding` (if conversion
105 |     ///   is necessary).
106 |     ///
107 |     /// - Parameter range: The range of characters in the receiver to get.
108 |     ///
109 |     /// - Parameter leftover: The remaining range. Pass `nil` If you do
110 |     ///   not need this value.
111 |     ///
112 |     /// - Returns: `true` iff some characters were converted.
113 |     ///
114 |     /// - Note: Conversion stops when the buffer fills or when the
115 |     ///   conversion isn't possible due to the chosen encoding.
116 |     ///
117 |     /// - Note: will get a maximum of `min(buffer.count, maxLength)` bytes.
118 |     public func getBytes(inout buffer: [UInt8], maxLength maxBufferCount: Int, usedLength usedBufferCount: UnsafeMutablePointer<Int>, encoding: NSStringEncoding, options: NSStringEncodingConversionOptions, range: Range<Index>, remainingRange leftover: UnsafeMutablePointer<Range<Index>>) -> Bool
119 |     /// *[Foundation]* Converts the `String`’s content to a given encoding and
120 |     /// stores them in a buffer.
121 |     /// - Note: will store a maximum of `min(buffer.count, maxLength)` bytes.
122 |     public func getCString(inout buffer: [CChar], maxLength: Int, encoding: NSStringEncoding) -> Bool
123 |     /// *[Foundation]* Returns by reference the beginning of the first line and
124 |     /// the end of the last line touched by the given range.
125 |     public func getLineStart(start: UnsafeMutablePointer<Index>, end: UnsafeMutablePointer<Index>, contentsEnd: UnsafeMutablePointer<Index>, forRange: Range<Index>)
126 |     /// *[Foundation]* Returns by reference the beginning of the first paragraph
127 |     /// and the end of the last paragraph touched by the given range.
128 |     public func getParagraphStart(start: UnsafeMutablePointer<Index>, end: UnsafeMutablePointer<Index>, contentsEnd: UnsafeMutablePointer<Index>, forRange: Range<Index>)
129 |     /// *[Foundation]* An unsigned integer that can be used as a hash table address.
130 |     public var hash: Int { get }
131 |     /// *[Foundation]* Produces an initialized `NSString` object equivalent to the given
132 |     /// `bytes` interpreted in the given `encoding`.
133 |     public init?<S : SequenceType where S.Generator.Element == UInt8>(bytes: S, encoding: NSStringEncoding)
134 |     /// *[Foundation]* Produces an initialized `String` object that contains a
135 |     /// given number of bytes from a given buffer of bytes interpreted
136 |     /// in a given encoding, and optionally frees the buffer.  WARNING:
137 |     /// this initializer is not memory-safe!
138 |     public init?(bytesNoCopy bytes: UnsafeMutablePointer<Void>, length: Int, encoding: NSStringEncoding, freeWhenDone flag: Bool)
139 |     /// *[Foundation]* Returns an initialized `String` object that contains a
140 |     /// given number of characters from a given array of Unicode
141 |     /// characters.
142 |     public init(utf16CodeUnits: UnsafePointer<unichar>, count: Int)
143 |     /// *[Foundation]* Returns an initialized `String` object that contains a given
144 |     /// number of characters from a given array of UTF-16 Code Units
145 |     public init(utf16CodeUnitsNoCopy: UnsafePointer<unichar>, count: Int, freeWhenDone flag: Bool)
146 |     /// *[Foundation]* Produces a string created by reading data from the file at a
147 |     /// given path interpreted using a given encoding.
148 |     public init(contentsOfFile path: String, encoding enc: NSStringEncoding) throws
149 |     /// *[Foundation]* Produces a string created by reading data from the file at
150 |     /// a given path and returns by reference the encoding used to
151 |     /// interpret the file.
152 |     public init(contentsOfFile path: String, usedEncoding: UnsafeMutablePointer<NSStringEncoding> = default) throws
153 |     /// *[Foundation]* Produces a string created by reading data from a given URL
154 |     /// interpreted using a given encoding.  Errors are written into the
155 |     /// inout `error` argument.
156 |     public init(contentsOfURL url: NSURL, encoding enc: NSStringEncoding) throws
157 |     /// *[Foundation]* Produces a string created by reading data from a given URL
158 |     /// and returns by reference the encoding used to interpret the
159 |     /// data.  Errors are written into the inout `error` argument.
160 |     public init(contentsOfURL url: NSURL, usedEncoding enc: UnsafeMutablePointer<NSStringEncoding> = default) throws
161 |     /// *[Foundation]* Produces a string containing the bytes in a given C array,
162 |     /// interpreted according to a given encoding.
163 |     public init?(CString: UnsafePointer<CChar>, encoding enc: NSStringEncoding)
164 |     /// *[Foundation]* Returns a `String` initialized by converting given `data` into
165 |     /// Unicode characters using a given `encoding`.
166 |     public init?(data: NSData, encoding: NSStringEncoding)
167 |     /// *[Foundation]* Returns a `String` object initialized by using a given
168 |     /// format string as a template into which the remaining argument
169 |     /// values are substituted.
170 |     public init(format: String, _ arguments: CVarArgType...)
171 |     /// *[Foundation]* Returns a `String` object initialized by using a given
172 |     /// format string as a template into which the remaining argument
173 |     /// values are substituted according to the user’s default locale.
174 |     public init(format: String, arguments: [CVarArgType])
175 |     /// *[Foundation]* Returns a `String` object initialized by using a given
176 |     /// format string as a template into which the remaining argument
177 |     /// values are substituted according to given locale information.
178 |     public init(format: String, locale: NSLocale?, _ args: CVarArgType...)
179 |     /// *[Foundation]* Returns a `String` object initialized by using a given
180 |     /// format string as a template into which the remaining argument
181 |     /// values are substituted according to given locale information.
182 |     public init(format: String, locale: NSLocale?, arguments: [CVarArgType])
183 |     /// *[Foundation]* Returns the number of bytes required to store the
184 |     /// `String` in a given encoding.
185 |     @warn_unused_result
186 |     public func lengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
187 |     /// *[Foundation]* Returns the range of characters representing the line or lines
188 |     /// containing a given range.
189 |     @warn_unused_result
190 |     public func lineRangeForRange(aRange: Range<Index>) -> Range<Index>
191 |     /// *[Foundation]* Returns an array of linguistic tags for the specified
192 |     /// range and requested tags within the receiving string.
193 |     @warn_unused_result
194 |     public func linguisticTagsInRange(range: Range<Index>, scheme tagScheme: String, options opts: NSLinguisticTaggerOptions = default, orthography: NSOrthography? = default, tokenRanges: UnsafeMutablePointer<[Range<Index>]> = default) -> [String]
195 |     /// *[Foundation]* Compares the string and a given string using a
196 |     /// case-insensitive, localized, comparison.
197 |     @warn_unused_result
198 |     public func localizedCaseInsensitiveCompare(aString: String) -> NSComparisonResult
199 |     /// *[Foundation]* Compares the string and a given string using a localized
200 |     /// comparison.
201 |     @warn_unused_result
202 |     public func localizedCompare(aString: String) -> NSComparisonResult
203 |     /// *[Foundation]* Compares strings as sorted by the Finder.
204 |     @warn_unused_result
205 |     public func localizedStandardCompare(string: String) -> NSComparisonResult
206 |     /// *[Foundation]* A lowercase version of the string that is produced using the current
207 |     /// locale.
208 |     public var localizedLowercaseString: String { get }
209 |     /// *[Foundation]* Returns a version of the string with all letters
210 |     /// converted to lowercase, taking into account the specified
211 |     /// locale.
212 |     @warn_unused_result
213 |     public func lowercaseStringWithLocale(locale: NSLocale?) -> String
214 |     /// *[Foundation]* Returns the maximum number of bytes needed to store the
215 |     /// `String` in a given encoding.
216 |     @warn_unused_result
217 |     public func maximumLengthOfBytesUsingEncoding(encoding: NSStringEncoding) -> Int
218 |     /// *[Foundation]* Returns the range of characters representing the
219 |     /// paragraph or paragraphs containing a given range.
220 |     @warn_unused_result
221 |     public func paragraphRangeForRange(aRange: Range<Index>) -> Range<Index>
222 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
223 |     /// contents using Form C.
224 |     public var precomposedStringWithCanonicalMapping: String { get }
225 |     /// *[Foundation]* Returns a string made by normalizing the `String`’s
226 |     /// contents using Form KC.
227 |     public var precomposedStringWithCompatibilityMapping: String { get }
228 |     /// *[Foundation]* Parses the `String` as a text representation of a
229 |     /// property list, returning an NSString, NSData, NSArray, or
230 |     /// NSDictionary object, according to the topmost element.
231 |     @warn_unused_result
232 |     public func propertyList() -> AnyObject
233 |     /// *[Foundation]* Returns a dictionary object initialized with the keys and
234 |     /// values found in the `String`.
235 |     @warn_unused_result
236 |     public func propertyListFromStringsFileFormat() -> [String : String]
237 |     /// *[Foundation]* Finds and returns the range in the `String` of the first
238 |     /// character from a given character set found in a given range with
239 |     /// given options.
240 |     @warn_unused_result
241 |     public func rangeOfCharacterFromSet(aSet: NSCharacterSet, options mask: NSStringCompareOptions = default, range aRange: Range<Index>? = default) -> Range<Index>?
242 |     /// *[Foundation]* Returns the range in the `String` of the composed
243 |     /// character sequence located at a given index.
244 |     @warn_unused_result
245 |     public func rangeOfComposedCharacterSequenceAtIndex(anIndex: Index) -> Range<Index>
246 |     /// *[Foundation]* Returns the range in the string of the composed character
247 |     /// sequences for a given range.
248 |     @warn_unused_result
249 |     public func rangeOfComposedCharacterSequencesForRange(range: Range<Index>) -> Range<Index>
250 |     /// *[Foundation]* Finds and returns the range of the first occurrence of a
251 |     /// given string within a given range of the `String`, subject to
252 |     /// given options, using the specified locale, if any.
253 |     @warn_unused_result
254 |     public func rangeOfString(aString: String, options mask: NSStringCompareOptions = default, range searchRange: Range<Index>? = default, locale: NSLocale? = default) -> Range<Index>?
255 |     /// *[Foundation]* Returns `true` if `self` contains `string`, taking the current locale
256 |     /// into account.
257 |     ///
258 |     /// This is the most appropriate method for doing user-level string searches,
259 |     /// similar to how searches are done generally in the system.  The search is
260 |     /// locale-aware, case and diacritic insensitive.  The exact list of search
261 |     /// options applied may change over time.
262 |     @warn_unused_result
263 |     public func localizedStandardContainsString(string: String) -> Bool
264 |     /// *[Foundation]* Finds and returns the range of the first occurrence of a given string,
265 |     /// taking the current locale into account.  Returns `nil` if the string was
266 |     /// not found.
267 |     ///
268 |     /// This is the most appropriate method for doing user-level string searches,
269 |     /// similar to how searches are done generally in the system.  The search is
270 |     /// locale-aware, case and diacritic insensitive.  The exact list of search
271 |     /// options applied may change over time.
272 |     @warn_unused_result
273 |     public func localizedStandardRangeOfString(string: String) -> Range<Index>?
274 |     /// *[Foundation]* Returns the smallest encoding to which the `String` can
275 |     /// be converted without loss of information.
276 |     public var smallestEncoding: NSStringEncoding { get }
277 |     /// *[Foundation]* Returns a new string made from the `String` by replacing
278 |     /// all characters not in the specified set with percent encoded
279 |     /// characters.
280 |     @warn_unused_result
281 |     public func stringByAddingPercentEncodingWithAllowedCharacters(allowedCharacters: NSCharacterSet) -> String?
282 |     /// *[Foundation]* Returns a representation of the `String` using a given
283 |     /// encoding to determine the percent escapes necessary to convert
284 |     /// the `String` into a legal URL string.
285 |     @available(*, deprecated, message="Use stringByAddingPercentEncodingWithAllowedCharacters(_:) instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.")
286 |     public func stringByAddingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
287 |     /// *[Foundation]* Returns a string made by appending to the `String` a
288 |     /// string constructed from a given format string and the following
289 |     /// arguments.
290 |     @warn_unused_result
291 |     public func stringByAppendingFormat(format: String, _ arguments: CVarArgType...) -> String
292 |     /// *[Foundation]* Returns a new string made by appending a given string to
293 |     /// the `String`.
294 |     @warn_unused_result
295 |     public func stringByAppendingString(aString: String) -> String
296 |     /// *[Foundation]* Returns a string with the given character folding options
297 |     /// applied.
298 |     @warn_unused_result
299 |     public func stringByFoldingWithOptions(options: NSStringCompareOptions, locale: NSLocale?) -> String
300 |     /// *[Foundation]* Returns a new string formed from the `String` by either
301 |     /// removing characters from the end, or by appending as many
302 |     /// occurrences as necessary of a given pad string.
303 |     @warn_unused_result
304 |     public func stringByPaddingToLength(newLength: Int, withString padString: String, startingAtIndex padIndex: Int) -> String
305 |     /// *[Foundation]* Returns a new string made from the `String` by replacing
306 |     /// all percent encoded sequences with the matching UTF-8
307 |     /// characters.
308 |     public var stringByRemovingPercentEncoding: String? { get }
309 |     /// *[Foundation]* Returns a new string in which the characters in a
310 |     /// specified range of the `String` are replaced by a given string.
311 |     @warn_unused_result
312 |     public func stringByReplacingCharactersInRange(range: Range<Index>, withString replacement: String) -> String
313 |     /// *[Foundation]* Returns a new string in which all occurrences of a target
314 |     /// string in a specified range of the `String` are replaced by
315 |     /// another given string.
316 |     @warn_unused_result
317 |     public func stringByReplacingOccurrencesOfString(target: String, withString replacement: String, options: NSStringCompareOptions = default, range searchRange: Range<Index>? = default) -> String
318 |     /// *[Foundation]* Returns a new string made by replacing in the `String`
319 |     /// all percent escapes with the matching characters as determined
320 |     /// by a given encoding.
321 |     @available(*, deprecated, message="Use stringByRemovingPercentEncoding instead, which always uses the recommended UTF-8 encoding.")
322 |     public func stringByReplacingPercentEscapesUsingEncoding(encoding: NSStringEncoding) -> String?
323 |     /// *[Foundation]* Returns a new string made by removing from both ends of
324 |     /// the `String` characters contained in a given character set.
325 |     @warn_unused_result
326 |     public func stringByTrimmingCharactersInSet(set: NSCharacterSet) -> String
327 |     /// *[Foundation]* Returns a new string containing the characters of the
328 |     /// `String` from the one at a given index to the end.
329 |     @warn_unused_result
330 |     public func substringFromIndex(index: Index) -> String
331 |     /// *[Foundation]* Returns a new string containing the characters of the
332 |     /// `String` up to, but not including, the one at a given index.
333 |     @warn_unused_result
334 |     public func substringToIndex(index: Index) -> String
335 |     /// *[Foundation]* Returns a string object containing the characters of the
336 |     /// `String` that lie within a given range.
337 |     @warn_unused_result
338 |     public func substringWithRange(aRange: Range<Index>) -> String
339 |     /// *[Foundation]* An uppercase version of the string that is produced using the current
340 |     /// locale.
341 |     public var localizedUppercaseString: String { get }
342 |     /// *[Foundation]* Returns a version of the string with all letters
343 |     /// converted to uppercase, taking into account the specified
344 |     /// locale.
345 |     @warn_unused_result
346 |     public func uppercaseStringWithLocale(locale: NSLocale?) -> String
347 |     /// *[Foundation]* Writes the contents of the `String` to a file at a given
348 |     /// path using a given encoding.
349 |     public func writeToFile(path: String, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding) throws
350 |     /// *[Foundation]* Writes the contents of the `String` to the URL specified
351 |     /// by url using the specified encoding.
352 |     public func writeToURL(url: NSURL, atomically useAuxiliaryFile: Bool, encoding enc: NSStringEncoding) throws
353 |     /// *[Foundation]* Perform string transliteration.
354 |     @warn_unused_result
355 |     public func stringByApplyingTransform(transform: String, reverse: Bool) -> String?
356 |     /// *[Foundation]* Returns `true` iff `other` is non-empty and contained within
357 |     /// `self` by case-sensitive, non-literal search.
358 |     ///
359 |     /// Equivalent to `self.rangeOfString(other) != nil`
360 |     @warn_unused_result
361 |     public func containsString(other: String) -> Bool
362 |     /// *[Foundation]* Returns `true` iff `other` is non-empty and contained within
363 |     /// `self` by case-insensitive, non-literal search, taking into
364 |     /// account the current locale.
365 |     ///
366 |     /// Locale-independent case-insensitive operation, and other needs,
367 |     /// can be achieved by calling
368 |     /// `rangeOfString(_:options:_,range:_locale:_)`.
369 |     ///
370 |     /// Equivalent to
371 |     ///
372 |     ///     self.rangeOfString(
373 |     ///       other, options: .CaseInsensitiveSearch,
374 |     ///       locale: NSLocale.currentLocale()) != nil
375 |     @warn_unused_result
376 |     public func localizedCaseInsensitiveContainsString(other: String) -> Bool
377 | }
378 | 
379 | extension String : _ObjectiveCBridgeable {
380 | }
381 | 
382 | extension String {
383 |     /// *[Foundation]*
384 |     public init(_ cocoaString: NSString)
385 | }
386 | 
387 | extension Float : _ObjectiveCBridgeable {
388 |     /// *[Foundation]*
389 |     public init(_ number: NSNumber)
390 | }
391 | 
392 | extension Dictionary : _ObjectiveCBridgeable {
393 | }
394 | 
395 | extension Set : _ObjectiveCBridgeable {
396 | }
397 | 
398 | extension Double : _ObjectiveCBridgeable {
399 |     /// *[Foundation]*
400 |     public init(_ number: NSNumber)
401 | }
402 | 
403 | 


--------------------------------------------------------------------------------
/data/addenda/3.0/foundation.txt:
--------------------------------------------------------------------------------
  1 | extension String {
  2 |     /// *[Foundation]*
  3 |     /// Returns an Array of the encodings string objects support
  4 |     /// in the application's environment.
  5 |     public static func availableStringEncodings() -> [String.Encoding]
  6 | 
  7 |     /// *[Foundation]*
  8 |     /// Returns the C-string encoding assumed for any method accepting
  9 |     /// a C string as an argument.
 10 |     public static func defaultCStringEncoding() -> String.Encoding
 11 | 
 12 |     /// *[Foundation]*
 13 |     /// Returns a human-readable string giving the name of a given encoding.
 14 |     public static func localizedName(of encoding: String.Encoding) -> String
 15 | 
 16 |     /// *[Foundation]*
 17 |     /// Returns a string created by using a given format string as a
 18 |     /// template into which the remaining argument values are substituted
 19 |     /// according to the user's default locale.
 20 |     public static func localizedStringWithFormat(_ format: String, _ arguments: CVarArg...) -> String
 21 | 
 22 |     /// *[Foundation]*
 23 |     /// Produces a string created by copying the data from a given
 24 |     /// C array of UTF8-encoded bytes.
 25 |     public init?(utf8String bytes: UnsafePointer<CChar>)
 26 | 
 27 |     /// *[Foundation]*
 28 |     /// Returns a Boolean value that indicates whether the
 29 |     /// `String` can be converted to a given encoding without loss of
 30 |     /// information.
 31 |     public func canBeConverted(to encoding: String.Encoding) -> Bool
 32 | 
 33 |     /// *[Foundation]*
 34 |     /// Produce a string with the first character from each word changed
 35 |     /// to the corresponding uppercase value.
 36 |     public var capitalized: String { get }
 37 | 
 38 |     /// *[Foundation]*
 39 |     /// A capitalized representation of the `String` that is produced
 40 |     /// using the current locale.
 41 |     public var localizedCapitalized: String { get }
 42 | 
 43 |     /// *[Foundation]*
 44 |     /// Returns a capitalized representation of the `String`
 45 |     /// using the specified locale.
 46 |     public func capitalized(with locale: Locale?) -> String
 47 | 
 48 |     /// *[Foundation]*
 49 |     /// Returns the result of invoking `compare:options:` with
 50 |     /// `NSCaseInsensitiveSearch` as the only option.
 51 |     public func caseInsensitiveCompare(_ aString: String) -> ComparisonResult
 52 | 
 53 |     /// *[Foundation]*
 54 |     /// Returns a string containing characters the `String` and a
 55 |     /// given string have in common, starting from the beginning of each
 56 |     /// up to the first characters that aren't equivalent.
 57 |     public func commonPrefix(with aString: String, options: CompareOptions = default) -> String
 58 | 
 59 |     /// *[Foundation]*
 60 |     /// Compares the string using the specified options and
 61 |     /// returns the lexical ordering for the range.
 62 |     public func compare(_ aString: String, options mask: CompareOptions = default, range: Range<Index>? = default, locale: Locale? = default) -> ComparisonResult
 63 | 
 64 |     /// *[Foundation]*
 65 |     /// Interprets the `String` as a path in the file system and
 66 |     /// attempts to perform filename completion, returning a numeric
 67 |     /// value that indicates whether a match was possible, and by
 68 |     /// reference the longest path that matches the `String`.
 69 |     /// Returns the actual number of matching paths.
 70 |     public func completePath(into outputName: UnsafeMutablePointer<String>? = default, caseSensitive: Bool, matchesInto outputArray: UnsafeMutablePointer<[String]>? = default, filterTypes: [String]? = default) -> Int
 71 | 
 72 |     /// *[Foundation]*
 73 |     /// Returns an array containing substrings from the `String`
 74 |     /// that have been divided by characters in a given set.
 75 |     public func components(separatedBy separator: CharacterSet) -> [String]
 76 | 
 77 |     /// *[Foundation]*
 78 |     /// Returns an array containing substrings from the `String`
 79 |     /// that have been divided by a given separator.
 80 |     public func components(separatedBy separator: String) -> [String]
 81 | 
 82 |     /// *[Foundation]*
 83 |     /// Returns a representation of the `String` as a C string
 84 |     /// using a given encoding.
 85 |     public func cString(using encoding: String.Encoding) -> [CChar]?
 86 | 
 87 |     /// *[Foundation]*
 88 |     /// Returns a `Data` containing a representation of
 89 |     /// the `String` encoded using a given encoding.
 90 |     public func data(using encoding: String.Encoding, allowLossyConversion: Bool = default) -> Data?
 91 | 
 92 |     /// *[Foundation]*
 93 |     /// Returns a string made by normalizing the `String`'s
 94 |     /// contents using Form D.
 95 |     public var decomposedStringWithCanonicalMapping: String { get }
 96 | 
 97 |     /// *[Foundation]*
 98 |     /// Returns a string made by normalizing the `String`'s
 99 |     /// contents using Form KD.
100 |     public var decomposedStringWithCompatibilityMapping: String { get }
101 | 
102 |     /// *[Foundation]*
103 |     /// Enumerates all the lines in a string.
104 |     public func enumerateLines(_ body: (line: String, stop: inout Bool) -> ())
105 | 
106 |     /// *[Foundation]*
107 |     /// Performs linguistic analysis on the specified string by
108 |     /// enumerating the specific range of the string, providing the
109 |     /// Block with the located tags.
110 |     public func enumerateLinguisticTags(in range: Range<Index>, scheme tagScheme: String, options opts: NSLinguisticTagger.Options = default, orthography: NSOrthography? = default, _ body: (String, Range<Index>, Range<Index>, inout Bool) -> ())
111 | 
112 |     /// *[Foundation]*
113 |     /// Enumerates the substrings of the specified type in the
114 |     /// specified range of the string.
115 |     public func enumerateSubstrings(in range: Range<Index>, options opts: EnumerationOptions = default, _ body: (substring: String?, substringRange: Range<Index>, enclosingRange: Range<Index>, inout Bool) -> ())
116 | 
117 |     /// *[Foundation]*
118 |     /// Returns the fastest encoding to which the `String` may be
119 |     /// converted without loss of information.
120 |     public var fastestEncoding: String.Encoding { get }
121 | 
122 |     /// *[Foundation]*
123 |     /// Writes the given `range` of characters into `buffer` in a given
124 |     /// `encoding`, without any allocations.  Does not NULL-terminate.
125 |     ///
126 |     /// - Parameter buffer: A buffer into which to store the bytes from
127 |     ///   the receiver. The returned bytes are not NUL-terminated.
128 |     ///
129 |     /// - Parameter maxBufferCount: The maximum number of bytes to write
130 |     ///   to buffer.
131 |     ///
132 |     /// - Parameter usedBufferCount: The number of bytes used from
133 |     ///   buffer. Pass `nil` if you do not need this value.
134 |     ///
135 |     /// - Parameter encoding: The encoding to use for the returned bytes.
136 |     ///
137 |     /// - Parameter options: A mask to specify options to use for
138 |     ///   converting the receiver's contents to `encoding` (if conversion
139 |     ///   is necessary).
140 |     ///
141 |     /// - Parameter range: The range of characters in the receiver to get.
142 |     ///
143 |     /// - Parameter leftover: The remaining range. Pass `nil` If you do
144 |     ///   not need this value.
145 |     ///
146 |     /// - Returns: `true` iff some characters were converted.
147 |     ///
148 |     /// - Note: Conversion stops when the buffer fills or when the
149 |     ///   conversion isn't possible due to the chosen encoding.
150 |     ///
151 |     /// - Note: will get a maximum of `min(buffer.count, maxLength)` bytes.
152 |     public func getBytes(_ buffer: inout [UInt8], maxLength maxBufferCount: Int, usedLength usedBufferCount: UnsafeMutablePointer<Int>, encoding: String.Encoding, options: EncodingConversionOptions = default, range: Range<Index>, remaining leftover: UnsafeMutablePointer<Range<Index>>) -> Bool
153 | 
154 |     /// *[Foundation]*
155 |     /// Converts the `String`'s content to a given encoding and
156 |     /// stores them in a buffer.
157 |     /// - Note: will store a maximum of `min(buffer.count, maxLength)` bytes.
158 |     public func getCString(_ buffer: inout [CChar], maxLength: Int, encoding: String.Encoding) -> Bool
159 | 
160 |     /// *[Foundation]*
161 |     /// Returns by reference the beginning of the first line and
162 |     /// the end of the last line touched by the given range.
163 |     public func getLineStart(_ start: UnsafeMutablePointer<Index>, end: UnsafeMutablePointer<Index>, contentsEnd: UnsafeMutablePointer<Index>, for range: Range<Index>)
164 | 
165 |     /// *[Foundation]*
166 |     /// Returns by reference the beginning of the first paragraph
167 |     /// and the end of the last paragraph touched by the given range.
168 |     public func getParagraphStart(_ start: UnsafeMutablePointer<Index>, end: UnsafeMutablePointer<Index>, contentsEnd: UnsafeMutablePointer<Index>, for range: Range<Index>)
169 | 
170 |     /// *[Foundation]*
171 |     /// An unsigned integer that can be used as a hash table address.
172 |     public var hash: Int { get }
173 | 
174 |     /// *[Foundation]*
175 |     /// Produces an initialized `NSString` object equivalent to the given
176 |     /// `bytes` interpreted in the given `encoding`.
177 |     public init?<S : Sequence where S.Iterator.Element == UInt8>(bytes: S, encoding: String.Encoding)
178 | 
179 |     /// *[Foundation]*
180 |     /// Produces an initialized `String` object that contains a
181 |     /// given number of bytes from a given buffer of bytes interpreted
182 |     /// in a given encoding, and optionally frees the buffer.  WARNING:
183 |     /// this initializer is not memory-safe!
184 |     public init?(bytesNoCopy bytes: UnsafeMutablePointer<Swift.Void>, length: Int, encoding: String.Encoding, freeWhenDone flag: Bool)
185 | 
186 |     /// *[Foundation]*
187 |     /// Returns an initialized `String` object that contains a
188 |     /// given number of characters from a given array of Unicode
189 |     /// characters.
190 |     public init(utf16CodeUnits: UnsafePointer<unichar>, count: Int)
191 | 
192 |     /// *[Foundation]*
193 |     /// Returns an initialized `String` object that contains a given
194 |     /// number of characters from a given array of UTF-16 Code Units
195 |     public init(utf16CodeUnitsNoCopy: UnsafePointer<unichar>, count: Int, freeWhenDone flag: Bool)
196 | 
197 |     /// *[Foundation]*
198 |     /// Produces a string created by reading data from the file at a
199 |     /// given path interpreted using a given encoding.
200 |     public init(contentsOfFile path: String, encoding enc: String.Encoding) throws
201 | 
202 |     /// *[Foundation]*
203 |     /// Produces a string created by reading data from the file at
204 |     /// a given path and returns by reference the encoding used to
205 |     /// interpret the file.
206 |     public init(contentsOfFile path: String, usedEncoding: inout String.Encoding) throws
207 | 
208 |     /// *[Foundation]*
209 |     public init(contentsOfFile path: String) throws
210 | 
211 |     /// *[Foundation]*
212 |     /// Produces a string created by reading data from a given URL
213 |     /// interpreted using a given encoding.  Errors are written into the
214 |     /// inout `error` argument.
215 |     public init(contentsOf url: URL, encoding enc: String.Encoding) throws
216 | 
217 |     /// *[Foundation]*
218 |     /// Produces a string created by reading data from a given URL
219 |     /// and returns by reference the encoding used to interpret the
220 |     /// data.  Errors are written into the inout `error` argument.
221 |     public init(contentsOf url: URL, usedEncoding: inout String.Encoding) throws
222 | 
223 |     /// *[Foundation]*
224 |     public init(contentsOf url: URL) throws
225 | 
226 |     /// *[Foundation]*
227 |     /// Produces a string containing the bytes in a given C array,
228 |     /// interpreted according to a given encoding.
229 |     public init?(cString: UnsafePointer<CChar>, encoding enc: String.Encoding)
230 | 
231 |     /// *[Foundation]*
232 |     /// Returns a `String` initialized by converting given `data` into
233 |     /// Unicode characters using a given `encoding`.
234 |     public init?(data: Data, encoding: String.Encoding)
235 | 
236 |     /// *[Foundation]*
237 |     /// Returns a `String` object initialized by using a given
238 |     /// format string as a template into which the remaining argument
239 |     /// values are substituted.
240 |     public init(format: String, _ arguments: CVarArg...)
241 | 
242 |     /// *[Foundation]*
243 |     /// Returns a `String` object initialized by using a given
244 |     /// format string as a template into which the remaining argument
245 |     /// values are substituted according to the user's default locale.
246 |     public init(format: String, arguments: [CVarArg])
247 | 
248 |     /// *[Foundation]*
249 |     /// Returns a `String` object initialized by using a given
250 |     /// format string as a template into which the remaining argument
251 |     /// values are substituted according to given locale information.
252 |     public init(format: String, locale: Locale?, _ args: CVarArg...)
253 | 
254 |     /// *[Foundation]*
255 |     /// Returns a `String` object initialized by using a given
256 |     /// format string as a template into which the remaining argument
257 |     /// values are substituted according to given locale information.
258 |     public init(format: String, locale: Locale?, arguments: [CVarArg])
259 | 
260 |     /// *[Foundation]*
261 |     /// Returns the number of bytes required to store the
262 |     /// `String` in a given encoding.
263 |     public func lengthOfBytes(using encoding: String.Encoding) -> Int
264 | 
265 |     /// *[Foundation]*
266 |     /// Returns the range of characters representing the line or lines
267 |     /// containing a given range.
268 |     public func lineRange(for aRange: Range<Index>) -> Range<Index>
269 | 
270 |     /// *[Foundation]*
271 |     /// Returns an array of linguistic tags for the specified
272 |     /// range and requested tags within the receiving string.
273 |     public func linguisticTags(in range: Range<Index>, scheme tagScheme: String, options opts: NSLinguisticTagger.Options = default, orthography: NSOrthography? = default, tokenRanges: UnsafeMutablePointer<[Range<Index>]>? = default) -> [String]
274 | 
275 |     /// *[Foundation]*
276 |     /// Compares the string and a given string using a
277 |     /// case-insensitive, localized, comparison.
278 |     public func localizedCaseInsensitiveCompare(_ aString: String) -> ComparisonResult
279 | 
280 |     /// *[Foundation]*
281 |     /// Compares the string and a given string using a localized
282 |     /// comparison.
283 |     public func localizedCompare(_ aString: String) -> ComparisonResult
284 | 
285 |     /// *[Foundation]*
286 |     /// Compares strings as sorted by the Finder.
287 |     public func localizedStandardCompare(_ string: String) -> ComparisonResult
288 | 
289 |     /// *[Foundation]*
290 |     /// A lowercase version of the string that is produced using the current
291 |     /// locale.
292 |     public var localizedLowercase: String { get }
293 | 
294 |     /// *[Foundation]*
295 |     /// Returns a version of the string with all letters
296 |     /// converted to lowercase, taking into account the specified
297 |     /// locale.
298 |     public func lowercased(with locale: Locale?) -> String
299 | 
300 |     /// *[Foundation]*
301 |     /// Returns the maximum number of bytes needed to store the
302 |     /// `String` in a given encoding.
303 |     public func maximumLengthOfBytes(using encoding: String.Encoding) -> Int
304 | 
305 |     /// *[Foundation]*
306 |     /// Returns the range of characters representing the
307 |     /// paragraph or paragraphs containing a given range.
308 |     public func paragraphRange(for aRange: Range<Index>) -> Range<Index>
309 | 
310 |     /// *[Foundation]*
311 |     /// Returns a string made by normalizing the `String`'s
312 |     /// contents using Form C.
313 |     public var precomposedStringWithCanonicalMapping: String { get }
314 | 
315 |     /// *[Foundation]*
316 |     /// Returns a string made by normalizing the `String`'s
317 |     /// contents using Form KC.
318 |     public var precomposedStringWithCompatibilityMapping: String { get }
319 | 
320 |     /// *[Foundation]*
321 |     /// Parses the `String` as a text representation of a
322 |     /// property list, returning an NSString, NSData, NSArray, or
323 |     /// NSDictionary object, according to the topmost element.
324 |     public func propertyList() -> AnyObject
325 | 
326 |     /// *[Foundation]*
327 |     /// Returns a dictionary object initialized with the keys and
328 |     /// values found in the `String`.
329 |     public func propertyListFromStringsFileFormat() -> [String : String]
330 | 
331 |     /// *[Foundation]*
332 |     /// Finds and returns the range in the `String` of the first
333 |     /// character from a given character set found in a given range with
334 |     /// given options.
335 |     public func rangeOfCharacter(from aSet: CharacterSet, options mask: CompareOptions = default, range aRange: Range<Index>? = default) -> Range<Index>?
336 | 
337 |     /// *[Foundation]*
338 |     /// Returns the range in the `String` of the composed
339 |     /// character sequence located at a given index.
340 |     public func rangeOfComposedCharacterSequence(at anIndex: Index) -> Range<Index>
341 | 
342 |     /// *[Foundation]*
343 |     /// Returns the range in the string of the composed character
344 |     /// sequences for a given range.
345 |     public func rangeOfComposedCharacterSequences(for range: Range<Index>) -> Range<Index>
346 | 
347 |     /// *[Foundation]*
348 |     /// Finds and returns the range of the first occurrence of a
349 |     /// given string within a given range of the `String`, subject to
350 |     /// given options, using the specified locale, if any.
351 |     public func range(of aString: String, options mask: CompareOptions = default, range searchRange: Range<Index>? = default, locale: Locale? = default) -> Range<Index>?
352 | 
353 |     /// *[Foundation]*
354 |     /// Returns `true` if `self` contains `string`, taking the current locale
355 |     /// into account.
356 |     ///
357 |     /// This is the most appropriate method for doing user-level string searches,
358 |     /// similar to how searches are done generally in the system.  The search is
359 |     /// locale-aware, case and diacritic insensitive.  The exact list of search
360 |     /// options applied may change over time.
361 |     public func localizedStandardContains(_ string: String) -> Bool
362 | 
363 |     /// *[Foundation]*
364 |     /// Finds and returns the range of the first occurrence of a given string,
365 |     /// taking the current locale into account.  Returns `nil` if the string was
366 |     /// not found.
367 |     ///
368 |     /// This is the most appropriate method for doing user-level string searches,
369 |     /// similar to how searches are done generally in the system.  The search is
370 |     /// locale-aware, case and diacritic insensitive.  The exact list of search
371 |     /// options applied may change over time.
372 |     public func localizedStandardRange(of string: String) -> Range<Index>?
373 | 
374 |     /// *[Foundation]*
375 |     /// Returns the smallest encoding to which the `String` can
376 |     /// be converted without loss of information.
377 |     public var smallestEncoding: String.Encoding { get }
378 | 
379 |     /// *[Foundation]*
380 |     /// Returns a new string made from the `String` by replacing
381 |     /// all characters not in the specified set with percent encoded
382 |     /// characters.
383 |     public func addingPercentEncoding(withAllowedCharacters allowedCharacters: CharacterSet) -> String?
384 | 
385 |     /// *[Foundation]*
386 |     /// Returns a representation of the `String` using a given
387 |     /// encoding to determine the percent escapes necessary to convert
388 |     /// the `String` into a legal URL string.
389 |     @available(*, deprecated, message: "Use addingPercentEncoding(withAllowedCharacters:) instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.")
390 |     public func addingPercentEscapes(using encoding: String.Encoding) -> String?
391 | 
392 |     /// *[Foundation]*
393 |     /// Returns a string made by appending to the `String` a
394 |     /// string constructed from a given format string and the following
395 |     /// arguments.
396 |     public func appendingFormat(_ format: String, _ arguments: CVarArg...) -> String
397 | 
398 |     /// *[Foundation]*
399 |     /// Returns a new string made by appending a given string to
400 |     /// the `String`.
401 |     public func appending(_ aString: String) -> String
402 | 
403 |     /// *[Foundation]*
404 |     /// Returns a string with the given character folding options
405 |     /// applied.
406 |     public func folding(_ options: CompareOptions = default, locale: Locale?) -> String
407 | 
408 |     /// *[Foundation]*
409 |     /// Returns a new string formed from the `String` by either
410 |     /// removing characters from the end, or by appending as many
411 |     /// occurrences as necessary of a given pad string.
412 |     public func padding(toLength newLength: Int, withPad padString: String, startingAt padIndex: Int) -> String
413 | 
414 |     /// *[Foundation]*
415 |     /// Returns a new string made from the `String` by replacing
416 |     /// all percent encoded sequences with the matching UTF-8
417 |     /// characters.
418 |     public var removingPercentEncoding: String? { get }
419 | 
420 |     /// *[Foundation]*
421 |     /// Returns a new string in which the characters in a
422 |     /// specified range of the `String` are replaced by a given string.
423 |     public func replacingCharacters(in range: Range<Index>, with replacement: String) -> String
424 | 
425 |     /// *[Foundation]*
426 |     /// Returns a new string in which all occurrences of a target
427 |     /// string in a specified range of the `String` are replaced by
428 |     /// another given string.
429 |     public func replacingOccurrences(of target: String, with replacement: String, options: CompareOptions = default, range searchRange: Range<Index>? = default) -> String
430 | 
431 |     /// *[Foundation]*
432 |     /// Returns a new string made by replacing in the `String`
433 |     /// all percent escapes with the matching characters as determined
434 |     /// by a given encoding.
435 |     @available(*, deprecated, message: "Use removingPercentEncoding instead, which always uses the recommended UTF-8 encoding.")
436 |     public func replacingPercentEscapes(using encoding: String.Encoding) -> String?
437 | 
438 |     /// *[Foundation]*
439 |     /// Returns a new string made by removing from both ends of
440 |     /// the `String` characters contained in a given character set.
441 |     public func trimmingCharacters(in set: CharacterSet) -> String
442 | 
443 |     /// *[Foundation]*
444 |     /// Returns a new string containing the characters of the
445 |     /// `String` from the one at a given index to the end.
446 |     public func substring(from index: Index) -> String
447 | 
448 |     /// *[Foundation]*
449 |     /// Returns a new string containing the characters of the
450 |     /// `String` up to, but not including, the one at a given index.
451 |     public func substring(to index: Index) -> String
452 | 
453 |     /// *[Foundation]*
454 |     /// Returns a string object containing the characters of the
455 |     /// `String` that lie within a given range.
456 |     public func substring(with aRange: Range<Index>) -> String
457 | 
458 |     /// *[Foundation]*
459 |     /// An uppercase version of the string that is produced using the current
460 |     /// locale.
461 |     public var localizedUppercase: String { get }
462 | 
463 |     /// *[Foundation]*
464 |     /// Returns a version of the string with all letters
465 |     /// converted to uppercase, taking into account the specified
466 |     /// locale.
467 |     public func uppercased(with locale: Locale?) -> String
468 | 
469 |     /// *[Foundation]*
470 |     /// Writes the contents of the `String` to a file at a given
471 |     /// path using a given encoding.
472 |     public func write(toFile path: String, atomically useAuxiliaryFile: Bool, encoding enc: String.Encoding) throws
473 | 
474 |     /// *[Foundation]*
475 |     /// Writes the contents of the `String` to the URL specified
476 |     /// by url using the specified encoding.
477 |     public func write(to url: URL, atomically useAuxiliaryFile: Bool, encoding enc: String.Encoding) throws
478 | 
479 |     /// *[Foundation]*
480 |     /// Perform string transliteration.
481 |     public func applyingTransform(_ transform: StringTransform, reverse: Bool) -> String?
482 | 
483 |     /// *[Foundation]*
484 |     /// Returns `true` iff `other` is non-empty and contained within
485 |     /// `self` by case-sensitive, non-literal search.
486 |     ///
487 |     /// Equivalent to `self.rangeOfString(other) != nil`
488 |     public func contains(_ other: String) -> Bool
489 | 
490 |     /// *[Foundation]*
491 |     /// Returns `true` iff `other` is non-empty and contained within
492 |     /// `self` by case-insensitive, non-literal search, taking into
493 |     /// account the current locale.
494 |     ///
495 |     /// Locale-independent case-insensitive operation, and other needs,
496 |     /// can be achieved by calling
497 |     /// `rangeOfString(_:options:_, range:_locale:_)`.
498 |     ///
499 |     /// Equivalent to
500 |     ///
501 |     ///     self.rangeOf(
502 |     ///       other, options: .CaseInsensitiveSearch,
503 |     ///       locale: Locale.current()) != nil
504 |     public func localizedCaseInsensitiveContains(_ other: String) -> Bool
505 | }
506 | 
507 | extension String {
508 |     /// *[Foundation]*
509 |     public init(_ cocoaString: NSString)
510 | }
511 | 
512 | extension Bool {
513 |     /// *[Foundation]*
514 |     public init(_ number: NSNumber)
515 | }
516 | 
517 | extension Double {
518 |     /// *[Foundation]*
519 |     public init(_ number: NSNumber)
520 | }
521 | 
522 | extension UInt {
523 |     /// *[Foundation]*
524 |     public init(_ number: NSNumber)
525 | }
526 | 
527 | extension String.UTF16View.Index : Strideable {
528 |     /// *[Foundation]*
529 |     /// Construct from an integer offset.
530 |     public init(_ offset: Int)
531 | 
532 |     /// *[Foundation]*
533 |     /// Returns a stride `x` such that `self.advanced(by: x)` approximates
534 |     /// `other`.
535 |     ///
536 |     /// If `Stride` conforms to `Integer`, then `self.advanced(by: x) == other`.
537 |     ///
538 |     /// - Complexity: O(1).
539 |     public func distance(to other: String.UTF16View.Index) -> Int
540 | 
541 |     /// *[Foundation]*
542 |     /// Returns a `Self` `x` such that `self.distance(to: x)` approximates `n`.
543 |     ///
544 |     /// If `Stride` conforms to `Integer`, then `self.distance(to: x) == n`.
545 |     ///
546 |     /// - Complexity: O(1).
547 |     public func advanced(by n: Int) -> String.UTF16View.Index
548 | }
549 | 
550 | extension Float {
551 |     /// *[Foundation]*
552 |     public init(_ number: NSNumber)
553 | }
554 | extension Int {
555 |     /// *[Foundation]*
556 |     public init(_ number: NSNumber)
557 | }
558 | 
559 | 


--------------------------------------------------------------------------------
/test/data/ok.txt:
--------------------------------------------------------------------------------
   1 | infix operator + {
   2 |     associativity left
   3 |     precedence 140
   4 | }
   5 | 
   6 | prefix operator ++ {
   7 | }
   8 | 
   9 | infix operator == {
  10 |     associativity none
  11 |     precedence 130
  12 | }
  13 | 
  14 | func +(lhs: Int, rhs: Int) -> Int
  15 | 
  16 | func +<C : _ExtensibleCollectionType, S : SequenceType where S.Generator.Element == S.Generator.Element>(lhs: C, rhs: S) -> C
  17 | 
  18 | func +<T : Strideable>(lhs: T.Stride, rhs: T) -> T
  19 | 
  20 | func +<T : Strideable>(lhs: T, rhs: T.Stride) -> T
  21 | 
  22 | prefix func ++(inout x: Int) -> Int
  23 | 
  24 | func ==(lhs: Int, rhs: Int) -> Bool
  25 | 
  26 | func ==(lhs: Bool, rhs: Bool) -> Bool
  27 | 
  28 | /// Returns true if these arrays contain the same elements.
  29 | func ==<T : Equatable>(lhs: [T], rhs: [T]) -> Bool
  30 | 
  31 | 
  32 | 
  33 | /// The protocol to which all types implicitly conform
  34 | typealias Any = protocol<>
  35 | 
  36 | 
  37 | /// The protocol to which all class types implicitly conform.
  38 | ///
  39 | /// When used as a concrete type, all known `@objc` `class` methods and
  40 | /// properties are available, as implicitly-unwrapped-optional methods
  41 | /// and properties respectively, on each instance of `AnyClass`. For
  42 | /// example:
  43 | ///
  44 | /// .. parsed-literal:
  45 | ///
  46 | ///   class C {
  47 | ///     @objc class var cValue: Int { return 42 }
  48 | ///   }
  49 | ///
  50 | ///   // If x has an @objc cValue: Int, return its value.  
  51 | ///   // Otherwise, return nil.
  52 | ///   func getCValue(x: AnyClass) -> Int? {
  53 | ///     return **x.cValue**
  54 | ///   }
  55 | ///
  56 | /// See also: `AnyObject`
  57 | typealias AnyClass = AnyObject.Type
  58 | 
  59 | 
  60 | /// The protocol to which all classes implicitly conform.
  61 | ///
  62 | /// When used as a concrete type, all known `@objc` methods and
  63 | /// properties are available, as implicitly-unwrapped-optional methods
  64 | /// and properties respectively, on each instance of `AnyObject`.  For
  65 | /// example:
  66 | ///
  67 | /// .. parsed-literal:
  68 | ///
  69 | ///   class C {
  70 | ///     @objc func getCValue() -> Int { return 42 }
  71 | ///   }
  72 | ///
  73 | ///   // If x has a method @objc getValue()->Int, call it and
  74 | ///   // return the result.  Otherwise, return nil.
  75 | ///   func getCValue1(x: AnyObject) -> Int? {
  76 | ///     if let f: ()->Int = **x.getCValue** {
  77 | ///       return f()
  78 | ///     }
  79 | ///     return nil
  80 | ///   }
  81 | ///
  82 | ///   // A more idiomatic implementation using "optional chaining"
  83 | ///   func getCValue2(x: AnyObject) -> Int? {
  84 | ///     return **x.getCValue?()**
  85 | ///   }
  86 | ///
  87 | ///   // An implementation that assumes the required method is present
  88 | ///   func getCValue3(x: AnyObject) -> **Int** {
  89 | ///     return **x.getCValue()** // x.getCValue is implicitly unwrapped.
  90 | ///   }
  91 | ///
  92 | /// See also: `AnyClass`
  93 | @objc protocol AnyObject {
  94 | }
  95 | 
  96 | 
  97 | /// Conceptually_, `Array` is an efficient, tail-growable random-access
  98 | /// collection of arbitrary elements.
  99 | ///
 100 | /// Common Properties of Array Types
 101 | /// ================================
 102 | ///
 103 | /// The information in this section applies to all three of Swift's
 104 | /// array types, `Array<T>`, `ContiguousArray<T>`, and `Slice<T>`.
 105 | /// When you read the word "array" here in a normal typeface, it
 106 | /// applies to all three of them.
 107 | ///
 108 | /// Value Semantics
 109 | /// ---------------
 110 | ///
 111 | /// Each array variable, `let` binding, or stored property has an
 112 | /// independent value that includes the values of all of its elements.
 113 | /// Therefore, mutations to the array are not observable through its
 114 | /// copies::
 115 | ///
 116 | ///   var a = [1, 2, 3]
 117 | ///   var b = a
 118 | ///   b[0] = 4
 119 | ///   println("a=\(a), b=\(b)")     // a=[1, 2, 3], b=[4, 2, 3]
 120 | ///
 121 | /// (Of course, if the array stores `class` references, the objects
 122 | /// are shared; only the values of the references are independent)
 123 | ///
 124 | /// Arrays use Copy-on-Write so that their storage and elements are
 125 | /// only copied lazily, upon mutation, when more than one array
 126 | /// instance is using the same buffer.  Therefore, the first in any
 127 | /// sequence of mutating operations may cost `O(N)` time and space,
 128 | /// where `N` is the length of the array.
 129 | ///
 130 | /// Growth and Capacity
 131 | /// -------------------
 132 | ///
 133 | /// When an array's contiguous storage fills up, new storage must be
 134 | /// allocated and elements must be moved to the new storage.  `Array`,
 135 | /// `ContiguousArray`, and `Slice` share an exponential growth
 136 | /// strategy that makes `append` a constant time operation *when
 137 | /// amortized over many invocations*.  In addition to a `count`
 138 | /// property, these array types have a `capacity` that reflects their
 139 | /// potential to store elements without reallocation, and when you
 140 | /// know how many elements you'll store, you can call
 141 | /// `reserveCapacity` to pre-emptively reallocate and prevent
 142 | /// intermediate reallocations.
 143 | ///
 144 | /// .. _Conceptually:
 145 | ///
 146 | /// Objective-C Bridge
 147 | /// ==================
 148 | ///
 149 | /// The main distinction between `Array` and the other array types is
 150 | /// that it interoperates seamlessly and efficiently with Objective-C.
 151 | ///
 152 | /// `Array<T>` is considered bridged to Objective-C iff `T` is bridged
 153 | /// to Objective-C.
 154 | ///
 155 | /// When `T` is a `class` or `@objc` protocol type, `Array` may store
 156 | /// its elements in an `NSArray`.  Since any arbitrary subclass of
 157 | /// `NSArray` can become an `Array`, there are no guarantees about
 158 | /// representation or efficiency in this case (see also
 159 | /// `ContiguousArray`).  Since `NSArray` is immutable, it is just as
 160 | /// though the storage was shared by some copy: the first in any
 161 | /// sequence of mutating operations causes elements to be copied into
 162 | /// unique, contiguous storage which may cost `O(N)` time and space,
 163 | /// where `N` is the length of the array (or more, if the underlying
 164 | /// `NSArray` is has unusual performance characteristics).
 165 | ///
 166 | /// Bridging to Objective-C
 167 | /// -----------------------
 168 | ///
 169 | /// Any bridged `Array` can be implicitly converted to an `NSArray`.
 170 | /// When `T` is a `class` or `@objc` protocol, bridging takes O(1)
 171 | /// time and O(1) space.  Other `Array`\ s must be bridged
 172 | /// element-by-element, allocating a new object for each element, at a
 173 | /// cost of at least O(`count`) time and space.
 174 | ///
 175 | /// Bridging from Objective-C
 176 | /// -------------------------
 177 | ///
 178 | /// An `NSArray` can be implicitly or explicitly converted to any
 179 | /// bridged `Array<T>`.  This conversion calls `copyWithZone` on the
 180 | /// `NSArray`, to ensure it won't be modified, and stores the result
 181 | /// in the `Array`.  Type-checking, to ensure the `NSArray`\ 's
 182 | /// elements match or can be bridged to `T`, is deferred until the
 183 | /// first element access.
 184 | struct Array<T> : MutableCollectionType, Sliceable {
 185 | 
 186 |     /// The type of element stored by this `Array`
 187 |     typealias Element = T
 188 | 
 189 |     /// Always zero, which is the index of the first element when non-empty.
 190 |     var startIndex: Int { get }
 191 | 
 192 |     /// A "past-the-end" element index; the successor of the last valid
 193 |     /// subscript argument.
 194 |     var endIndex: Int { get }
 195 |     subscript (index: Int) -> T
 196 | 
 197 |     /// Return a *generator* over the elements.
 198 |     ///
 199 |     /// Complexity: O(1)
 200 |     func generate() -> IndexingGenerator<[T]>
 201 | 
 202 |     /// A type that can represent a sub-range of an `Array` 
 203 |     typealias SubSlice = Slice<T>
 204 |     subscript (subRange: Range<Int>) -> Slice<T>
 205 | 
 206 |     /// Initialization from an existing buffer does not have "array.init"
 207 |     /// semantics because the caller may retain an alias to buffer.
 208 |     init(_ buffer: _ArrayBuffer<T>)
 209 | }
 210 | 
 211 | extension Array : ArrayLiteralConvertible {
 212 | 
 213 |     /// Create an instance containing `elements`.
 214 |     init(arrayLiteral elements: T...)
 215 | }
 216 | 
 217 | 
 218 | 
 219 | extension Array {
 220 | 
 221 |     /// Construct an empty Array
 222 |     init()
 223 | 
 224 |     /// Construct from an arbitrary sequence with elements of type `T`
 225 |     init<S : SequenceType where T == T>(_ s: S)
 226 | 
 227 |     /// Construct a Array of `count` elements, each initialized to
 228 |     /// `repeatedValue`.
 229 |     init(count: Int, repeatedValue: T)
 230 | 
 231 |     /// How many elements the Array stores
 232 |     var count: Int { get }
 233 | 
 234 |     /// How many elements the `Array` can store without reallocation
 235 |     var capacity: Int { get }
 236 | 
 237 |     /// `true` if and only if the `Array` is empty
 238 |     var isEmpty: Bool { get }
 239 | 
 240 |     /// The first element, or `nil` if the array is empty
 241 |     var first: T? { get }
 242 | 
 243 |     /// The last element, or `nil` if the array is empty
 244 |     var last: T? { get }
 245 | 
 246 |     /// Reserve enough space to store minimumCapacity elements.
 247 |     ///
 248 |     /// PostCondition: `capacity >= minimumCapacity` and the array has
 249 |     /// mutable contiguous storage.
 250 |     ///
 251 |     /// Complexity: O(`count`)
 252 |     mutating func reserveCapacity(minimumCapacity: Int)
 253 | 
 254 |     /// Append newElement to the Array
 255 |     ///
 256 |     /// Complexity: amortized O(1) unless `self`'s storage is shared with another live array; O(`count`) if `self` does not wrap a bridged `NSArray`; otherwise the efficiency is unspecified.
 257 |     mutating func append(newElement: T)
 258 | 
 259 |     /// Append the elements of `newElements` to `self`.
 260 |     ///
 261 |     /// Complexity: O(*length of result*) 
 262 |     /// 
 263 |     mutating func extend<S : SequenceType where T == T>(newElements: S)
 264 | 
 265 |     /// Remove an element from the end of the Array in O(1).
 266 |     /// Requires: count > 0
 267 |     mutating func removeLast() -> T
 268 | 
 269 |     /// Insert `newElement` at index `i`.
 270 |     ///
 271 |     /// Requires: `i <= count`
 272 |     ///
 273 |     /// Complexity: O(\ `count`\ ).
 274 |     mutating func insert(newElement: T, atIndex i: Int)
 275 | 
 276 |     /// Remove and return the element at index `i`
 277 |     ///
 278 |     /// Invalidates all indices with respect to `self`.
 279 |     ///
 280 |     /// Complexity: O(\ `count`\ ).
 281 |     mutating func removeAtIndex(index: Int) -> T
 282 | 
 283 |     /// Remove all elements.
 284 |     ///
 285 |     /// Postcondition: `capacity == 0` iff `keepCapacity` is `false`.
 286 |     ///
 287 |     /// Complexity: O(\ `countElements(self)`\ ).
 288 |     mutating func removeAll(keepCapacity: Bool = default)
 289 | 
 290 |     /// Interpose `self` between each consecutive pair of `elements`,
 291 |     /// and concatenate the elements of the resulting sequence.  For
 292 |     /// example, `[-1, -2].join([[1, 2, 3], [4, 5, 6], [7, 8, 9]])`
 293 |     /// yields `[1, 2, 3, -1, -2, 4, 5, 6, -1, -2, 7, 8, 9]`
 294 |     func join<S : SequenceType where [T] == [T]>(elements: S) -> [T]
 295 | 
 296 |     /// Return the result of repeatedly calling `combine` with an
 297 |     /// accumulated value initialized to `initial` and each element of
 298 |     /// `self`, in turn, i.e. return
 299 |     /// `combine(combine(...combine(combine(initial, self[0]),
 300 |     /// self[1]),...self[count-2]), self[count-1])`.
 301 |     func reduce<U>(initial: U, combine: (U, T) -> U) -> U
 302 | 
 303 |     /// Sort `self` in-place according to `isOrderedBefore`.  Requires:
 304 |     /// `isOrderedBefore` induces a `strict weak ordering
 305 |     /// <http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings>`__
 306 |     /// over the elements.
 307 |     mutating func sort(isOrderedBefore: (T, T) -> Bool)
 308 | 
 309 |     /// Return a copy of `self` that has been sorted according to
 310 |     /// `isOrderedBefore`.  Requires: `isOrderedBefore` induces a
 311 |     /// `strict weak ordering
 312 |     /// <http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings>`__
 313 |     /// over the elements.
 314 |     func sorted(isOrderedBefore: (T, T) -> Bool) -> [T]
 315 | 
 316 |     /// Return an `Array` containing the results of calling
 317 |     /// `transform(x)` on each element `x` of `self`
 318 |     func map<U>(transform: (T) -> U) -> [U]
 319 | 
 320 |     /// A Array containing the elements of `self` in reverse order
 321 |     func reverse() -> [T]
 322 | 
 323 |     /// Return an `Array` containing the elements `x` of `self` for which
 324 |     /// `includeElement(x)` is `true`
 325 |     func filter(includeElement: (T) -> Bool) -> [T]
 326 | }
 327 | 
 328 | 
 329 | 
 330 | /// Conforming types can be initialized with array literals
 331 | protocol ArrayLiteralConvertible {
 332 |     typealias Element
 333 | 
 334 |     /// Create an instance initialized with `elements`.
 335 |     init(arrayLiteral elements: Element...)
 336 | }
 337 | 
 338 | 
 339 | /// An *index* that can step backwards via application of its
 340 | /// `predecessor()` method.
 341 | protocol BidirectionalIndexType : ForwardIndexType, _BidirectionalIndexType {
 342 | }
 343 | 
 344 | 
 345 | /// A value type whose instances are either `true` or `false`.
 346 | struct Bool {
 347 | 
 348 |     /// Default-initialize Boolean value to `false`.
 349 |     init()
 350 | }
 351 | 
 352 | extension Bool : Equatable, Hashable {
 353 | 
 354 |     /// The hash value.
 355 |     ///
 356 |     /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
 357 |     ///
 358 |     /// **Note:** the hash value is not guaranteed to be stable across
 359 |     /// different invocations of the same program.  Do not persist the
 360 |     /// hash value across program runs.
 361 |     var hashValue: Int { get }
 362 | }
 363 | 
 364 | extension Bool : Reflectable {
 365 | 
 366 |     /// Returns a mirror that reflects `self`.
 367 |     func getMirror() -> MirrorType
 368 | }
 369 | 
 370 | 
 371 | /// The C '_Bool' and C++ 'bool' type.
 372 | typealias CBool = Bool
 373 | 
 374 | /// The C 'long' type.
 375 | typealias CLong = Int
 376 | 
 377 | 
 378 | /// A multi-pass *sequence* with addressable positions.
 379 | ///
 380 | /// Positions are represented by an associated `Index` type.  Whereas
 381 | /// an arbitrary *sequence* may be consumed as it is traversed, a
 382 | /// *collection* is multi-pass: any element may be revisited merely by
 383 | /// saving its index.
 384 | ///
 385 | /// The sequence view of the elements is identical to the collection
 386 | /// view.  In other words, the following code binds the same series of
 387 | /// values to `x` as does `for x in self {}`::
 388 | ///
 389 | ///   for i in startIndex..<endIndex {
 390 | ///     let x = self[i]
 391 | ///   }
 392 | protocol CollectionType : _CollectionType, SequenceType {
 393 |     subscript (position: Self.Index) -> Self.Generator.Element { get }
 394 | }
 395 | 
 396 | 
 397 | /// Instances of conforming types can be compared for value equality
 398 | /// using operators `==` and `!=`.
 399 | ///
 400 | /// When adopting `Equatable`, only the `==` operator is required to be
 401 | /// implemented.  The standard library provides an implementation for `!=`.
 402 | protocol Equatable {
 403 | 
 404 |     /// Return true if `lhs` is equal to `rhs`.
 405 |     ///
 406 |     /// **Equality implies substitutability**.  When `x == y`, `x` and
 407 |     /// `y` are interchangeable in any code that only depends on their
 408 |     /// values.
 409 |     ///
 410 |     /// Class instance identity as distinguished by triple-equals `===`
 411 |     /// is notably not part of an instance's value.  Exposing other
 412 |     /// non-value aspects of `Equatable` types is discouraged, and any
 413 |     /// that *are* exposed should be explicitly pointed out in
 414 |     /// documentation.
 415 |     /// 
 416 |     /// **Equality is an equivalence relation**
 417 |     ///
 418 |     /// - `x == x` is `true`
 419 |     /// - `x == y` implies `y == x`
 420 |     /// - `x == y` and `y == z` implies `x == z`
 421 |     ///
 422 |     /// **Inequality is the inverse of equality**, i.e. `!(x == y)` iff
 423 |     /// `x != y`
 424 |     func ==(lhs: Self, rhs: Self) -> Bool
 425 | }
 426 | 
 427 | /// A collection type that can be efficiently appended-to.
 428 | protocol ExtensibleCollectionType : _ExtensibleCollectionType {
 429 | }
 430 | 
 431 | 
 432 | /// Represents a discrete value in a series, where a value's
 433 | /// successor, if any, is reachable by applying the value's
 434 | /// `successor()` method.
 435 | protocol ForwardIndexType : _ForwardIndexType {
 436 | }
 437 | 
 438 | 
 439 | /// Encapsulates iteration state and interface for iteration over a
 440 | /// *sequence*.
 441 | ///
 442 | /// **Note:** While it is safe to copy a *generator*, advancing one
 443 | /// copy may invalidate the others.
 444 | ///
 445 | /// Any code that uses multiple generators (or `for`\ ...\ `in` loops)
 446 | /// over a single *sequence* should have static knowledge that the
 447 | /// specific *sequence* is multi-pass, either because its concrete
 448 | /// type is known or because it is constrained to `CollectionType`.
 449 | /// Also, the generators must be obtained by distinct calls to the
 450 | /// *sequence's* `generate()` method, rather than by copying.
 451 | protocol GeneratorType {
 452 | 
 453 |     /// The type of element generated by `self`.
 454 |     typealias Element
 455 | 
 456 |     /// Advance to the next element and return it, or `nil` if no next
 457 |     /// element exists.
 458 |     ///
 459 |     /// Requires: `next()` has not been applied to a copy of `self`
 460 |     /// since the copy was made, and no preceding call to `self.next()`
 461 |     /// has returned `nil`.  Specific implementations of this protocol
 462 |     /// are encouraged to respond to violations of this requirement by
 463 |     /// calling `preconditionFailure("...")`.
 464 |     mutating func next() -> Element?
 465 | }
 466 | 
 467 | 
 468 | /// Instances of conforming types provide an integer `hashValue` and
 469 | /// can be used as `Dictionary` keys.
 470 | protocol Hashable : Equatable {
 471 | 
 472 |     /// The hash value.
 473 |     ///
 474 |     /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
 475 |     ///
 476 |     /// **Note:** the hash value is not guaranteed to be stable across
 477 |     /// different invocations of the same program.  Do not persist the
 478 |     /// hash value across program runs.
 479 |     var hashValue: Int { get }
 480 | }
 481 | 
 482 | 
 483 | 
 484 | /// A 64-bit signed integer value
 485 | /// type.
 486 | struct Int : SignedIntegerType {
 487 |     var value: Builtin.Word
 488 | 
 489 |     /// A type that can represent the number of steps between pairs of
 490 |     /// values.
 491 |     typealias Distance = Int
 492 | 
 493 |     /// Create an instance initialized to zero.
 494 |     init()
 495 | 
 496 |     /// Create an instance initialized to `value`.
 497 |     init(_ value: Int)
 498 | 
 499 |     /// Creates an integer from its big-endian representation, changing the
 500 |     /// byte order if necessary.
 501 |     init(bigEndian value: Int)
 502 | 
 503 |     /// Creates an integer from its little-endian representation, changing the
 504 |     /// byte order if necessary.
 505 |     init(littleEndian value: Int)
 506 |     init(_builtinIntegerLiteral value: Builtin.Int2048)
 507 | 
 508 |     /// Create an instance initialized to `value`.
 509 |     init(integerLiteral value: Int)
 510 | 
 511 |     /// Returns the big-endian representation of the integer, changing the
 512 |     /// byte order if necessary.
 513 |     var bigEndian: Int { get }
 514 | 
 515 |     /// Returns the little-endian representation of the integer, changing the
 516 |     /// byte order if necessary.
 517 |     var littleEndian: Int { get }
 518 | 
 519 |     /// Returns the current integer with the byte order swapped.
 520 |     var byteSwapped: Int { get }
 521 |     static var max: Int { get }
 522 |     static var min: Int { get }
 523 | }
 524 | 
 525 | extension Int : Hashable {
 526 | 
 527 |     /// The hash value.
 528 |     ///
 529 |     /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
 530 |     ///
 531 |     /// **Note:** the hash value is not guaranteed to be stable across
 532 |     /// different invocations of the same program.  Do not persist the
 533 |     /// hash value across program runs.
 534 |     var hashValue: Int { get }
 535 | }
 536 | 
 537 | extension Int : RandomAccessIndexType {
 538 | 
 539 |     /// Returns the next consecutive value after `self`.
 540 |     ///
 541 |     /// Requires: the next value is representable.
 542 |     func successor() -> Int
 543 | 
 544 |     /// Returns the previous consecutive value before `self`.
 545 |     ///
 546 |     /// Requires: the previous value is representable.
 547 |     func predecessor() -> Int
 548 | 
 549 |     /// Return the minimum number of applications of `successor` or
 550 |     /// `predecessor` required to reach `other` from `self`.
 551 |     ///
 552 |     /// Complexity: O(1).
 553 |     func distanceTo(other: Int) -> Distance
 554 | 
 555 |     /// Return `self` offset by `n` steps.
 556 |     ///
 557 |     /// :returns: If `n > 0`, the result of applying `successor` to
 558 |     /// `self` `n` times.  If `n < 0`, the result of applying
 559 |     /// `predecessor` to `self` `-n` times. Otherwise, `self`.
 560 |     ///
 561 |     /// Complexity: O(1)
 562 |     func advancedBy(amount: Distance) -> Int
 563 | }
 564 | 
 565 | extension Int {
 566 | 
 567 |     /// Add `lhs` and `rhs`, returning a result and a
 568 |     /// `Bool` that is true iff the operation caused an arithmetic
 569 |     /// overflow.
 570 |     static func addWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
 571 | 
 572 |     /// Subtract `lhs` and `rhs`, returning a result and a
 573 |     /// `Bool` that is true iff the operation caused an arithmetic
 574 |     /// overflow.
 575 |     static func subtractWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
 576 | 
 577 |     /// Multiply `lhs` and `rhs`, returning a result and a
 578 |     /// `Bool` that is true iff the operation caused an arithmetic
 579 |     /// overflow.
 580 |     static func multiplyWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
 581 | 
 582 |     /// Divide `lhs` and `rhs`, returning
 583 |     /// a result and a `Bool`
 584 |     /// that is true iff the operation caused an arithmetic overflow.
 585 |     static func divideWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
 586 | 
 587 |     /// Divide `lhs` and `rhs`, returning
 588 |     /// the remainder and a `Bool`
 589 |     /// that is true iff the operation caused an arithmetic overflow.
 590 |     static func remainderWithOverflow(lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
 591 | 
 592 |     /// Represent this number using Swift's widest native signed
 593 |     /// integer type.
 594 |     func toIntMax() -> IntMax
 595 | }
 596 | 
 597 | extension Int {
 598 |     init(_ v: UInt8)
 599 |     init(_ v: Int8)
 600 |     init(_ v: UInt16)
 601 |     init(_ v: Int16)
 602 |     init(_ v: UInt32)
 603 |     init(_ v: Int32)
 604 |     init(_ v: UInt64)
 605 | 
 606 |     /// Construct a `Int` having the same bitwise representation as
 607 |     /// the least significant bits of the provided bit pattern.
 608 |     ///
 609 |     /// No range or overflow checking occurs.
 610 |     init(truncatingBitPattern: UInt64)
 611 |     init(_ v: Int64)
 612 | 
 613 |     /// Construct a `Int` having the same bitwise representation as
 614 |     /// the least significant bits of the provided bit pattern.
 615 |     ///
 616 |     /// No range or overflow checking occurs.
 617 |     init(truncatingBitPattern: Int64)
 618 |     init(_ v: UInt)
 619 | 
 620 |     /// Construct a `Int` having the same memory representation as
 621 |     /// the `UInt` `bitPattern`.  No range or overflow checking
 622 |     /// occurs, and the resulting `Int` may not have the same numeric
 623 |     /// value as `bitPattern`--it is only guaranteed to use the same
 624 |     /// pattern of bits.
 625 |     init(bitPattern: UInt)
 626 | }
 627 | 
 628 | extension Int : Reflectable {
 629 | 
 630 |     /// Returns a mirror that reflects `self`.
 631 |     func getMirror() -> MirrorType
 632 | }
 633 | 
 634 | 
 635 | /// The common requirements for types that support integer arithmetic.
 636 | protocol IntegerArithmeticType : _IntegerArithmeticType {
 637 | 
 638 |     /// Add `lhs` and `rhs`, returning a result and trapping in case of
 639 |     /// arithmetic overflow (except in -Ounchecked builds).
 640 |     func +(lhs: Self, rhs: Self) -> Self
 641 | 
 642 | }
 643 | 
 644 | 
 645 | /// Conforming types can be initialized with integer literals
 646 | protocol IntegerLiteralConvertible {
 647 |     typealias IntegerLiteralType
 648 | 
 649 |     /// Create an instance initialized to `value`.
 650 |     init(integerLiteral value: IntegerLiteralType)
 651 | }
 652 | 
 653 | 
 654 | /// The default type for an otherwise-unconstrained integer literal
 655 | typealias IntegerLiteralType = Int
 656 | 
 657 | 
 658 | /// A set of common requirements for Swift's integer types.
 659 | protocol IntegerType : _IntegerType, RandomAccessIndexType {
 660 | }
 661 | 
 662 | 
 663 | /// An interval over a `Comparable` type.
 664 | protocol IntervalType {
 665 | 
 666 |     /// The type of the `Interval`\ 's endpoints
 667 |     typealias Bound : Comparable
 668 | 
 669 |     /// Returns `true` iff the interval contains `value`
 670 |     func contains(value: Bound) -> Bool
 671 | 
 672 |     /// Return `rhs` clamped to `self`.  The bounds of the result, even
 673 |     /// if it is empty, are always within the bounds of `self`
 674 |     func clamp(intervalToClamp: Self) -> Self
 675 | 
 676 |     /// True iff `self` is empty
 677 |     var isEmpty: Bool { get }
 678 | 
 679 |     /// The `Interval`\ 's lower bound. Invariant: `start` <= `end`
 680 |     var start: Bound { get }
 681 | 
 682 |     /// The `Interval`\ 's upper bound. Invariant: `start` <= `end`
 683 |     var end: Bound { get }
 684 | }
 685 | 
 686 | 
 687 | /// How children of this value should be presented in the IDE.
 688 | enum MirrorDisposition {
 689 |     case Struct
 690 |     case Class
 691 |     case Enum
 692 |     case Tuple
 693 |     case Aggregate
 694 |     case IndexContainer
 695 |     case KeyContainer
 696 |     case MembershipContainer
 697 |     case Container
 698 |     case Optional
 699 |     case ObjCObject
 700 | }
 701 | 
 702 | 
 703 | /// The type returned by `reflect(x)`; supplies an API for runtime
 704 | /// reflection on `x`
 705 | protocol MirrorType {
 706 | 
 707 |     /// The instance being reflected
 708 |     var value: Any { get }
 709 | 
 710 |     /// Identical to `value.dynamicType`
 711 |     var valueType: Any.Type { get }
 712 | 
 713 |     /// A unique identifier for `value` if it is a class instance; `nil`
 714 |     /// otherwise.
 715 |     var objectIdentifier: ObjectIdentifier? { get }
 716 | 
 717 |     /// The count of `value`\ 's logical children 
 718 |     var count: Int { get }
 719 |     subscript (i: Int) -> (String, MirrorType) { get }
 720 | 
 721 |     /// A string description of `value`.
 722 |     var summary: String { get }
 723 | 
 724 |     /// A rich representation of `value` for an IDE, or `nil` if none is supplied.
 725 |     var quickLookObject: QuickLookObject? { get }
 726 | 
 727 |     /// How `value` should be presented in an IDE.
 728 |     var disposition: MirrorDisposition { get }
 729 | }
 730 | 
 731 | 
 732 | /// A *collection* that supports subscript assignment.
 733 | ///
 734 | /// For any instance `a` of a type conforming to
 735 | /// `MutableCollectionType`, ::
 736 | ///
 737 | ///   a[i] = x
 738 | ///   let y = a[i]
 739 | ///
 740 | /// is equivalent to ::
 741 | ///
 742 | ///   a[i] = x
 743 | ///   let y = x
 744 | ///
 745 | protocol MutableCollectionType : CollectionType {
 746 |     subscript (position: Self.Index) -> Self.Generator.Element { get set }
 747 | }
 748 | 
 749 | 
 750 | /// A *collection* with mutable slices.
 751 | ///
 752 | /// For example,
 753 | ///
 754 | /// .. parsed-literal:
 755 | ///
 756 | ///      x[i..<j] = *someExpression*
 757 | ///      x[i..<j].\ *mutatingMethod*\ ()
 758 | protocol MutableSliceable : Sliceable, MutableCollectionType {
 759 |     subscript (_: Range<Self.Index>) -> Self.SubSlice { get set }
 760 | }
 761 | 
 762 | 
 763 | /// An instance that exposes API for interaction with processes
 764 | let Process: _Process
 765 | 
 766 | 
 767 | /// The sum of types that can be used as a quick look representation.
 768 | ///
 769 | /// This type must be binary-compatible with the 'QuickLookObject' struct in
 770 | /// stdlib/Runtime/Reflection.mm, and 'QuickLookObject?' must be binary
 771 | /// compatible with 'OptionalQuickLookObject' from the same.
 772 | ///
 773 | /// NB: This type is somewhat carefully laid out to *suppress* enum layout
 774 | /// optimization so that it is easier to manufacture in the C++ runtime
 775 | /// implementation.
 776 | enum QuickLookObject {
 777 |     case Text(String)
 778 |     case Int(Int64)
 779 |     case UInt(UInt64)
 780 |     case Float(Double)
 781 |     case Image(Any)
 782 |     case Sound(Any)
 783 |     case Color(Any)
 784 |     case BezierPath(Any)
 785 |     case AttributedString(Any)
 786 |     case Rectangle(Double, Double, Double, Double)
 787 |     case Point(Double, Double)
 788 |     case Size(Double, Double)
 789 |     case Logical(Bool)
 790 |     case Range(UInt64, UInt64)
 791 |     case View(Any)
 792 |     case Sprite(Any)
 793 |     case URL(String)
 794 | }
 795 | 
 796 | 
 797 | /// An *index* that can be offset by an arbitrary number of positions,
 798 | /// and can measure the distance to any reachable value, in O(1).
 799 | protocol RandomAccessIndexType : BidirectionalIndexType, _RandomAccessIndexType {
 800 | }
 801 | 
 802 | 
 803 | /// A *collection* that supports replacement of an arbitrary subRange
 804 | /// of elements with the elements of another collection.
 805 | protocol RangeReplaceableCollectionType : ExtensibleCollectionType {
 806 | 
 807 |     /// Replace the given `subRange` of elements with `newElements`.
 808 |     ///
 809 |     /// Invalidates all indices with respect to `self`.
 810 |     ///
 811 |     /// Complexity: O(\ `countElements(subRange)`\ ) if
 812 |     /// `subRange.endIndex == self.endIndex` and `isEmpty(newElements)`\ ,
 813 |     /// O(\ `countElements(self)`\ + \`countElements(newElements)`\ ) otherwise.
 814 |     mutating func replaceRange<C : CollectionType where `Self`.Generator.Element == Self.Generator.Element>(subRange: Range<Self.Index>, with newElements: C)
 815 | 
 816 |     /// Insert `newElement` at index `i`.
 817 |     ///
 818 |     /// Invalidates all indices with respect to `self`.
 819 |     ///
 820 |     /// Complexity: O(\ `countElements(self)`\ ).
 821 |     ///
 822 |     /// Can be implemented as::
 823 |     ///
 824 |     ///   Swift.insert(&self, newElement, atIndex: i)
 825 |     mutating func insert(newElement: Self.Generator.Element, atIndex i: Self.Index)
 826 | 
 827 |     /// Insert `newElements` at index `i`
 828 |     ///
 829 |     /// Invalidates all indices with respect to `self`.
 830 |     ///
 831 |     /// Complexity: O(\ `countElements(self) + countElements(newElements)`\ ).
 832 |     ///
 833 |     /// Can be implemented as::
 834 |     ///
 835 |     ///   Swift.splice(&self, newElements, atIndex: i)
 836 |     mutating func splice<S : CollectionType where `Self`.Generator.Element == Self.Generator.Element>(newElements: S, atIndex i: Self.Index)
 837 | 
 838 |     /// Remove the element at index `i`
 839 |     ///
 840 |     /// Invalidates all indices with respect to `self`.
 841 |     ///
 842 |     /// Complexity: O(\ `countElements(self)`\ ).
 843 |     ///
 844 |     /// Can be implemented as::
 845 |     ///
 846 |     ///   Swift.removeAtIndex(&self, i)
 847 |     mutating func removeAtIndex(i: Self.Index) -> Self.Generator.Element
 848 | 
 849 |     /// Remove the indicated `subRange` of elements
 850 |     ///
 851 |     /// Invalidates all indices with respect to `self`.
 852 |     ///
 853 |     /// Complexity: O(\ `countElements(self)`\ ).
 854 |     ///
 855 |     /// Can be implemented as::
 856 |     ///
 857 |     ///   Swift.removeRange(&self, subRange)
 858 |     mutating func removeRange(subRange: Range<Self.Index>)
 859 | 
 860 |     /// Remove all elements
 861 |     ///
 862 |     /// Invalidates all indices with respect to `self`.
 863 |     ///
 864 |     /// :param: `keepCapacity`, if `true`, is a non-binding request to
 865 |     ///    avoid releasing storage, which can be a useful optimization
 866 |     ///    when `self` is going to be grown again.
 867 |     ///
 868 |     /// Complexity: O(\ `countElements(self)`\ ).
 869 |     ///
 870 |     /// Can be implemented as::
 871 |     ///
 872 |     ///   Swift.removeAll(&self, keepCapacity: keepCapacity)
 873 |     mutating func removeAll(#keepCapacity: Bool)
 874 | }
 875 | 
 876 | 
 877 | /// Customizes the result of `reflect(x)`, where `x` is a conforming
 878 | /// type.
 879 | protocol Reflectable {
 880 | 
 881 |     /// Returns a mirror that reflects `self`.
 882 |     func getMirror() -> MirrorType
 883 | }
 884 | 
 885 | /// A type that can be iterated with a `for`\ ...\ `in` loop.
 886 | ///
 887 | /// `SequenceType` makes no requirement on conforming types regarding
 888 | /// whether they will be destructively "consumed" by iteration.  To
 889 | /// ensure non-destructive iteration, constrain your *sequence* to
 890 | /// `CollectionType`.
 891 | protocol SequenceType : _Sequence_Type {
 892 | 
 893 |     /// A type that provides the *sequence*\ 's iteration interface and
 894 |     /// encapsulates its iteration state.
 895 |     typealias Generator : GeneratorType
 896 | 
 897 |     /// Return a *generator* over the elements of this *sequence*.
 898 |     ///
 899 |     /// Complexity: O(1)
 900 |     func generate() -> Generator
 901 | }
 902 | 
 903 | /// A set of common requirements for Swift's signed integer types.
 904 | protocol SignedIntegerType : _SignedIntegerType, IntegerType {
 905 | }
 906 | 
 907 | /// A *collection* from which a sub-range of elements (a "slice")
 908 | /// can be efficiently extracted.
 909 | protocol Sliceable : _Sliceable {
 910 | 
 911 |     /// The *collection* type that represents a sub-range of elements.
 912 |     ///
 913 |     /// Though it can't currently be enforced by the type system, the
 914 |     /// `SubSlice` type in a concrete implementation of `Sliceable`
 915 |     /// should also be `Sliceable`.
 916 |     typealias SubSlice : _Sliceable
 917 |     subscript (bounds: Range<Self.Index>) -> SubSlice { get }
 918 | }
 919 | 
 920 | 
 921 | /// Conforming types are notionally continuous, one-dimensional
 922 | /// values that can be offset and measured.
 923 | ///
 924 | /// See also: `stride(from: to: by:)` and `stride(from: through: by:)`
 925 | protocol Strideable : _Strideable {
 926 | }
 927 | 
 928 | 
 929 | /// The empty tuple type.
 930 | ///
 931 | /// This is the default return type of functions for which no explicit
 932 | /// return type is specified.
 933 | typealias Void = ()
 934 | 
 935 | 
 936 | /// A signed integer type that occupies one machine word
 937 | typealias Word = Int
 938 | 
 939 | 
 940 | /// This protocol is an implementation detail of `BidirectionalIndexType`; do
 941 | /// not use it directly.
 942 | ///
 943 | /// Its requirements are inherited by `BidirectionalIndexType` and thus must
 944 | /// be satisfied by types conforming to that protocol.
 945 | protocol _BidirectionalIndexType : _ForwardIndexType {
 946 | 
 947 |     /// Return the previous consecutive value in a discrete sequence.
 948 |     ///
 949 |     /// If `self` has a well-defined successor,
 950 |     /// `self.successor().predecessor() == self`.  If `self` has a
 951 |     /// well-defined predecessor, `self.predecessor().successor() ==
 952 |     /// self`.
 953 |     ///
 954 |     /// Requires: `self` has a well-defined predecessor.
 955 |     func predecessor() -> Self
 956 | }
 957 | 
 958 | 
 959 | /// This protocol is an implementation detail of `CollectionType`; do
 960 | /// not use it directly.
 961 | ///
 962 | /// Its requirements are inherited by `CollectionType` and thus must
 963 | /// be satisfied by types conforming to that protocol.
 964 | protocol _CollectionType : _SequenceType {
 965 | 
 966 |     /// A type that represents a valid position in the collection.
 967 |     ///
 968 |     /// Valid indices consist of the position of every element and a
 969 |     /// "past the end" position that's not valid for use as a subscript.
 970 |     typealias Index : ForwardIndexType
 971 | 
 972 |     /// The position of the first element in a non-empty collection.
 973 |     ///
 974 |     /// Identical to `endIndex` in an empty collection.
 975 |     var startIndex: Index { get }
 976 | 
 977 |     /// The collection's "past the end" position.
 978 |     ///
 979 |     /// `endIndex` is not a valid argument to `subscript`, and is always
 980 |     /// reachable from `startIndex` by zero or more applications of
 981 |     /// `successor()`.
 982 |     var endIndex: Index { get }
 983 |     typealias _Element
 984 |     subscript (_i: Index) -> _Element { get }
 985 | }
 986 | 
 987 | 
 988 | 
 989 | /// This protocol is an implementation detail of `ExtensibleCollectionType`; do
 990 | /// not use it directly.
 991 | ///
 992 | /// Its requirements are inherited by `ExtensibleCollectionType` and thus must
 993 | /// be satisfied by types conforming to that protocol.
 994 | protocol _ExtensibleCollectionType : CollectionType {
 995 | 
 996 |     /// Create an empty instance
 997 |     init()
 998 | 
 999 |     /// A non-binding request to ensure `n` elements of available storage.
1000 |     ///
1001 |     /// This works as an optimization to avoid multiple reallocations of
1002 |     /// linear data structures like `Array`.  Conforming types may
1003 |     /// reserve more than `n`, exactly `n`, less than `n` elements of
1004 |     /// storage, or even ignore the request completely.
1005 |     mutating func reserveCapacity(n: Self.Index.Distance)
1006 | 
1007 |     /// Append `x` to `self`.
1008 |     ///
1009 |     /// Applying `successor()` to the index of the new element yields
1010 |     /// `self.endIndex`.
1011 |     ///
1012 |     /// Complexity: amortized O(1).
1013 |     mutating func append(x: Self.Generator.Element)
1014 | 
1015 |     /// Append the elements of `newElements` to `self`.
1016 |     ///
1017 |     /// Complexity: O(*length of result*) 
1018 |     /// 
1019 |     /// A possible implementation::
1020 |     ///
1021 |     ///   reserveCapacity(countElements(self) + underestimateCount(newElements))
1022 |     ///   for x in newElements {
1023 |     ///     newElements.append(x)
1024 |     ///   }
1025 |     mutating func extend<S : SequenceType where `Self`.Generator.Element == Self.Generator.Element>(newElements: S)
1026 | }
1027 | 
1028 | 
1029 | /// This protocol is an implementation detail of `ForwardIndexType`; do
1030 | /// not use it directly.
1031 | ///
1032 | /// Its requirements are inherited by `ForwardIndexType` and thus must
1033 | /// be satisfied by types conforming to that protocol.
1034 | protocol _ForwardIndexType : _Incrementable {
1035 | 
1036 |     /// A type that can represent the number of steps between pairs of
1037 |     /// `Self` values where one value is reachable from the other.
1038 |     ///
1039 |     /// Reachability is defined by the ability to produce one value from
1040 |     /// the other via zero or more applications of `successor`.
1041 |     typealias Distance : _SignedIntegerType = Int
1042 |     typealias _DisabledRangeIndex = _DisabledRangeIndex_
1043 | }
1044 | 
1045 | 
1046 | /// This protocol is an implementation detail of `ForwardIndexType`; do
1047 | /// not use it directly.
1048 | ///
1049 | /// Its requirements are inherited by `ForwardIndexType` and thus must
1050 | /// be satisfied by types conforming to that protocol.
1051 | protocol _Incrementable : Equatable {
1052 | 
1053 |     /// Return the next consecutive value in a discrete sequence of
1054 |     /// `Self` values
1055 |     ///
1056 |     /// Requires: `self` has a well-defined successor.
1057 |     func successor() -> Self
1058 | }
1059 | 
1060 | 
1061 | /// This protocol is an implementation detail of `IntegerArithmeticType`; do
1062 | /// not use it directly.
1063 | ///
1064 | /// Its requirements are inherited by `IntegerArithmeticType` and thus must
1065 | /// be satisfied by types conforming to that protocol.
1066 | protocol _IntegerArithmeticType {
1067 | 
1068 |     /// Add `lhs` and `rhs`, returning a result and a `Bool` that is
1069 |     /// true iff the operation caused an arithmetic overflow.
1070 |     class func addWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1071 | 
1072 |     /// Subtract `lhs` and `rhs`, returning a result and a `Bool` that is
1073 |     /// true iff the operation caused an arithmetic overflow.
1074 |     class func subtractWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1075 | 
1076 |     /// Multiply `lhs` and `rhs`, returning a result and a `Bool` that is
1077 |     /// true iff the operation caused an arithmetic overflow.
1078 |     class func multiplyWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1079 | 
1080 |     /// Divide `lhs` and `rhs`, returning a result and a `Bool` that is
1081 |     /// true iff the operation caused an arithmetic overflow.
1082 |     class func divideWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1083 | 
1084 |     /// Divide `lhs` and `rhs`, returning the remainder and a `Bool` that is
1085 |     /// true iff the operation caused an arithmetic overflow.
1086 |     class func remainderWithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
1087 | }
1088 | 
1089 | 
1090 | /// This protocol is an implementation detail of `IntegerType`; do
1091 | /// not use it directly.
1092 | ///
1093 | /// Its requirements are inherited by `IntegerType` and thus must
1094 | /// be satisfied by types conforming to that protocol.
1095 | protocol _IntegerType : IntegerLiteralConvertible, Hashable, IntegerArithmeticType, _Incrementable {
1096 | }
1097 | 
1098 | 
1099 | /// This protocol is an implementation detail of `RandomAccessIndexType`; do
1100 | /// not use it directly.
1101 | ///
1102 | /// Its requirements are inherited by `RandomAccessIndexType` and thus must
1103 | /// be satisfied by types conforming to that protocol.
1104 | protocol _RandomAccessIndexType : _BidirectionalIndexType, Strideable {
1105 | 
1106 |     /// Return the minimum number of applications of `successor` or
1107 |     /// `predecessor` required to reach `other` from `self`.
1108 |     ///
1109 |     /// Complexity: O(1).
1110 |     ///
1111 |     /// Axioms::
1112 |     /// 
1113 |     ///   x.distanceTo(x.successor())) == 1
1114 |     ///   x.distanceTo(x.predecessor())) == -1
1115 |     ///   x.advancedBy(x.distanceTo(y)) == y
1116 |     func distanceTo(other: Self) -> Self.Distance
1117 | 
1118 |     /// Return `self` offset by `n` steps.
1119 |     ///
1120 |     /// :returns: If `n > 0`, the result of applying `successor` to
1121 |     /// `self` `n` times.  If `n < 0`, the result of applying
1122 |     /// `predecessor` to `self` `-n` times. Otherwise, `self`.
1123 |     ///
1124 |     /// Complexity: O(1)
1125 |     ///
1126 |     /// Axioms::
1127 |     ///
1128 |     ///   x.advancedBy(0) == x
1129 |     ///   x.advancedBy(1) == x.successor()
1130 |     ///   x.advancedBy(-1) == x.predecessor()
1131 |     ///   x.distanceTo(x.advancedBy(m)) == m
1132 |     func advancedBy(n: Self.Distance) -> Self
1133 | }
1134 | 
1135 | 
1136 | /// This protocol is an implementation detail of `SequenceType`; do
1137 | /// not use it directly.
1138 | ///
1139 | /// Its requirements are inherited by `SequenceType` and thus must
1140 | /// be satisfied by types conforming to that protocol.
1141 | protocol _SequenceType {
1142 | }
1143 | 
1144 | 
1145 | /// This protocol is an implementation detail of `SequenceType`; do
1146 | /// not use it directly.
1147 | ///
1148 | /// Its requirements are inherited by `SequenceType` and thus must
1149 | /// be satisfied by types conforming to that protocol.
1150 | protocol _Sequence_Type : _SequenceType {
1151 | 
1152 |     /// A type whose instances can produce the elements of this
1153 |     /// sequence, in order.
1154 |     typealias Generator : GeneratorType
1155 | 
1156 |     /// Return a *generator* over the elements of this *sequence*.  The
1157 |     /// *generator*\ 's next element is the first element of the
1158 |     /// sequence.
1159 |     ///
1160 |     /// Complexity: O(1)
1161 |     func generate() -> Generator
1162 | }
1163 | 
1164 | 
1165 | /// This protocol is an implementation detail of `SignedIntegerType`;
1166 | /// do not use it directly.
1167 | ///
1168 | /// Its requirements are inherited by `SignedIntegerType` and thus
1169 | /// must be satisfied by types conforming to that protocol.
1170 | protocol _SignedIntegerType : _IntegerType {
1171 | 
1172 |     /// Represent this number using Swift's widest native signed integer
1173 |     /// type.
1174 |     func toIntMax() -> IntMax
1175 | 
1176 |     /// Convert from Swift's widest signed integer type, trapping on
1177 |     /// overflow.
1178 |     init(_: IntMax)
1179 | }
1180 | 
1181 | 
1182 | /// This protocol is an implementation detail of `Sliceable`; do
1183 | /// not use it directly.
1184 | ///
1185 | /// Its requirements are inherited by `Sliceable` and thus must
1186 | /// be satisfied by types conforming to that protocol.
1187 | protocol _Sliceable : CollectionType {
1188 | }
1189 | 
1190 | 
1191 | /// This protocol is an implementation detail of `Strideable`; do
1192 | /// not use it directly.
1193 | ///
1194 | /// Its requirements are inherited by `Strideable` and thus must
1195 | /// be satisfied by types conforming to that protocol.
1196 | protocol _Strideable {
1197 | 
1198 |     /// A type that can represent the distance between two values of `Self`
1199 |     typealias Stride : SignedNumberType
1200 | 
1201 |     /// Returns a stride `x` such that `self.advancedBy(x)` approximates
1202 |     /// `other`.
1203 |     ///
1204 |     /// Complexity: O(1).
1205 |     ///
1206 |     /// See also: `RandomAccessIndexType`\ 's `distanceTo`, which provides a
1207 |     /// stronger semantic guarantee.
1208 |     func distanceTo(other: Self) -> Stride
1209 | 
1210 |     /// Returns a `Self` `x` such that `self.distanceTo(x)` approximates
1211 |     /// `n`.
1212 |     ///
1213 |     /// Complexity: O(1).
1214 |     ///
1215 |     /// See also: `RandomAccessIndexType`\ 's `advancedBy`, which
1216 |     /// provides a stronger semantic guarantee.
1217 |     func advancedBy(n: Stride) -> Self
1218 | }
1219 | 
1220 | 
1221 | /// Return the result of advancing `start` by `n` positions.  If `T`
1222 | /// models `RandomAccessIndexType`, executes in O(1).  Otherwise,
1223 | /// executes in O(`abs(n)`).  If `T` does not model
1224 | /// `BidirectionalIndexType`, requires that `n` is non-negative.
1225 | ///
1226 | /// `advance(i, n)` is a synonym for `i++n'
1227 | func advance<T : ForwardIndexType>(start: T, n: T.Distance) -> T
1228 | 
1229 | 
1230 | /// Return the result of advancing start by `n` positions, or until it
1231 | /// equals `end`.  If `T` models `RandomAccessIndexType`, executes in
1232 | /// O(1).  Otherwise, executes in O(`abs(n)`).  If `T` does not model
1233 | /// `BidirectionalIndexType`, requires that `n` is non-negative.
1234 | func advance<T : ForwardIndexType>(start: T, n: T.Distance, end: T) -> T
1235 | 
1236 | 
1237 | /// Returns the minimum memory alignment of `T`.
1238 | func alignof<T>(_: T.Type) -> Int
1239 | 
1240 | 
1241 | /// Returns the minimum memory alignment of `T`.
1242 | func alignofValue<T>(_: T) -> Int
1243 | 
1244 | 
1245 | /// User code assertions.
1246 | ///
1247 | /// User code assertions and fatal errors are only enabled in debug mode. In
1248 | /// release or fast mode these checks are disabled. This means they may have no
1249 | /// effect on program semantics, depending on the assert configuration.
1250 | /// Traditional C-style assert with an optional message.
1251 | ///
1252 | /// When assertions are enabled and `condition` is false, stop program
1253 | /// execution in a debuggable state after printing a message.  When
1254 | /// assertions are disabled in release and fast builds, `condition` is not even
1255 | /// evaluated.
1256 | ///
1257 | /// When assertions are turned off, the optimizer can assume that the
1258 | /// `condition` is true.
1259 | func assert(condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = default, file: StaticString = default, line: UWord = default)
1260 | 
1261 | 
1262 | /// Dump an object's contents using its mirror to standard output.
1263 | func dump<T>(x: T, name: String? = default, indent: Int = default, maxDepth: Int = default, maxItems: Int = default) -> T
1264 | 
1265 | 
1266 | /// Dump an object's contents using its mirror to the specified output stream.
1267 | func dump<T, TargetStream : OutputStreamType>(x: T, inout targetStream: TargetStream, name: String? = default, indent: Int = default, maxDepth: Int = default, maxItems: Int = default) -> T
1268 | 
1269 | 
1270 | /// Return a lazy `SequenceType` containing pairs (*n*, *x*), where
1271 | /// *n*\ s are consecutive `Int`\ s starting at zero, and *x*\ s are
1272 | /// the elements of `base`::
1273 | ///
1274 | ///   > for (n, c) in enumerate("Swift") { println("\(n): '\(c)'" )}
1275 | ///   0: 'S'
1276 | ///   1: 'w'
1277 | ///   2: 'i'
1278 | ///   3: 'f'
1279 | ///   4: 't'
1280 | func enumerate<Seq : SequenceType>(base: Seq) -> EnumerateSequence<Seq>
1281 | 
1282 | 
1283 | /// Re-order the given `range` of `elements` and return a pivot index
1284 | /// *p*.  Postcondition: for all *i* in `range.startIndex..<`\ *p*,
1285 | /// and *j* in *p*\ `..<range.endIndex`, `less(elements[`\ *i*\ `],
1286 | /// elements[`\ *j*\ `]) && !less(elements[`\ *j*\ `], elements[`\
1287 | /// *p*\ `])`.  Only returns `range.endIndex` when `elements` is
1288 | /// empty.
1289 | /// Requires: `isOrderedBefore` is a `strict weak ordering
1290 | /// <http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings>`__
1291 | /// over `elements`.
1292 | func partition<C : MutableCollectionType where C.Index : RandomAccessIndexType>(inout elements: C, range: Range<C.Index>, isOrderedBefore: (C.Generator.Element, C.Generator.Element) -> Bool) -> C.Index
1293 | 
1294 | 
1295 | /// Translate `input`, in the given `InputEncoding`, into `output`, in
1296 | /// the given `OutputEncoding`.
1297 | ///
1298 | /// :param: `stopOnError` causes encoding to stop when an encoding
1299 | ///   error is detected in `input`, if `true`.  Otherwise, U+FFFD
1300 | ///   replacement characters are inserted for each detected error.
1301 | func transcode<Input : GeneratorType, Output : SinkType, InputEncoding : UnicodeCodecType, OutputEncoding : UnicodeCodecType where InputEncoding.CodeUnit == InputEncoding.CodeUnit, OutputEncoding.CodeUnit == OutputEncoding.CodeUnit>(inputEncoding: InputEncoding.Type, outputEncoding: OutputEncoding.Type, input: Input, output: Output, #stopOnError: Bool) -> (Bool)
1302 | 
1303 | 
1304 | /// Like `withUnsafeMutablePointer`, but passes pointers to `arg0`, `arg1`,
1305 | /// and `arg2`.
1306 | func withUnsafeMutablePointers<A0, A1, A2, Result>(inout arg0: A0, inout arg1: A1, inout arg2: A2, body: (UnsafeMutablePointer<A0>, UnsafeMutablePointer<A1>, UnsafeMutablePointer<A2>) -> Result) -> Result
1307 | 
1308 | 
1309 | /// A collection of consecutive discrete index values.
1310 | ///
1311 | /// :param: `T` is both the element type and the index type of the
1312 | ///   collection.
1313 | ///
1314 | /// Like other collections, a range containing one element has an
1315 | /// `endIndex` that is the successor of its `startIndex`; and an empty
1316 | /// range has `startIndex == endIndex`.
1317 | ///
1318 | /// Axiom: for any `Range` `r`, `r[i] == i`.
1319 | ///
1320 | /// Therefore, if `T` has a maximal value, it can serve as an
1321 | /// `endIndex`, but can never be contained in a `Range<T>`.
1322 | ///
1323 | /// It also follows from the axiom above that `(-99..<100)[0] == 0`.
1324 | /// To prevent confusion (because some expect the result to be `-99`),
1325 | /// in a context where `T` is known to be an integer type,
1326 | /// subscripting with `T` is a compile-time error::
1327 | ///
1328 | ///   // error: could not find an overload for 'subscript'...
1329 | ///   println( Range<Int>(start:-99, end:100)[0] )
1330 | ///
1331 | /// However, subscripting that range still works in a generic context::
1332 | ///
1333 | ///   func brackets<T:ForwardIndexType>(x: Range<T>, i: T) -> T {
1334 | ///     return x[i] // Just forward to subscript
1335 | ///   }
1336 | ///   println(brackets(Range<Int>(start:-99, end:100), 0)) // prints 0
1337 | struct Range<T : ForwardIndexType> : Equatable, CollectionType, Printable, DebugPrintable {
1338 | 
1339 |     /// Construct a copy of `x`
1340 |     init(_ x: Range<T>)
1341 | 
1342 |     /// Construct a range with `startIndex == start` and `endIndex ==
1343 |     /// end`.
1344 |     init(start: T, end: T)
1345 | 
1346 |     /// `true` iff the range is empty, i.e. `startIndex == endIndex`
1347 |     var isEmpty: Bool { get }
1348 | 
1349 |     /// A type that represents a valid position in the collection.
1350 |     /// 
1351 |     /// Valid indices consist of the position of every element and a
1352 |     /// "past the end" position that's not valid for use as a subscript.
1353 |     typealias Index = T
1354 |     typealias Slice = Range<T>
1355 |     subscript (position: T) -> T { get }
1356 |     subscript (_: T._DisabledRangeIndex) -> T { get }
1357 | 
1358 |     /// A type whose instances can produce the elements of this
1359 |     /// sequence, in order.
1360 |     typealias Generator = RangeGenerator<T>
1361 | 
1362 |     /// Return a *generator* over the elements of this *sequence*.
1363 |     ///
1364 |     /// Complexity: O(1)
1365 |     func generate() -> RangeGenerator<T>
1366 | 
1367 |     /// The range's lower bound
1368 |     ///
1369 |     /// Identical to `endIndex` in an empty range.
1370 |     var startIndex: T
1371 | 
1372 |     /// The range's upper bound
1373 |     ///
1374 |     /// `endIndex` is not a valid argument to `subscript`, and is always
1375 |     /// reachable from `startIndex` by zero or more applications of
1376 |     /// `successor()`.
1377 |     var endIndex: T
1378 | 
1379 |     /// A textual representation of `self`.
1380 |     var description: String { get }
1381 | 
1382 |     /// A textual representation of `self`, suitable for debugging.
1383 |     var debugDescription: String { get }
1384 | }
1385 | 


--------------------------------------------------------------------------------