Skip to content

Instantly share code, notes, and snippets.

@mattt
Last active December 9, 2019 20:32
Show Gist options
  • Save mattt/95669a73cb395894144ec6e5f0557748 to your computer and use it in GitHub Desktop.
Save mattt/95669a73cb395894144ec6e5f0557748 to your computer and use it in GitHub Desktop.
Early Swift Doc output JSON for Swift standard library
This file has been truncated, but you can view the full file.
{
"files" : [
{
"enumerations" : [
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"cases" : [
{
"name" : "none",
"keyword" : "case",
"attributes" : [],
"context" : "ArithmeticOverflow",
"modifiers" : []
},
{
"context" : "ArithmeticOverflow",
"attributes" : [],
"modifiers" : [],
"keyword" : "case",
"name" : "overflow"
}
],
"name" : "ArithmeticOverflow",
"keyword" : "enum"
}
},
{
"documentation" : [
[
"summary",
"Command-line arguments for the current process.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"cases" : [],
"attributes" : [],
"keyword" : "enum",
"name" : "CommandLine"
}
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"cases" : [
{
"name" : "signalingNaN",
"keyword" : "case",
"modifiers" : [],
"context" : "FloatingPointClassification",
"attributes" : []
},
{
"attributes" : [],
"context" : "FloatingPointClassification",
"modifiers" : [],
"name" : "quietNaN",
"keyword" : "case"
},
{
"keyword" : "case",
"name" : "negativeInfinity",
"modifiers" : [],
"context" : "FloatingPointClassification",
"attributes" : []
},
{
"keyword" : "case",
"name" : "negativeNormal",
"context" : "FloatingPointClassification",
"attributes" : [],
"modifiers" : []
},
{
"attributes" : [],
"context" : "FloatingPointClassification",
"modifiers" : [],
"name" : "negativeSubnormal",
"keyword" : "case"
},
{
"modifiers" : [],
"attributes" : [],
"context" : "FloatingPointClassification",
"name" : "negativeZero",
"keyword" : "case"
},
{
"context" : "FloatingPointClassification",
"attributes" : [],
"modifiers" : [],
"name" : "positiveZero",
"keyword" : "case"
},
{
"modifiers" : [],
"attributes" : [],
"context" : "FloatingPointClassification",
"name" : "positiveSubnormal",
"keyword" : "case"
},
{
"context" : "FloatingPointClassification",
"attributes" : [],
"modifiers" : [],
"name" : "positiveNormal",
"keyword" : "case"
},
{
"name" : "positiveInfinity",
"keyword" : "case",
"attributes" : [],
"context" : "FloatingPointClassification",
"modifiers" : []
}
],
"keyword" : "enum",
"name" : "FloatingPointClassification"
},
"documentation" : [
[
"summary",
"The IEEE 754 floating-point classes.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A rule for rounding a floating-point number.\n"
]
],
"declaration" : {
"name" : "FloatingPointRoundingRule",
"keyword" : "enum",
"cases" : [
{
"context" : "FloatingPointRoundingRule",
"attributes" : [],
"modifiers" : [],
"keyword" : "case",
"name" : "toNearestOrAwayFromZero"
},
{
"attributes" : [],
"context" : "FloatingPointRoundingRule",
"modifiers" : [],
"name" : "toNearestOrEven",
"keyword" : "case"
},
{
"keyword" : "case",
"name" : "up",
"context" : "FloatingPointRoundingRule",
"attributes" : [],
"modifiers" : []
},
{
"modifiers" : [],
"attributes" : [],
"context" : "FloatingPointRoundingRule",
"name" : "down",
"keyword" : "case"
},
{
"attributes" : [],
"context" : "FloatingPointRoundingRule",
"modifiers" : [],
"keyword" : "case",
"name" : "towardZero"
},
{
"name" : "awayFromZero",
"keyword" : "case",
"modifiers" : [],
"attributes" : [],
"context" : "FloatingPointRoundingRule"
}
],
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"The sign of a floating-point value.\n"
]
],
"declaration" : {
"attributes" : [],
"cases" : [
{
"keyword" : "case",
"name" : "plus",
"modifiers" : [],
"context" : "FloatingPointSign",
"attributes" : []
},
{
"keyword" : "case",
"name" : "minus",
"context" : "FloatingPointSign",
"attributes" : [],
"modifiers" : []
}
],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "FloatingPointSign",
"keyword" : "enum"
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"cases" : [
{
"keyword" : "case",
"name" : "none",
"context" : "ImplicitlyUnwrappedOptional",
"attributes" : [],
"modifiers" : []
},
{
"keyword" : "case",
"name" : "some",
"associatedValue" : [
{
"attributes" : [],
"type" : "Wrapped"
}
],
"modifiers" : [],
"context" : "ImplicitlyUnwrappedOptional",
"attributes" : []
}
],
"attributes" : [],
"name" : "ImplicitlyUnwrappedOptional",
"keyword" : "enum"
},
"documentation" : [
[
"summary",
"An optional type that allows implicit member access.\n"
],
[
"discussion",
"*Deprecated.*\n"
]
]
},
{
"declaration" : {
"name" : "MemoryLayout",
"keyword" : "enum",
"attributes" : [],
"cases" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"The memory layout of a type, describing its size, stride, and alignment.\n"
],
[
"discussion",
"You can use `MemoryLayout` as a source of information about a type when\nallocating or binding memory using unsafe pointers. The following example\ndeclares a `Point` type with `x` and `y` coordinates and a Boolean\n`isFilled` property.\n"
],
[
"discussion",
"``` \n struct Point {\n let x: Double\n let y: Double\n let isFilled: Bool\n }\n```\n"
],
[
"discussion",
"The size, stride, and alignment of the `Point` type are accessible as\nstatic properties of `MemoryLayout<Point>`.\n"
],
[
"discussion",
"``` \n // MemoryLayout<Point>.size == 17\n // MemoryLayout<Point>.stride == 24\n // MemoryLayout<Point>.alignment == 8\n```\n"
],
[
"discussion",
"Always use a multiple of a type's `stride` instead of its `size` when\nallocating memory or accounting for the distance between instances in\nmemory. This example allocates untyped, uninitialized memory with space\nfor four instances of `Point`.\n"
],
[
"discussion",
"``` \n let count = 4\n let pointPointer = UnsafeMutableRawPointer.allocate(\n bytes: count * MemoryLayout<Point>.stride,\n alignedTo: MemoryLayout<Point>.alignment)\n```\n"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"cases" : [
{
"modifiers" : [],
"attributes" : [],
"context" : "Mirror.AncestorRepresentation",
"keyword" : "case",
"name" : "generated"
},
{
"keyword" : "case",
"associatedValue" : [
{
"attributes" : [],
"type" : "() -> Mirror"
}
],
"name" : "customized",
"modifiers" : [],
"context" : "Mirror.AncestorRepresentation",
"attributes" : []
},
{
"name" : "suppressed",
"keyword" : "case",
"attributes" : [],
"context" : "Mirror.AncestorRepresentation",
"modifiers" : []
}
],
"context" : "Mirror",
"attributes" : [],
"name" : "AncestorRepresentation",
"keyword" : "enum"
},
"documentation" : [
[
"summary",
"Representation of ancestor classes.\n"
],
[
"discussion",
"A `CustomReflectable` class can control how its mirror will\nrepresent ancestor classes by initializing the mirror with a\n`AncestorRepresentation`. This setting has no effect on mirrors\nreflecting value type instances.\n"
]
]
},
{
"declaration" : {
"keyword" : "enum",
"name" : "DisplayStyle",
"modifiers" : [
{
"name" : "public"
}
],
"cases" : [
{
"modifiers" : [],
"attributes" : [],
"context" : "Mirror.DisplayStyle",
"name" : "struct",
"keyword" : "case"
},
{
"modifiers" : [],
"attributes" : [],
"context" : "Mirror.DisplayStyle",
"keyword" : "case",
"name" : "class"
},
{
"name" : "enum",
"keyword" : "case",
"modifiers" : [],
"context" : "Mirror.DisplayStyle",
"attributes" : []
},
{
"name" : "tuple",
"keyword" : "case",
"context" : "Mirror.DisplayStyle",
"attributes" : [],
"modifiers" : []
},
{
"keyword" : "case",
"name" : "optional",
"context" : "Mirror.DisplayStyle",
"attributes" : [],
"modifiers" : []
},
{
"name" : "collection",
"keyword" : "case",
"attributes" : [],
"context" : "Mirror.DisplayStyle",
"modifiers" : []
},
{
"context" : "Mirror.DisplayStyle",
"attributes" : [],
"modifiers" : [],
"keyword" : "case",
"name" : "dictionary"
},
{
"keyword" : "case",
"name" : "set",
"attributes" : [],
"context" : "Mirror.DisplayStyle",
"modifiers" : []
}
],
"attributes" : [],
"context" : "Mirror"
},
"documentation" : [
[
"summary",
"A suggestion of how a `Mirror`'s `subject` is to be interpreted.\n"
],
[
"discussion",
"Playgrounds and the debugger will show a representation similar\nto the one used for instances of the kind indicated by the\n`DisplayStyle` case name when the `Mirror` is used for display.\n"
]
]
},
{
"documentation" : [
[
"summary",
"The return type of functions that do not return normally; a type with no\nvalues.\n"
],
[
"discussion",
"Use `Never` as the return type when declaring a closure, function, or\nmethod that unconditionally throws an error, traps, or otherwise does\nnot terminate.\n"
],
[
"discussion",
"``` \n func crashAndBurn() -> Never {\n fatalError(\"Something very, very bad happened\")\n }\n```\n"
]
],
"declaration" : {
"keyword" : "enum",
"name" : "Never",
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"cases" : []
}
},
{
"declaration" : {
"name" : "Optional",
"keyword" : "enum",
"cases" : [
{
"name" : "none",
"keyword" : "case",
"context" : "Optional",
"attributes" : [],
"modifiers" : []
},
{
"context" : "Optional",
"attributes" : [],
"modifiers" : [],
"keyword" : "case",
"associatedValue" : [
{
"attributes" : [],
"type" : "Wrapped"
}
],
"name" : "some"
}
],
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"A type that represents either a wrapped value or `nil`, the absence of a\nvalue.\n"
],
[
"discussion",
"You use the `Optional` type whenever you use optional values, even if you\nnever type the word `Optional`. Swift's type system usually shows the\nwrapped type's name with a trailing question mark (`?`) instead of showing\nthe full type name. For example, if a variable has the type `Int?`, that's\njust another way of writing `Optional<Int>`. The shortened form is\npreferred for ease of reading and writing code.\n"
],
[
"discussion",
"The types of `shortForm` and `longForm` in the following code sample are\nthe same:\n"
],
[
"discussion",
"``` \n let shortForm: Int? = Int(\"42\")\n let longForm: Optional<Int> = Int(\"42\")\n```\n"
],
[
"discussion",
"The `Optional` type is an enumeration with two cases. `Optional.none` is\nequivalent to the `nil` literal. `Optional.some(Wrapped)` stores a wrapped\nvalue. For example:\n"
],
[
"discussion",
"``` \n let number: Int? = Optional.some(42)\n let noNumber: Int? = Optional.none\n print(noNumber == nil)\n // Prints \"true\"\n```\n"
],
[
"discussion",
"You must unwrap the value of an `Optional` instance before you can use it\nin many contexts. Because Swift provides several ways to safely unwrap\noptional values, you can choose the one that helps you write clear,\nconcise code.\n"
],
[
"discussion",
"The following examples use this dictionary of image names and file paths:\n"
],
[
"discussion",
"``` \n let imagePaths = [\"star\": \"/glyphs/star.png\",\n \"portrait\": \"/images/content/portrait.jpg\",\n \"spacer\": \"/images/shared/spacer.gif\"]\n```\n"
],
[
"discussion",
"Getting a dictionary's value using a key returns an optional value, so\n`imagePaths[\"star\"]` has type `Optional<String>` or, written in the\npreferred manner, `String?`.\n"
],
[
"discussion",
"## Optional Binding\n"
],
[
"discussion",
"To conditionally bind the wrapped value of an `Optional` instance to a new\nvariable, use one of the optional binding control structures, including\n`if let`, `guard let`, and `switch`.\n"
],
[
"discussion",
"``` \n if let starPath = imagePaths[\"star\"] {\n print(\"The star image is at '\\(starPath)'\")\n } else {\n print(\"Couldn't find the star image\")\n }\n // Prints \"The star image is at '/glyphs/star.png'\"\n```\n"
],
[
"discussion",
"## Optional Chaining\n"
],
[
"discussion",
"To safely access the properties and methods of a wrapped instance, use the\npostfix optional chaining operator (`?`). The following example uses\noptional chaining to access the `hasSuffix(_:)` method on a `String?`\ninstance.\n"
],
[
"discussion",
"``` \n if let isPNG = imagePaths[\"star\"]?.hasSuffix(\".png\") {\n print(\"The star image is in PNG format\")\n }\n // Prints \"The star image is in PNG format\"\n```\n"
],
[
"discussion",
"## Using the Nil-Coalescing Operator\n"
],
[
"discussion",
"Use the nil-coalescing operator (`??`) to supply a default value in case\nthe `Optional` instance is `nil`. Here a default path is supplied for an\nimage that is missing from `imagePaths`.\n"
],
[
"discussion",
"``` \n let defaultImagePath = \"/images/default.png\"\n let heartPath = imagePaths[\"heart\"] ?? defaultImagePath\n print(heartPath)\n // Prints \"/images/default.png\"\n```\n"
],
[
"discussion",
"The `??` operator also works with another `Optional` instance on the\nright-hand side. As a result, you can chain multiple `??` operators\ntogether.\n"
],
[
"discussion",
"``` \n let shapePath = imagePaths[\"cir\"] ?? imagePaths[\"squ\"] ?? defaultImagePath\n print(shapePath)\n // Prints \"/images/default.png\"\n```\n"
],
[
"discussion",
"## Unconditional Unwrapping\n"
],
[
"discussion",
"When you're certain that an instance of `Optional` contains a value, you\ncan unconditionally unwrap the value by using the forced\nunwrap operator (postfix `!`). For example, the result of the failable `Int`\ninitializer is unconditionally unwrapped in the example below.\n"
],
[
"discussion",
"``` \n let number = Int(\"42\")!\n print(number)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"You can also perform unconditional optional chaining by using the postfix\n`!` operator.\n"
],
[
"discussion",
"``` \n let isPNG = imagePaths[\"star\"]!.hasSuffix(\".png\")\n print(isPNG)\n // Prints \"true\"\n```\n"
],
[
"discussion",
"Unconditionally unwrapping a `nil` instance with `!` triggers a runtime\nerror.\n"
]
]
},
{
"documentation" : [
[
"summary",
"The sum of types that can be used as a Quick Look representation.\n"
]
],
"declaration" : {
"keyword" : "enum",
"name" : "PlaygroundQuickLook",
"cases" : [
{
"keyword" : "case",
"name" : "text",
"associatedValue" : [
{
"attributes" : [],
"type" : "String"
}
],
"modifiers" : [],
"attributes" : [],
"context" : "PlaygroundQuickLook"
},
{
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : [],
"associatedValue" : [
{
"attributes" : [],
"type" : "Int64"
}
],
"name" : "int",
"keyword" : "case"
},
{
"keyword" : "case",
"name" : "uInt",
"associatedValue" : [
{
"type" : "UInt64",
"attributes" : []
}
],
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : []
},
{
"attributes" : [],
"context" : "PlaygroundQuickLook",
"modifiers" : [],
"associatedValue" : [
{
"attributes" : [],
"type" : "Float32"
}
],
"name" : "float",
"keyword" : "case"
},
{
"keyword" : "case",
"name" : "double",
"associatedValue" : [
{
"type" : "Float64",
"attributes" : []
}
],
"context" : "PlaygroundQuickLook",
"attributes" : [],
"modifiers" : []
},
{
"attributes" : [],
"context" : "PlaygroundQuickLook",
"modifiers" : [],
"name" : "image",
"associatedValue" : [
{
"type" : "Any",
"attributes" : []
}
],
"keyword" : "case"
},
{
"keyword" : "case",
"name" : "sound",
"associatedValue" : [
{
"type" : "Any",
"attributes" : []
}
],
"modifiers" : [],
"attributes" : [],
"context" : "PlaygroundQuickLook"
},
{
"associatedValue" : [
{
"attributes" : [],
"type" : "Any"
}
],
"name" : "color",
"keyword" : "case",
"modifiers" : [],
"attributes" : [],
"context" : "PlaygroundQuickLook"
},
{
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : [],
"keyword" : "case",
"name" : "bezierPath",
"associatedValue" : [
{
"attributes" : [],
"type" : "Any"
}
]
},
{
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : [],
"name" : "attributedString",
"associatedValue" : [
{
"type" : "Any",
"attributes" : []
}
],
"keyword" : "case"
},
{
"keyword" : "case",
"associatedValue" : [
{
"type" : "Float64",
"attributes" : []
},
{
"type" : "Float64",
"attributes" : []
},
{
"type" : "Float64",
"attributes" : []
},
{
"attributes" : [],
"type" : "Float64"
}
],
"name" : "rectangle",
"attributes" : [],
"context" : "PlaygroundQuickLook",
"modifiers" : []
},
{
"keyword" : "case",
"name" : "point",
"associatedValue" : [
{
"attributes" : [],
"type" : "Float64"
},
{
"attributes" : [],
"type" : "Float64"
}
],
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : []
},
{
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : [],
"keyword" : "case",
"name" : "size",
"associatedValue" : [
{
"type" : "Float64",
"attributes" : []
},
{
"attributes" : [],
"type" : "Float64"
}
]
},
{
"modifiers" : [],
"attributes" : [],
"context" : "PlaygroundQuickLook",
"keyword" : "case",
"name" : "bool",
"associatedValue" : [
{
"type" : "Bool",
"attributes" : []
}
]
},
{
"attributes" : [],
"context" : "PlaygroundQuickLook",
"modifiers" : [],
"associatedValue" : [
{
"attributes" : [],
"type" : "Int64"
},
{
"attributes" : [],
"type" : "Int64"
}
],
"name" : "range",
"keyword" : "case"
},
{
"associatedValue" : [
{
"type" : "Any",
"attributes" : []
}
],
"name" : "view",
"keyword" : "case",
"attributes" : [],
"context" : "PlaygroundQuickLook",
"modifiers" : []
},
{
"name" : "sprite",
"associatedValue" : [
{
"type" : "Any",
"attributes" : []
}
],
"keyword" : "case",
"modifiers" : [],
"attributes" : [],
"context" : "PlaygroundQuickLook"
},
{
"associatedValue" : [
{
"attributes" : [],
"type" : "String"
}
],
"name" : "url",
"keyword" : "case",
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : []
},
{
"keyword" : "case",
"associatedValue" : [
{
"attributes" : [],
"type" : "[UInt8]"
},
{
"attributes" : [],
"type" : "String"
}
],
"name" : "_raw",
"modifiers" : [],
"context" : "PlaygroundQuickLook",
"attributes" : []
}
],
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"The result of one Unicode decoding step.\n"
],
[
"discussion",
"Each `UnicodeDecodingResult` instance can represent a Unicode scalar value,\nan indication that no more Unicode scalars are available, or an indication\nof a decoding error.\n"
],
[
"seealso",
"`UnicodeCodec.decode(next:)`"
]
],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"cases" : [
{
"keyword" : "case",
"name" : "scalarValue",
"associatedValue" : [
{
"attributes" : [],
"type" : "UnicodeScalar"
}
],
"modifiers" : [],
"context" : "UnicodeDecodingResult",
"attributes" : []
},
{
"name" : "emptyInput",
"keyword" : "case",
"attributes" : [],
"context" : "UnicodeDecodingResult",
"modifiers" : []
},
{
"name" : "error",
"keyword" : "case",
"context" : "UnicodeDecodingResult",
"attributes" : [],
"modifiers" : []
}
],
"keyword" : "enum",
"name" : "UnicodeDecodingResult"
}
}
],
"structures" : [
{
"declaration" : {
"keyword" : "struct",
"methods" : [
{
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyBidirectionalCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "AnyIndex",
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "AnyIndex"
}
]
}
},
{
"attributes" : [],
"name" : "formIndex(after:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyBidirectionalCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout AnyIndex"
}
]
}
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyBidirectionalCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "AnyIndex",
"input" : [
{
"name" : "_",
"type" : "AnyIndex",
"attributes" : []
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "IntMax"
}
]
},
"attributes" : [],
"name" : "index(_:offsetBy:)",
"keyword" : "func"
},
{
"context" : "AnyBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "AnyIndex",
"attributes" : []
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "IntMax"
},
{
"attributes" : [],
"type" : "AnyIndex",
"name" : "limitedBy"
}
],
"output" : "AnyIndex?"
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyBidirectionalCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "inout AnyIndex"
},
{
"attributes" : [],
"type" : "IntMax",
"name" : "offsetBy"
}
]
},
"attributes" : [],
"name" : "formIndex(_:offsetBy:)",
"keyword" : "func"
},
{
"keyword" : "func",
"name" : "formIndex(_:offsetBy:limitedBy:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "inout AnyIndex",
"attributes" : []
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "IntMax"
},
{
"name" : "limitedBy",
"attributes" : [],
"type" : "AnyIndex"
}
],
"output" : "Bool"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "AnyBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"signature" : {
"output" : "IntMax",
"input" : [
{
"name" : "from",
"type" : "AnyIndex",
"attributes" : []
},
{
"type" : "AnyIndex",
"attributes" : [],
"name" : "to"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "AnyBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)",
"context" : "AnyBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "AnyIndex",
"input" : [
{
"type" : "AnyIndex",
"attributes" : [],
"name" : "before"
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"name" : "formIndex(before:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "inout AnyIndex",
"attributes" : [],
"name" : "before"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyBidirectionalCollection"
}
],
"name" : "AnyBidirectionalCollection",
"attributes" : [],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A type-erased wrapper over any collection with indices that\nsupport bidirectional traversal.\n"
],
[
"discussion",
"An `AnyBidirectionalCollection` instance forwards its operations to a base collection having the\nsame `Element` type, hiding the specifics of the underlying\ncollection.\n"
],
[
"seealso",
"`AnyRandomAccessCollection`, `AnyForwardCollection`"
]
]
},
{
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "AnyCollection",
"methods" : [
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "AnyIndex",
"input" : [
{
"attributes" : [],
"type" : "AnyIndex",
"name" : "after"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyCollection",
"keyword" : "func",
"name" : "index(after:)",
"attributes" : []
},
{
"attributes" : [],
"name" : "formIndex(after:)",
"keyword" : "func",
"context" : "AnyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "inout AnyIndex",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"context" : "AnyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "AnyIndex",
"input" : [
{
"attributes" : [],
"type" : "AnyIndex",
"name" : "_"
},
{
"attributes" : [],
"type" : "IntMax",
"name" : "offsetBy"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)"
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "AnyIndex?",
"input" : [
{
"name" : "_",
"type" : "AnyIndex",
"attributes" : []
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "IntMax"
},
{
"name" : "limitedBy",
"type" : "AnyIndex",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyCollection",
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : []
},
{
"attributes" : [],
"name" : "formIndex(_:offsetBy:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout AnyIndex",
"name" : "_"
},
{
"name" : "offsetBy",
"type" : "IntMax",
"attributes" : []
}
]
}
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Bool",
"input" : [
{
"type" : "inout AnyIndex",
"attributes" : [],
"name" : "_"
},
{
"type" : "IntMax",
"attributes" : [],
"name" : "offsetBy"
},
{
"attributes" : [],
"type" : "AnyIndex",
"name" : "limitedBy"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyCollection",
"keyword" : "func",
"name" : "formIndex(_:offsetBy:limitedBy:)",
"attributes" : []
},
{
"context" : "AnyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "IntMax",
"input" : [
{
"name" : "from",
"type" : "AnyIndex",
"attributes" : []
},
{
"name" : "to",
"type" : "AnyIndex",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
}
],
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"A type-erased wrapper over any collection with indices that\nsupport forward traversal.\n"
],
[
"discussion",
"An `AnyCollection` instance forwards its operations to a base collection having the\nsame `Element` type, hiding the specifics of the underlying\ncollection.\n"
],
[
"seealso",
"`AnyBidirectionalCollection`, `AnyRandomAccessCollection`"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "AnyHashable"
},
"documentation" : [
[
"summary",
"A type-erased hashable value.\n"
],
[
"discussion",
"The `AnyHashable` type forwards equality comparisons and hashing operations\nto an underlying hashable value, hiding its specific underlying type.\n"
],
[
"discussion",
"You can store mixed-type keys in dictionaries and other collections that\nrequire `Hashable` conformance by wrapping mixed-type keys in\n`AnyHashable` instances:\n"
],
[
"discussion",
"``` \n let descriptions: [AnyHashable: Any] = [\n AnyHashable(\"😄\"): \"emoji\",\n AnyHashable(42): \"an Int\",\n AnyHashable(Int8(43)): \"an Int8\",\n AnyHashable(Set([\"a\", \"b\"])): \"a set of strings\"\n ]\n print(descriptions[AnyHashable(42)]!) // prints \"an Int\"\n print(descriptions[AnyHashable(43)]) // prints \"nil\"\n print(descriptions[AnyHashable(Int8(43))]!) // prints \"an Int8\"\n print(descriptions[AnyHashable(Set([\"a\", \"b\"]))]!) // prints \"a set of strings\"\n```\n"
]
]
},
{
"documentation" : [
[
"summary",
"A wrapper over an underlying index that hides the specific underlying type.\n"
],
[
"seealso",
"`AnyCollection`"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "AnyIndex",
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : []
}
},
{
"documentation" : [
[
"summary",
"A type-erased iterator of `Element`.\n"
],
[
"discussion",
"This iterator forwards its `next()` method to an arbitrary underlying\niterator having the same `Element` type, hiding the specifics of the\nunderlying `IteratorProtocol`.\n"
],
[
"seealso",
"`AnySequence`"
]
],
"declaration" : {
"attributes" : [],
"name" : "AnyIterator",
"methods" : [
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyIterator",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Element?",
"input" : []
},
"attributes" : [],
"name" : "next()",
"keyword" : "func"
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"name" : "AnyRandomAccessCollection",
"methods" : [
{
"keyword" : "func",
"name" : "index(after:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "AnyIndex"
}
],
"output" : "AnyIndex"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyRandomAccessCollection"
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "inout AnyIndex",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyRandomAccessCollection",
"keyword" : "func",
"name" : "formIndex(after:)",
"attributes" : []
},
{
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "AnyIndex"
},
{
"type" : "IntMax",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "AnyIndex"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyRandomAccessCollection"
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "AnyIndex",
"attributes" : [],
"name" : "_"
},
{
"name" : "offsetBy",
"type" : "IntMax",
"attributes" : []
},
{
"name" : "limitedBy",
"type" : "AnyIndex",
"attributes" : []
}
],
"output" : "AnyIndex?"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyRandomAccessCollection",
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(_:offsetBy:)",
"context" : "AnyRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout AnyIndex",
"name" : "_"
},
{
"name" : "offsetBy",
"type" : "IntMax",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"attributes" : [],
"name" : "formIndex(_:offsetBy:limitedBy:)",
"keyword" : "func",
"context" : "AnyRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "inout AnyIndex"
},
{
"type" : "IntMax",
"attributes" : [],
"name" : "offsetBy"
},
{
"type" : "AnyIndex",
"attributes" : [],
"name" : "limitedBy"
}
],
"output" : "Bool"
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyRandomAccessCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "AnyIndex",
"name" : "from"
},
{
"name" : "to",
"attributes" : [],
"type" : "AnyIndex"
}
],
"output" : "IntMax"
},
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
},
{
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "AnyIndex",
"name" : "before"
}
],
"output" : "AnyIndex"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "AnyRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(before:)",
"attributes" : []
},
{
"name" : "formIndex(before:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "before",
"type" : "inout AnyIndex",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "AnyRandomAccessCollection"
}
]
},
"documentation" : [
[
"summary",
"A type-erased wrapper over any collection with indices that\nsupport random access traversal.\n"
],
[
"discussion",
"An `AnyRandomAccessCollection` instance forwards its operations to a base collection having the\nsame `Element` type, hiding the specifics of the underlying\ncollection.\n"
],
[
"seealso",
"`AnyForwardCollection`, `AnyBidirectionalCollection`"
]
]
},
{
"documentation" : [
[
"summary",
"A type-erased sequence.\n"
],
[
"discussion",
"An instance of `AnySequence` forwards its operations to an underlying base\nsequence having the same `Element` type, hiding the specifics of the\nunderlying sequence.\n"
],
[
"seealso",
"`AnyIterator`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"attributes" : [],
"methods" : [],
"name" : "AnySequence",
"keyword" : "struct"
}
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"keyword" : "func",
"name" : "index(after:)",
"attributes" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "Array",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Int",
"name" : "after"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Array",
"keyword" : "func",
"name" : "formIndex(after:)",
"attributes" : []
},
{
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "before"
}
],
"output" : "Int"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "Array",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(before:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Array",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "inout Int",
"attributes" : [],
"name" : "before"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(before:)"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Array",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "Int",
"attributes" : []
},
{
"type" : "Int",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "Int"
},
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)"
},
{
"context" : "Array",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int?",
"input" : [
{
"type" : "Int",
"attributes" : [],
"name" : "_"
},
{
"attributes" : [],
"type" : "Int",
"name" : "offsetBy"
},
{
"name" : "limitedBy",
"type" : "Int",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)"
},
{
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"name" : "from",
"type" : "Int",
"attributes" : []
},
{
"name" : "to",
"type" : "Int",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Array"
}
],
"name" : "Array",
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"genericRequirements" : []
},
"documentation" : [
[
"summary",
"An ordered, random-access collection.\n"
],
[
"discussion",
"Arrays are one of the most commonly used data types in an app. You use\narrays to organize your app's data. Specifically, you use the `Array` type\nto hold elements of a single type, the array's `Element` type. An array\ncan store any kind of elements---from integers to strings to classes.\n"
],
[
"discussion",
"Swift makes it easy to create arrays in your code using an array literal:\nsimply surround a comma separated list of values with square brackets.\nWithout any other information, Swift creates an array that includes the\nspecified values, automatically inferring the array's `Element` type. For\nexample:\n"
],
[
"discussion",
"``` \n // An array of 'Int' elements\n let oddNumbers = [1, 3, 5, 7, 9, 11, 13, 15]\n\n // An array of 'String' elements\n let streets = [\"Albemarle\", \"Brandywine\", \"Chesapeake\"]\n```\n"
],
[
"discussion",
"You can create an empty array by specifying the `Element` type of your\narray in the declaration. For example:\n"
],
[
"discussion",
"``` \n // Shortened forms are preferred\n var emptyDoubles: [Double] = []\n\n // The full type name is also allowed\n var emptyFloats: Array<Float> = Array()\n```\n"
],
[
"discussion",
"If you need an array that is preinitialized with a fixed number of default\nvalues, use the `Array(repeating:count:)` initializer.\n"
],
[
"discussion",
"``` \n var digitCounts = Array(repeating: 0, count: 10)\n print(digitCounts)\n // Prints \"[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\"\n```\n"
],
[
"discussion",
"# Accessing Array Values\n"
],
[
"discussion",
"When you need to perform an operation on all of an array's elements, use a\n`for`-`in` loop to iterate through the array's contents.\n"
],
[
"discussion",
"``` \n for street in streets {\n print(\"I don't live on \\(street).\")\n }\n // Prints \"I don't live on Albemarle.\"\n // Prints \"I don't live on Brandywine.\"\n // Prints \"I don't live on Chesapeake.\"\n```\n"
],
[
"discussion",
"Use the `isEmpty` property to check quickly whether an array has any\nelements, or use the `count` property to find the number of elements in\nthe array.\n"
],
[
"discussion",
"``` \n if oddNumbers.isEmpty {\n print(\"I don't know any odd numbers.\")\n } else {\n print(\"I know \\(oddNumbers.count) odd numbers.\")\n }\n // Prints \"I know 8 odd numbers.\"\n```\n"
],
[
"discussion",
"Use the `first` and `last` properties for safe access to the value of the\narray's first and last elements. If the array is empty, these properties\nare `nil`.\n"
],
[
"discussion",
"``` \n if let firstElement = oddNumbers.first, let lastElement = oddNumbers.last {\n print(firstElement, lastElement, separator: \", \")\n }\n // Prints \"1, 15\"\n\n print(emptyDoubles.first, emptyDoubles.last, separator: \", \")\n // Prints \"nil, nil\"\n```\n"
],
[
"discussion",
"You can access individual array elements through a subscript. The first\nelement of a nonempty array is always at index zero. You can subscript an\narray with any integer from zero up to, but not including, the count of\nthe array. Using a negative number or an index equal to or greater than\n`count` triggers a runtime error. For example:\n"
],
[
"discussion",
"``` \n print(oddNumbers[0], oddNumbers[3], separator: \", \")\n // Prints \"1, 7\"\n\n print(emptyDoubles[0])\n // Triggers runtime error: Index out of range\n```\n"
],
[
"discussion",
"# Adding and Removing Elements\n"
],
[
"discussion",
"Suppose you need to store a list of the names of students that are signed\nup for a class you're teaching. During the registration period, you need\nto add and remove names as students add and drop the class.\n"
],
[
"discussion",
"``` \n var students = [\"Ben\", \"Ivy\", \"Jordell\"]\n```\n"
],
[
"discussion",
"To add single elements to the end of an array, use the `append(_:)` method.\nAdd multiple elements at the same time by passing another array or a\nsequence of any kind to the `append(contentsOf:)` method.\n"
],
[
"discussion",
"``` \n students.append(\"Maxime\")\n students.append(contentsOf: [\"Shakia\", \"William\"])\n // [\"Ben\", \"Ivy\", \"Jordell\", \"Maxime\", \"Shakia\", \"William\"]\n```\n"
],
[
"discussion",
"You can add new elements in the middle of an array by using the\n`insert(_:at:)` method for single elements and by using\n`insert(contentsOf:at:)` to insert multiple elements from another\ncollection or array literal. The elements at that index and later indices\nare shifted back to make room.\n"
],
[
"discussion",
"``` \n students.insert(\"Liam\", at: 3)\n // [\"Ben\", \"Ivy\", \"Jordell\", \"Liam\", \"Maxime\", \"Shakia\", \"William\"]\n```\n"
],
[
"discussion",
"To remove elements from an array, use the `remove(at:)`,\n`removeSubrange(_:)`, and `removeLast()` methods.\n"
],
[
"discussion",
"``` \n // Ben's family is moving to another state\n students.remove(at: 0)\n // [\"Ivy\", \"Jordell\", \"Liam\", \"Maxime\", \"Shakia\", \"William\"]\n\n // William is signing up for a different class\n students.removeLast()\n // [\"Ivy\", \"Jordell\", \"Liam\", \"Maxime\", \"Shakia\"]\n```\n"
],
[
"discussion",
"You can replace an existing element with a new value by assigning the new\nvalue to the subscript.\n"
],
[
"discussion",
"``` \n if let i = students.index(of: \"Maxime\") {\n students[i] = \"Max\"\n }\n // [\"Ivy\", \"Jordell\", \"Liam\", \"Max\", \"Shakia\"]\n```\n"
],
[
"discussion",
"## Growing the Size of an Array\n"
],
[
"discussion",
"Every array reserves a specific amount of memory to hold its contents. When\nyou add elements to an array and that array begins to exceed its reserved\ncapacity, the array allocates a larger region of memory and copies its\nelements into the new storage. The new storage is a multiple of the old\nstorage's size. This exponential growth strategy means that appending an\nelement happens in constant time, averaging the performance of many append\noperations. Append operations that trigger reallocation have a performance\ncost, but they occur less and less often as the array grows larger.\n"
],
[
"discussion",
"If you know approximately how many elements you will need to store, use the\n`reserveCapacity(_:)` method before appending to the array to avoid\nintermediate reallocations. Use the `capacity` and `count` properties to\ndetermine how many more elements the array can store without allocating\nlarger storage.\n"
],
[
"discussion",
"For arrays of most `Element` types, this storage is a contiguous block of\nmemory. For arrays with an `Element` type that is a class or `@objc`\nprotocol type, this storage can be a contiguous block of memory or an\ninstance of `NSArray`. Because any arbitrary subclass of `NSArray` can\nbecome an `Array`, there are no guarantees about representation or\nefficiency in this case.\n"
],
[
"discussion",
"# Modifying Copies of Arrays\n"
],
[
"discussion",
"Each array has an independent value that includes the values of all of its\nelements. For simple types such as integers and other structures, this\nmeans that when you change a value in one array, the value of that element\ndoes not change in any copies of the array. For example:\n"
],
[
"discussion",
"``` \n var numbers = [1, 2, 3, 4, 5]\n var numbersCopy = numbers\n numbers[0] = 100\n print(numbers)\n // Prints \"[100, 2, 3, 4, 5]\"\n print(numbersCopy)\n // Prints \"[1, 2, 3, 4, 5]\"\n```\n"
],
[
"discussion",
"If the elements in an array are instances of a class, the semantics are the\nsame, though they might appear different at first. In this case, the\nvalues stored in the array are references to objects that live outside the\narray. If you change a reference to an object in one array, only that\narray has a reference to the new object. However, if two arrays contain\nreferences to the same object, you can observe changes to that object's\nproperties from both arrays. For example:\n"
],
[
"discussion",
"``` \n // An integer type with reference semantics\n class IntegerReference {\n var value = 10\n }\n var firstIntegers = [IntegerReference(), IntegerReference()]\n var secondIntegers = firstIntegers\n\n // Modifications to an instance are visible from either array\n firstIntegers[0].value = 100\n print(secondIntegers[0].value)\n // Prints \"100\"\n\n // Replacements, additions, and removals are still visible\n // only in the modified array\n firstIntegers[0] = IntegerReference()\n print(firstIntegers[0].value)\n // Prints \"10\"\n print(secondIntegers[0].value)\n // Prints \"100\"\n```\n"
],
[
"discussion",
"Arrays, like all variable-size collections in the standard library, use\ncopy-on-write optimization. Multiple copies of an array share the same\nstorage until you modify one of the copies. When that happens, the array\nbeing modified replaces its storage with a uniquely owned copy of itself,\nwhich is then modified in place. Optimizations are sometimes applied that\ncan reduce the amount of copying.\n"
],
[
"discussion",
"This means that if an array is sharing storage with other copies, the first\nmutating operation on that array incurs the cost of copying the array. An\narray that is the sole owner of its storage can perform mutating\noperations in place.\n"
],
[
"discussion",
"In the example below, a `numbers` array is created along with two copies\nthat share the same storage. When the original `numbers` array is\nmodified, it makes a unique copy of its storage before making the\nmodification. Further modifications to `numbers` are made in place, while\nthe two copies continue to share the original storage.\n"
],
[
"discussion",
"``` \n var numbers = [1, 2, 3, 4, 5]\n var firstCopy = numbers\n var secondCopy = numbers\n\n // The storage for 'numbers' is copied here\n numbers[0] = 100\n numbers[1] = 200\n numbers[2] = 300\n // 'numbers' is [100, 200, 300, 4, 5]\n // 'firstCopy' and 'secondCopy' are [1, 2, 3, 4, 5]\n```\n"
],
[
"discussion",
"# Bridging Between Array and NSArray\n"
],
[
"discussion",
"When you need to access APIs that require data in an `NSArray` instance\ninstead of `Array`, use the type-cast operator (`as`) to bridge your\ninstance. For bridging to be possible, the `Element` type of your array\nmust be a class, an `@objc` protocol (a protocol imported from Objective-C\nor marked with the `@objc` attribute), or a type that bridges to a\nFoundation type.\n"
],
[
"discussion",
"The following example shows how you can bridge an `Array` instance to\n`NSArray` to use the `write(to:atomically:)` method. In this example, the\n`colors` array can be bridged to `NSArray` because the `colors` array's\n`String` elements bridge to `NSString`. The compiler prevents bridging the\n`moreColors` array, on the other hand, because its `Element` type is\n`Optional<String>`, which does *not* bridge to a Foundation type.\n"
],
[
"discussion",
"``` \n let colors = [\"periwinkle\", \"rose\", \"moss\"]\n let moreColors: [String?] = [\"ochre\", \"pine\"]\n\n let url = NSURL(fileURLWithPath: \"names.plist\")\n (colors as NSArray).write(to: url, atomically: true)\n // true\n\n (moreColors as NSArray).write(to: url, atomically: true)\n // error: cannot convert value of type '[String?]' to type 'NSArray'\n```\n"
],
[
"discussion",
"Bridging from `Array` to `NSArray` takes O(1) time and O(1) space if the\narray's elements are already instances of a class or an `@objc` protocol;\notherwise, it takes O(*n*) time and space.\n"
],
[
"discussion",
"When the destination array's element type is a class or an `@objc`\nprotocol, bridging from `NSArray` to `Array` first calls the `copy(with:)`\n(`- copyWithZone:` in Objective-C) method on the array to get an immutable\ncopy and then performs additional Swift bookkeeping work that takes O(1)\ntime. For instances of `NSArray` that are already immutable, `copy(with:)`\nusually returns the same array in O(1) time; otherwise, the copying\nperformance is unspecified. If `copy(with:)` returns the same array, the\ninstances of `NSArray` and `Array` share storage using the same\ncopy-on-write optimization that is used when two instances of `Array`\nshare storage.\n"
],
[
"discussion",
"When the destination array's element type is a nonclass type that bridges\nto a Foundation type, bridging from `NSArray` to `Array` performs a\nbridging copy of the elements to contiguous storage in O(*n*) time. For\nexample, bridging from `NSArray` to `Array<Int>` performs such a copy. No\nfurther bridging is required when accessing elements of the `Array`\ninstance.\n"
],
[
"note",
"The `ContiguousArray` and `ArraySlice` types are not bridged;\ninstances of those types always have a contiguous block of memory as\ntheir storage."
],
[
"seealso",
"`ContiguousArray`, `ArraySlice`, `Sequence`, `Collection`,\n`RangeReplaceableCollection`"
]
]
},
{
"declaration" : {
"attributes" : [],
"methods" : [
{
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "after"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "ArraySlice",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(after:)",
"keyword" : "func",
"attributes" : []
},
{
"context" : "ArraySlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout Int"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "formIndex(after:)",
"keyword" : "func"
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "Int"
}
],
"output" : "Int"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ArraySlice",
"name" : "index(before:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"name" : "formIndex(before:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ArraySlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "inout Int",
"attributes" : [],
"name" : "before"
}
]
}
},
{
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"name" : "_",
"type" : "Int",
"attributes" : []
},
{
"name" : "offsetBy",
"type" : "Int",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ArraySlice"
},
{
"context" : "ArraySlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int?",
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Int"
},
{
"name" : "offsetBy",
"type" : "Int",
"attributes" : []
},
{
"attributes" : [],
"type" : "Int",
"name" : "limitedBy"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "distance(from:to:)",
"context" : "ArraySlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "from"
},
{
"name" : "to",
"attributes" : [],
"type" : "Int"
}
]
},
"genericParameters" : [],
"genericRequirements" : []
}
],
"name" : "ArraySlice",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
]
},
"documentation" : [
[
"summary",
"A slice of an `Array`, `ContiguousArray`, or `ArraySlice` instance.\n"
],
[
"discussion",
"The `ArraySlice` type makes it fast and efficient for you to perform\noperations on sections of a larger array. Instead of copying over the\nelements of a slice to new storage, an `ArraySlice` instance presents a\nview onto the storage of a larger array. And because `ArraySlice`\npresents the same interface as `Array`, you can generally perform the\nsame operations on a slice as you could on the original array.\n"
],
[
"discussion",
"For more information about using arrays, see `Array` and `ContiguousArray`,\nwith which `ArraySlice` shares most properties and methods.\n"
],
[
"discussion",
"# Slices Are Views onto Arrays\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences\nfrom each class during a session.\n"
],
[
"discussion",
"``` \n let absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You want to compare the absences in the first half of the session with\nthose in the second half. To do so, start by creating two slices of the\n`absences` array.\n"
],
[
"discussion",
"``` \n let midpoint = absences.count / 2\n\n let firstHalf = absences.prefix(upTo: midpoint)\n let secondHalf = absences.suffix(from: midpoint)\n```\n"
],
[
"discussion",
"Neither the `firstHalf` nor `secondHalf` slices allocate any new storage\nof their own. Instead, each presents a view onto the storage of the\n`absences` array.\n"
],
[
"discussion",
"You can call any method on the slices that you might have called on the\n`absences` array. To learn which half had more absences, use the\n`reduce(_:_:)` method to calculate each sum.\n"
],
[
"discussion",
"``` \n let firstHalfSum = firstHalf.reduce(0, +)\n let secondHalfSum = secondHalf.reduce(0, +)\n\n if firstHalfSum > secondHalfSum {\n print(\"More absences in the first half.\")\n } else {\n print(\"More absences in the second half.\")\n }\n // Prints \"More absences in the second half.\"\n```\n"
],
[
"important",
"Long-term storage of `ArraySlice` instances is discouraged. A\nslice holds a reference to the entire storage of a larger array, not\njust to the portion it presents, even after the original array's lifetime\nends. Long-term storage of a slice may therefore prolong the lifetime of\nelements that are no longer otherwise accessible, which can appear to be\nmemory and object leakage."
],
[
"discussion",
"# Slices Maintain Indices\n"
],
[
"discussion",
"Unlike `Array` and `ContiguousArray`, the starting index for an\n`ArraySlice` instance isn't always zero. Slices maintain the same\nindices of the larger array for the same elements, so the starting\nindex of a slice depends on how it was created, letting you perform\nindex-based operations on either a full array or a slice.\n"
],
[
"discussion",
"Sharing indices between collections and their subsequences is an important\npart of the design of Swift's collection algorithms. Suppose you are\ntasked with finding the first two days with absences in the session. To\nfind the indices of the two days in question, follow these steps:\n"
],
[
"discussion",
"1) Call `index(where:)` to find the index of the first element in the\n `absences` array that is greater than zero.\n2) Create a slice of the `absences` array starting after the index found in\n step 1.\n3) Call `index(where:)` again, this time on the slice created in step 2.\n Where in some languages you might pass a starting index into an\n `indexOf` method to find the second day, in Swift you perform the same\n operation on a slice of the original array.\n4) Print the results using the indices found in steps 1 and 3 on the\n original `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n if let i = absences.index(where: { $0 > 0 }) { // 1\n let absencesAfterFirst = absences.suffix(from: i + 1) // 2\n if let j = absencesAfterFirst.index(where: { $0 > 0 }) { // 3\n print(\"The first day with absences had \\(absences[i]).\") // 4\n print(\"The second day with absences had \\(absences[j]).\")\n }\n }\n // Prints \"The first day with absences had 2.\"\n // Prints \"The second day with absences had 4.\"\n```\n"
],
[
"discussion",
"In particular, note that `j`, the index of the second day with absences,\nwas found in a slice of the original array and then used to access a value\nin the original `absences` array itself.\n"
],
[
"note",
"To safely reference the starting and ending indices of a slice,\nalways use the `startIndex` and `endIndex` properties instead of\nspecific values."
]
]
},
{
"documentation" : [
[
"summary",
"A mutable pointer-to-ObjC-pointer argument.\n"
],
[
"discussion",
"This type has implicit conversions to allow passing any of the following\nto a C or ObjC API:\n"
],
[
"discussion",
" - `nil`, which gets passed as a null pointer,\n - an inout argument of the referenced type, which gets passed as a pointer\n to a writeback temporary with autoreleasing ownership semantics,\n - an `UnsafeMutablePointer<Pointee>`, which is passed as-is.\n"
],
[
"discussion",
"Passing pointers to mutable arrays of ObjC class pointers is not\ndirectly supported. Unlike `UnsafeMutablePointer<Pointee>`,\n`AutoreleasingUnsafeMutablePointer<Pointee>` must reference storage that\ndoes not own a reference count to the referenced\nvalue. UnsafeMutablePointer's operations, by contrast, assume that\nthe referenced storage owns values loaded from or stored to it.\n"
],
[
"discussion",
"This type does not carry an owner pointer unlike the other C\\*Pointer types\nbecause it only needs to reference the results of inout conversions, which\nalready have writeback-scoped lifetime.\n"
]
],
"declaration" : {
"attributes" : [],
"name" : "AutoreleasingUnsafeMutablePointer",
"methods" : [],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Pointee",
"attributes" : []
}
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"genericRequirements" : [
"Base : _BidirectionalIndexable "
],
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"context" : "BidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "BidirectionalSlice.Index"
}
],
"output" : "BidirectionalSlice.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"signature" : {
"input" : [
{
"type" : "inout BidirectionalSlice.Index",
"attributes" : [],
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "BidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "formIndex(after:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "BidirectionalSlice",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "BidirectionalSlice.Index",
"input" : [
{
"type" : "BidirectionalSlice.Index",
"attributes" : [],
"name" : "before"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)"
},
{
"signature" : {
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "inout BidirectionalSlice.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "BidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "formIndex(before:)",
"keyword" : "func",
"attributes" : []
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "BidirectionalSlice.Index",
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "BidirectionalSlice.Index"
},
{
"name" : "offsetBy",
"type" : "BidirectionalSlice.IndexDistance",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "BidirectionalSlice",
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "BidirectionalSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "BidirectionalSlice.Index"
},
{
"type" : "BidirectionalSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
},
{
"type" : "BidirectionalSlice.Index",
"attributes" : [],
"name" : "limitedBy"
}
],
"output" : "BidirectionalSlice.Index?"
},
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func"
},
{
"context" : "BidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "BidirectionalSlice.IndexDistance",
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "BidirectionalSlice.Index"
},
{
"type" : "BidirectionalSlice.Index",
"attributes" : [],
"name" : "to"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "distance(from:to:)"
}
],
"name" : "BidirectionalSlice"
},
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `BidirectionalSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
]
]
},
{
"documentation" : [
[
"summary",
"A value type whose instances are either `true` or `false`.\n"
],
[
"discussion",
"`Bool` represents Boolean values in Swift. Create instances of `Bool` by\nusing one of the Boolean literals `true` or `false`, or by assigning the\nresult of a Boolean method or operation to a variable or constant.\n"
],
[
"discussion",
"``` \n var godotHasArrived = false\n\n let numbers = 1...5\n let containsTen = numbers.contains(10)\n print(containsTen)\n // Prints \"false\"\n\n let (a, b) = (100, 101)\n let aFirst = a < b\n print(aFirst)\n // Prints \"true\"\n```\n"
],
[
"discussion",
"Swift uses only simple Boolean values in conditional contexts to help avoid\naccidental programming errors and to help maintain the clarity of each\ncontrol statement. Unlike in other programming languages, in Swift, integers\nand strings cannot be used where a Boolean value is required.\n"
],
[
"discussion",
"For example, the following code sample does not compile, because it\nattempts to use the integer `i` in a logical context:\n"
],
[
"discussion",
"``` \n var i = 5\n while i {\n print(i)\n i -= 1\n }\n```\n"
],
[
"discussion",
"The correct approach in Swift is to compare the `i` value with zero in the\n`while` statement.\n"
],
[
"discussion",
"``` \n while i != 0 {\n print(i)\n i -= 1\n }\n```\n"
],
[
"discussion",
"# Using Imported Boolean values\n"
],
[
"discussion",
"The C `bool` and `Boolean` types and the Objective-C `BOOL` type are all\nbridged into Swift as `Bool`. The single `Bool` type in Swift guarantees\nthat functions, methods, and properties imported from C and Objective-C\nhave a consistent type interface.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "Bool",
"methods" : [],
"keyword" : "struct"
}
},
{
"documentation" : [
[
"summary",
"The corresponding Swift type to `va_list` in imported C APIs.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"name" : "CVaListPointer",
"methods" : []
}
},
{
"declaration" : {
"attributes" : [],
"methods" : [],
"name" : "Character",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : []
},
"documentation" : [
[
"summary",
"A single extended grapheme cluster, which approximates a user-perceived\ncharacter.\n"
],
[
"discussion",
"The `Character` type represents a character made up of one or more Unicode\nscalar values, grouped by a Unicode boundary algorithm. Generally, a\n`Character` instance matches what the reader of a string will perceive as\na single character. The number of visible characters is generally the most\nnatural way to count the length of a string.\n"
],
[
"discussion",
"``` \n let greeting = \"Hello! 🐥\"\n print(\"Character count: \\(greeting.characters.count)\")\n // Prints \"Character count: 8\"\n```\n"
],
[
"discussion",
"Because each character in a string can be made up of one or more Unicode\ncode points, the number of characters in a string may not match the length\nof the Unicode code point representation or the length of the string in a\nparticular binary representation.\n"
],
[
"discussion",
"``` \n print(\"Unicode code point count: \\(greeting.unicodeScalars.count)\")\n // Prints \"Unicode code point count: 15\"\n\n print(\"UTF-8 representation count: \\(greeting.utf8.count)\")\n // Prints \"UTF-8 representation count: 18\"\n```\n"
],
[
"discussion",
"Every `Character` instance is composed of one or more Unicode code points\nthat are grouped together as an *extended grapheme cluster*. The way these\ncode points are grouped is defined by a canonical, localized, or otherwise\ntailored Unicode segmentation algorithm.\n"
],
[
"discussion",
"For example, a country's Unicode flag character is made up of two regional\nindicator code points that correspond to that country's ISO 3166-1 alpha-2\ncode. The alpha-2 code for The United States is \"US\", so its flag\ncharacter is made up of the Unicode code points `\"\\u{1F1FA}\"` (REGIONAL\nINDICATOR SYMBOL LETTER U) and `\"\\u{1F1F8}\"` (REGIONAL INDICATOR SYMBOL\nLETTER S). When placed next to each other in a Swift string literal, these\ntwo code points are combined into a single grapheme cluster, represented\nby a `Character` instance in Swift.\n"
],
[
"discussion",
"``` \n let usFlag: Character = \"\\u{1F1FA}\\u{1F1F8}\"\n print(usFlag)\n // Prints \"🇺🇸\"\n```\n"
],
[
"discussion",
"For more information about the Unicode terms used in this discussion, see\nthe [Unicode.org glossary](http://www.unicode.org/glossary/). In particular, this discussion\nmentions [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster) and [Unicode scalar\nvalues](http://www.unicode.org/glossary/#unicode_scalar_value).\n"
]
]
},
{
"declaration" : {
"genericRequirements" : [
"Bound : Comparable "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Bound",
"attributes" : []
}
],
"modifiers" : [
{
"name" : "public"
}
],
"methods" : [
{
"keyword" : "func",
"name" : "contains(_:)",
"attributes" : [],
"signature" : {
"output" : "Bool",
"input" : [
{
"type" : "Bound",
"attributes" : [],
"name" : "_"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "ClosedRange",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"name" : "ClosedRange",
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"An interval over a comparable type, from a lower bound up to, and\nincluding, an upper bound.\n"
],
[
"discussion",
"You create instances of `ClosedRange` by using the closed range operator\n(`...`).\n"
],
[
"discussion",
"``` \n let lowercase = \"a\"...\"z\"\n```\n"
],
[
"discussion",
"You can use a `ClosedRange` instance to quickly check if a value is\ncontained in a particular range of values. For example:\n"
],
[
"discussion",
"``` \n print(lowercase.contains(\"c\")) // Prints \"true\"\n print(lowercase.contains(\"5\")) // Prints \"false\"\n print(lowercase.contains(\"z\")) // Prints \"true\"\n```\n"
],
[
"discussion",
"Unlike `Range`, instances of `ClosedRange` cannot represent an empty\ninterval.\n"
],
[
"discussion",
"``` \n let lowercaseA = \"a\"...\"a\"\n print(lowercaseA.isEmpty)\n // Prints \"false\"\n```\n"
],
[
"seealso",
"`CountableRange`, `Range`, `CountableClosedRange`"
]
]
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "ClosedRangeIndex",
"methods" : [],
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Bound",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [
"Bound : Comparable, ",
"Bound : _Strideable, ",
"Bound.Stride : SignedInteger "
]
},
"documentation" : [
[
"summary",
"A position in a `CountableClosedRange` instance.\n"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Bound : Comparable, ",
"Bound : _Strideable, ",
"Bound.Stride : SignedInteger "
],
"genericParameters" : [
{
"name" : "Bound",
"attributes" : []
}
],
"inheritence" : [],
"attributes" : [],
"methods" : [
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ClosedRangeIterator",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "ClosedRangeIterator<Bound>",
"input" : []
},
"attributes" : [],
"name" : "makeIterator()",
"keyword" : "func"
},
{
"keyword" : "func",
"name" : "next()",
"attributes" : [],
"signature" : {
"output" : "Bound?",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "ClosedRangeIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
]
}
],
"name" : "ClosedRangeIterator",
"keyword" : "struct"
},
"documentation" : [
[
"summary",
"An iterator over the elements of a `CountableClosedRange` instance.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A collection containing a single element of type `Element`.\n"
]
],
"declaration" : {
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "CollectionOfOne",
"methods" : [
{
"context" : "CollectionOfOne",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "after"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"attributes" : [],
"name" : "index(before:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "CollectionOfOne",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "before"
}
]
}
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "IteratorOverOne<Element>",
"input" : []
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "CollectionOfOne",
"keyword" : "func",
"name" : "makeIterator()",
"attributes" : []
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"A contiguously stored array.\n"
],
[
"discussion",
"The `ContiguousArray` type is a specialized array that always stores its\nelements in a contiguous region of memory. This contrasts with `Array`,\nwhich can store its elements in either a contiguous region of memory or an\n`NSArray` instance if its `Element` type is a class or `@objc` protocol.\n"
],
[
"discussion",
"If your array's `Element` type is a class or `@objc` protocol and you do\nnot need to bridge the array to `NSArray` or pass the array to Objective-C\nAPIs, using `ContiguousArray` may be more efficient and have more\npredictable performance than `Array`. If the array's `Element` type is a\nstruct or enumeration, `Array` and `ContiguousArray` should have similar\nefficiency.\n"
],
[
"discussion",
"For more information about using arrays, see `Array` and `ArraySlice`, with\nwhich `ContiguousArray` shares most properties and methods.\n"
]
],
"declaration" : {
"attributes" : [],
"methods" : [
{
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "ContiguousArray",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(after:)",
"attributes" : []
},
{
"name" : "formIndex(after:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout Int"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "ContiguousArray",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ContiguousArray",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "before"
}
],
"output" : "Int"
},
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)"
},
{
"context" : "ContiguousArray",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Int",
"name" : "before"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "formIndex(before:)",
"keyword" : "func"
},
{
"context" : "ContiguousArray",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int",
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Int"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "Int"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)"
},
{
"context" : "ContiguousArray",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int?",
"input" : [
{
"name" : "_",
"type" : "Int",
"attributes" : []
},
{
"type" : "Int",
"attributes" : [],
"name" : "offsetBy"
},
{
"name" : "limitedBy",
"type" : "Int",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func"
},
{
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "from"
},
{
"type" : "Int",
"attributes" : [],
"name" : "to"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "ContiguousArray",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : []
}
],
"name" : "ContiguousArray",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
]
}
},
{
"documentation" : [
[
"summary",
"A closed range that forms a collection of consecutive values.\n"
],
[
"discussion",
"You create a `CountableClosedRange` instance by using the closed range\noperator (`...`).\n"
],
[
"discussion",
"``` \n let throughFive = 0...5\n```\n"
],
[
"discussion",
"A `CountableClosedRange` instance contains both its lower bound and its\nupper bound.\n"
],
[
"discussion",
"``` \n print(throughFive.contains(3)) // Prints \"true\"\n print(throughFive.contains(10)) // Prints \"false\"\n print(throughFive.contains(5)) // Prints \"true\"\n```\n"
],
[
"discussion",
"Because a closed range includes its upper bound, a closed range whose lower\nbound is equal to the upper bound contains one element. Therefore, a\n`CountableClosedRange` instance cannot represent an empty range.\n"
],
[
"discussion",
"``` \n let zeroInclusive = 0...0\n print(zeroInclusive.isEmpty)\n // Prints \"false\"\n print(zeroInclusive.count)\n // Prints \"1\"\n```\n"
],
[
"discussion",
"You can use a `for`-`in` loop or any sequence or collection method with a\ncountable range. The elements of the range are the consecutive values from\nits lower bound up to, and including, its upper bound.\n"
],
[
"discussion",
"``` \n for n in throughFive.suffix(3) {\n print(n)\n }\n // Prints \"3\"\n // Prints \"4\"\n // Prints \"5\"\n```\n"
],
[
"discussion",
"You can create a countable range over any type that conforms to the\n`Strideable` protocol and uses an integer as its associated `Stride` type.\nBy default, Swift's integer and pointer types are usable as the bounds of\na countable range.\n"
],
[
"discussion",
"Because floating-point types such as `Float` and `Double` are their own\n`Stride` types, they cannot be used as the bounds of a countable range. If\nyou need to test whether values are contained within a closed interval\nbound by floating-point values, see the `ClosedRange` type. If you need to\niterate over consecutive floating-point values, see the\n`stride(from:through:by:)` function.\n"
],
[
"seealso",
"`CountableRange`, `ClosedRange`, `Range`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Bound",
"attributes" : []
}
],
"genericRequirements" : [
"Bound : Comparable, ",
"Bound : _Strideable, ",
"Bound.Stride : SignedInteger "
],
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : [],
"signature" : {
"output" : "ClosedRangeIterator<Bound>",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "CountableClosedRange",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "CountableClosedRange",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "CountableClosedRange.Index",
"attributes" : []
}
],
"output" : "CountableClosedRange.Index"
},
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"keyword" : "func",
"name" : "index(before:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "CountableClosedRange.Index",
"input" : [
{
"attributes" : [],
"type" : "CountableClosedRange.Index",
"name" : "before"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "CountableClosedRange"
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "CountableClosedRange.Index",
"input" : [
{
"type" : "CountableClosedRange.Index",
"attributes" : [],
"name" : "_"
},
{
"name" : "offsetBy",
"type" : "CountableClosedRange.IndexDistance",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "CountableClosedRange"
},
{
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func",
"context" : "CountableClosedRange",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "CountableClosedRange.Index",
"name" : "from"
},
{
"type" : "CountableClosedRange.Index",
"attributes" : [],
"name" : "to"
}
],
"output" : "CountableClosedRange.IndexDistance"
},
"genericRequirements" : [],
"genericParameters" : []
}
],
"name" : "CountableClosedRange"
}
},
{
"documentation" : [
[
"summary",
"A half-open range that forms a collection of consecutive values.\n"
],
[
"discussion",
"You create a `CountableRange` instance by using the half-open range\noperator (`..<`).\n"
],
[
"discussion",
"``` \n let upToFive = 0..<5\n```\n"
],
[
"discussion",
"The associated `Bound` type is both the element and index type of\n`CountableRange`. Each element of the range is its own corresponding\nindex. The lower bound of a `CountableRange` instance is its start index,\nand the upper bound is its end index.\n"
],
[
"discussion",
"``` \n print(upToFive.contains(3)) // Prints \"true\"\n print(upToFive.contains(10)) // Prints \"false\"\n print(upToFive.contains(5)) // Prints \"false\"\n```\n"
],
[
"discussion",
"If the `Bound` type has a maximal value, it can serve as an upper bound but\ncan never be contained in a `CountableRange<Bound>` instance. For example,\na `CountableRange<Int8>` instance can use `Int8.max` as its upper bound,\nbut it can't represent a range that includes `Int8.max`.\n"
],
[
"discussion",
"``` \n let maximumRange = Int8.min..<Int8.max\n print(maximumRange.contains(Int8.max))\n // Prints \"false\"\n```\n"
],
[
"discussion",
"If you need to create a range that includes the maximal value of its\n`Bound` type, see the `CountableClosedRange` type.\n"
],
[
"discussion",
"You can create a countable range over any type that conforms to the\n`Strideable` protocol and uses an integer as its associated `Stride` type.\nBy default, Swift's integer and pointer types are usable as the bounds of\na countable range.\n"
],
[
"discussion",
"Because floating-point types such as `Float` and `Double` are their own\n`Stride` types, they cannot be used as the bounds of a countable range. If\nyou need to test whether values are contained within an interval bound by\nfloating-point values, see the `Range` type. If you need to iterate over\nconsecutive floating-point values, see the `stride(from:to:by:)` function.\n"
],
[
"discussion",
"## Integer Index Ambiguity\n"
],
[
"discussion",
"Because each element of a `CountableRange` instance is its own index, for\nthe range `(-99..<100)` the element at index `0` is `0`. This is an\nunexpected result for those accustomed to zero-based collection indices,\nwho might expect the result to be `-99`. To prevent this confusion, in a\ncontext where `Bound` is known to be an integer type, subscripting\ndirectly is a compile-time error:\n"
],
[
"discussion",
"``` \n // error: ambiguous use of 'subscript'\n print((-99..<100)[0])\n```\n"
],
[
"discussion",
"However, subscripting that range still works in a generic context:\n"
],
[
"discussion",
"``` \n func brackets<T>(_ x: CountableRange<T>, _ i: T) -> T {\n return x[i] // Just forward to subscript\n }\n print(brackets(-99..<100, 0))\n // Prints \"0\"\n```\n"
],
[
"seealso",
"`CountableClosedRange`, `Range`, `ClosedRange`"
]
],
"declaration" : {
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Bound"
}
],
"genericRequirements" : [
"Bound : Comparable, ",
"Bound : _Strideable, ",
"Bound.Stride : SignedInteger "
],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "CountableRange.Index",
"input" : [
{
"type" : "CountableRange.Index",
"attributes" : [],
"name" : "after"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "CountableRange",
"name" : "index(after:)",
"keyword" : "func",
"attributes" : []
},
{
"signature" : {
"output" : "CountableRange.Index",
"input" : [
{
"attributes" : [],
"type" : "CountableRange.Index",
"name" : "before"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "CountableRange",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(before:)",
"attributes" : []
},
{
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "CountableRange.Index"
},
{
"attributes" : [],
"type" : "CountableRange.IndexDistance",
"name" : "offsetBy"
}
],
"output" : "CountableRange.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "CountableRange",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"attributes" : []
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "from",
"type" : "CountableRange.Index",
"attributes" : []
},
{
"name" : "to",
"attributes" : [],
"type" : "CountableRange.Index"
}
],
"output" : "CountableRange.IndexDistance"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "CountableRange",
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : []
}
],
"name" : "CountableRange",
"attributes" : []
}
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"context" : "DefaultBidirectionalIndices",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "DefaultBidirectionalIndices.Index"
}
],
"output" : "DefaultBidirectionalIndices.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"signature" : {
"input" : [
{
"type" : "inout DefaultBidirectionalIndices.Index",
"attributes" : [],
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "DefaultBidirectionalIndices",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "formIndex(after:)",
"attributes" : []
},
{
"name" : "index(before:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "DefaultBidirectionalIndices.Index",
"name" : "before"
}
],
"output" : "DefaultBidirectionalIndices.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "DefaultBidirectionalIndices"
},
{
"name" : "formIndex(before:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "inout DefaultBidirectionalIndices.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "DefaultBidirectionalIndices",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"name" : "DefaultBidirectionalIndices",
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Elements"
}
],
"inheritence" : [],
"genericRequirements" : [
"Elements : _BidirectionalIndexable "
]
},
"documentation" : [
[
"summary",
"A collection of indices for an arbitrary bidirectional collection.\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "DefaultIndices",
"methods" : [
{
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func",
"context" : "DefaultIndices",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "DefaultIndices.Index",
"input" : [
{
"type" : "DefaultIndices.Index",
"attributes" : [],
"name" : "after"
}
]
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"name" : "formIndex(after:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout DefaultIndices.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "DefaultIndices",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Elements",
"attributes" : []
}
],
"genericRequirements" : [
"Elements : _Indexable "
]
},
"documentation" : [
[
"summary",
"A collection of indices for an arbitrary collection.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A collection of indices for an arbitrary random-access collection.\n"
]
],
"declaration" : {
"attributes" : [],
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "DefaultRandomAccessIndices.Index",
"attributes" : [],
"name" : "after"
}
],
"output" : "DefaultRandomAccessIndices.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "DefaultRandomAccessIndices",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)",
"context" : "DefaultRandomAccessIndices",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "inout DefaultRandomAccessIndices.Index",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "DefaultRandomAccessIndices.Index",
"input" : [
{
"type" : "DefaultRandomAccessIndices.Index",
"attributes" : [],
"name" : "before"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "DefaultRandomAccessIndices",
"keyword" : "func",
"name" : "index(before:)",
"attributes" : []
},
{
"signature" : {
"input" : [
{
"name" : "before",
"type" : "inout DefaultRandomAccessIndices.Index",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "DefaultRandomAccessIndices",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "formIndex(before:)",
"attributes" : []
}
],
"name" : "DefaultRandomAccessIndices",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Elements : _RandomAccessIndexable "
],
"genericParameters" : [
{
"name" : "Elements",
"attributes" : []
}
],
"inheritence" : []
}
},
{
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "Index",
"methods" : [],
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"Used to access the key-value pairs in an instance of\n`Dictionary<Key, Value>`.\n"
],
[
"discussion",
"Dictionary has two subscripting interfaces:\n"
],
[
"discussion",
"1. Subscripting with a key, yielding an optional value:\n \n v = d[k]!\n\n2. Subscripting with an index, yielding a key-value pair:\n \n (k, v) = d[i]\n"
]
]
},
{
"documentation" : [
[
"summary",
"An iterator over the members of a `Dictionary<Key, Value>`.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Key",
"attributes" : []
},
{
"name" : "Value",
"attributes" : []
}
],
"genericRequirements" : [
"Key : Hashable "
],
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"context" : "DictionaryIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"output" : "(key: Key, value: Value)?",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "next()"
}
],
"name" : "DictionaryIterator"
}
},
{
"documentation" : [
[
"summary",
"A lightweight collection of key-value pairs.\n"
],
[
"discussion",
"Use a `DictionaryLiteral` instance when you need an ordered collection of\nkey-value pairs and don't require the fast key lookup that the\n`Dictionary` type provides. Unlike key-value pairs in a true dictionary,\nneither the key nor the value of a `DictionaryLiteral` instance must\nconform to the `Hashable` protocol.\n"
],
[
"discussion",
"You initialize a `DictionaryLiteral` instance using a Swift dictionary\nliteral. Besides maintaining the order of the original dictionary literal,\n`DictionaryLiteral` also allows duplicates keys. For example:\n"
],
[
"discussion",
"``` \n let recordTimes: DictionaryLiteral = [\"Florence Griffith-Joyner\": 10.49,\n \"Evelyn Ashford\": 10.76,\n \"Evelyn Ashford\": 10.79,\n \"Marlies Gohr\": 10.81]\n print(recordTimes.first!)\n // Prints \"(\"Florence Griffith-Joyner\", 10.49)\"\n```\n"
],
[
"discussion",
"Some operations that are efficient on a dictionary are slower when using\n`DictionaryLiteral`. In particular, to find the value matching a key, you\nmust search through every element of the collection. The call to\n`index(where:)` in the following example must traverse the whole\ncollection to find the element that matches the predicate:\n"
],
[
"discussion",
"``` \n let runner = \"Marlies Gohr\"\n if let index = recordTimes.index(where: { $0.0 == runner }) {\n let time = recordTimes[index].1\n print(\"\\(runner) set a 100m record of \\(time) seconds.\")\n } else {\n print(\"\\(runner) couldn't be found in the records.\")\n }\n // Prints \"Marlies Gohr set a 100m record of 10.81 seconds.\"\n```\n"
],
[
"discussion",
"## Dictionary Literals as Function Parameters\n"
],
[
"discussion",
"When calling a function with a `DictionaryLiteral` parameter, you can pass\na Swift dictionary literal without causing a `Dictionary` to be created.\nThis capability can be especially important when the order of elements in\nthe literal is significant.\n"
],
[
"discussion",
"For example, you could create an `IntPairs` structure that holds a list of\ntwo-integer tuples and use an initializer that accepts a\n`DictionaryLiteral` instance.\n"
],
[
"discussion",
"``` \n struct IntPairs {\n var elements: [(Int, Int)]\n\n init(_ elements: DictionaryLiteral<Int, Int>) {\n self.elements = Array(elements)\n }\n }\n```\n"
],
[
"discussion",
"When you're ready to create a new `IntPairs` instance, use a dictionary\nliteral as the parameter to the `IntPairs` initializer. The\n`DictionaryLiteral` instance preserves the order of the elements as\npassed.\n"
],
[
"discussion",
"``` \n let pairs = IntPairs([1: 2, 1: 1, 3: 4, 2: 1])\n print(pairs.elements)\n // Prints \"[(1, 2), (1, 1), (3, 4), (2, 1)]\"\n```\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Key"
},
{
"attributes" : [],
"name" : "Value"
}
],
"inheritence" : [],
"attributes" : [],
"methods" : [],
"name" : "DictionaryLiteral",
"keyword" : "struct"
}
},
{
"declaration" : {
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "Double",
"methods" : [],
"attributes" : []
},
"documentation" : [
[
"summary",
"A double-precision, floating-point value type.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A collection whose element type is `Element` but that is always empty.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"name" : "EmptyCollection",
"methods" : [
{
"context" : "EmptyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "EmptyCollection.Index",
"attributes" : []
}
],
"output" : "EmptyCollection.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(after:)"
},
{
"context" : "EmptyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "EmptyCollection.Index",
"attributes" : [],
"name" : "before"
}
],
"output" : "EmptyCollection.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "EmptyCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [],
"output" : "EmptyIterator<Element>"
},
"attributes" : [],
"name" : "makeIterator()",
"keyword" : "func"
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "EmptyCollection.Index",
"input" : [
{
"type" : "EmptyCollection.Index",
"attributes" : [],
"name" : "_"
},
{
"name" : "offsetBy",
"type" : "EmptyCollection.IndexDistance",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "EmptyCollection",
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"attributes" : []
},
{
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"context" : "EmptyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "EmptyCollection.Index"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "EmptyCollection.IndexDistance"
},
{
"name" : "limitedBy",
"attributes" : [],
"type" : "EmptyCollection.Index"
}
],
"output" : "EmptyCollection.Index?"
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"context" : "EmptyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "from",
"type" : "EmptyCollection.Index",
"attributes" : []
},
{
"name" : "to",
"attributes" : [],
"type" : "EmptyCollection.Index"
}
],
"output" : "EmptyCollection.IndexDistance"
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
}
]
}
},
{
"documentation" : [
[
"summary",
"An iterator that never produces an element.\n"
],
[
"seealso",
"`EmptyCollection<Element>`."
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "next()",
"context" : "EmptyIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [],
"output" : "Element?"
},
"genericParameters" : [],
"genericRequirements" : []
}
],
"name" : "EmptyIterator"
}
},
{
"documentation" : [
[
"summary",
"The iterator for `EnumeratedSequence`.\n"
],
[
"discussion",
"An instance of `EnumeratedIterator` wraps a base iterator and yields\nsuccessive `Int` values, starting at zero, along with the elements of the\nunderlying base iterator. The following example enumerates the elements of\nan array:\n"
],
[
"discussion",
"``` \n var iterator = [\"foo\", \"bar\"].enumerated().makeIterator()\n iterator.next() // (0, \"foo\")\n iterator.next() // (1, \"bar\")\n iterator.next() // nil\n```\n"
],
[
"discussion",
"To create an instance of `EnumeratedIterator`, call\n`enumerated().makeIterator()` on a sequence or collection.\n"
]
],
"declaration" : {
"attributes" : [],
"methods" : [
{
"keyword" : "func",
"name" : "next()",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "EnumeratedIterator.Element?"
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "EnumeratedIterator"
}
],
"name" : "EnumeratedIterator",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : IteratorProtocol "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : []
}
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "EnumeratedSequence",
"methods" : [
{
"signature" : {
"input" : [],
"output" : "EnumeratedIterator<Base.Iterator>"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "EnumeratedSequence",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : []
}
],
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : Sequence "
]
},
"documentation" : [
[
"summary",
"An enumeration of the elements of a sequence or collection.\n"
],
[
"discussion",
"`EnumeratedSequence` is a sequence of pairs (*n*, *x*), where *n*s are\nconsecutive `Int` values starting at zero, and *x*s are the elements of a\nbase sequence.\n"
],
[
"discussion",
"To create an instance of `EnumeratedSequence`, call `enumerated()` on a\nsequence or collection. The following example enumerates the elements of\nan array.\n"
],
[
"discussion",
"``` \n var s = [\"foo\", \"bar\"].enumerated()\n for (n, x) in s {\n print(\"\\(n): \\(x)\")\n }\n // Prints \"0: foo\"\n // Prints \"1: bar\"\n```\n"
]
]
},
{
"documentation" : [
[
"summary",
"A flattened view of a base collection of collections.\n"
],
[
"discussion",
"The elements of this view are a concatenation of the elements of\neach collection in the base.\n"
],
[
"discussion",
"The `joined` method is always lazy, but does not implicitly\nconfer laziness on algorithms applied to its result. In other\nwords, for ordinary collections `c`:\n"
],
[
"discussion",
" - `c.joined()` does not create new storage\n - `c.joined().map(f)` maps eagerly and returns a new array\n - `c.lazy.joined().map(f)` maps lazily and returns a `LazyMapCollection`\n\n<!-- end list -->\n"
],
[
"note",
"The performance of accessing `startIndex`, `first`, any methods\nthat depend on `startIndex`, or of advancing a `FlattenBidirectionalCollectionIndex`\ndepends on how many empty subcollections are found in the base\ncollection, and may not offer the usual performance given by\n`Collection` or `BidirectionalIndex`. Be aware, therefore, that\ngeneral operations on `FlattenBidirectionalCollection` instances may not have the\ndocumented complexity."
]
],
"declaration" : {
"keyword" : "struct",
"methods" : [
{
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : [],
"signature" : {
"output" : "FlattenIterator<Base.Iterator>",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "FlattenBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "FlattenBidirectionalCollection.Index",
"attributes" : []
}
],
"output" : "FlattenBidirectionalCollection.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "FlattenBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "index(before:)",
"attributes" : [],
"signature" : {
"output" : "FlattenBidirectionalCollection.Index",
"input" : [
{
"attributes" : [],
"type" : "FlattenBidirectionalCollection.Index",
"name" : "before"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "FlattenBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "forEach(_:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "(Base.Iterator.Element.Iterator.Element) throws -> Swift.Void",
"attributes" : []
}
],
"throwsOrRethrowsKeyword" : "rethrows"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "FlattenBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"name" : "FlattenBidirectionalCollection",
"attributes" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : BidirectionalCollection, ",
"Base.Iterator.Element : BidirectionalCollection "
],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "BaseElements"
}
],
"genericRequirements" : [
"BaseElements : BidirectionalCollection, ",
"BaseElements.Iterator.Element : BidirectionalCollection "
],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "FlattenBidirectionalCollectionIndex",
"methods" : [],
"attributes" : []
},
"documentation" : [
[
"summary",
"A position in a `FlattenBidirectionalCollection`.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A flattened view of a base collection of collections.\n"
],
[
"discussion",
"The elements of this view are a concatenation of the elements of\neach collection in the base.\n"
],
[
"discussion",
"The `joined` method is always lazy, but does not implicitly\nconfer laziness on algorithms applied to its result. In other\nwords, for ordinary collections `c`:\n"
],
[
"discussion",
" - `c.joined()` does not create new storage\n - `c.joined().map(f)` maps eagerly and returns a new array\n - `c.lazy.joined().map(f)` maps lazily and returns a `LazyMapCollection`\n\n<!-- end list -->\n"
],
[
"note",
"The performance of accessing `startIndex`, `first`, any methods\nthat depend on `startIndex`, or of advancing a `FlattenCollectionIndex`\ndepends on how many empty subcollections are found in the base\ncollection, and may not offer the usual performance given by\n`Collection` or `ForwardIndex`. Be aware, therefore, that\ngeneral operations on `FlattenCollection` instances may not have the\ndocumented complexity."
]
],
"declaration" : {
"keyword" : "struct",
"name" : "FlattenCollection",
"methods" : [
{
"context" : "FlattenCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [],
"output" : "FlattenIterator<Base.Iterator>"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "makeIterator()"
},
{
"keyword" : "func",
"name" : "index(after:)",
"attributes" : [],
"signature" : {
"output" : "FlattenCollection.Index",
"input" : [
{
"attributes" : [],
"type" : "FlattenCollection.Index",
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "FlattenCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"throwsOrRethrowsKeyword" : "rethrows",
"input" : [
{
"name" : "_",
"type" : "(Base.Iterator.Element.Iterator.Element) throws -> Swift.Void",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "FlattenCollection",
"name" : "forEach(_:)",
"keyword" : "func",
"attributes" : []
}
],
"attributes" : [],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"genericRequirements" : [
"Base : Collection, ",
"Base.Iterator.Element : Collection "
],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"attributes" : [],
"methods" : [],
"name" : "FlattenCollectionIndex",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"BaseElements : Collection, ",
"BaseElements.Iterator.Element : Collection "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "BaseElements"
}
],
"inheritence" : []
},
"documentation" : [
[
"summary",
"A position in a `FlattenCollection`.\n"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : IteratorProtocol, ",
"Base.Element : Sequence "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"attributes" : [],
"name" : "FlattenIterator",
"methods" : [
{
"context" : "FlattenIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [],
"output" : "Base.Element.Iterator.Element?"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "next()"
}
],
"keyword" : "struct"
},
"documentation" : [
[
"summary",
"An iterator that produces the elements contained in each segment\nproduced by some `Base` Iterator.\n"
],
[
"discussion",
"The elements traversed are the concatenation of those in each\nsegment produced by the base iterator.\n"
],
[
"note",
"This is the `IteratorProtocol` used by `FlattenSequence`,\n`FlattenCollection`, and `BidirectionalFlattenCollection`."
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : Sequence, ",
"Base.Iterator.Element : Sequence "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"attributes" : [],
"name" : "FlattenSequence",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "makeIterator()",
"context" : "FlattenSequence",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [],
"output" : "FlattenIterator<Base.Iterator>"
},
"genericParameters" : [],
"genericRequirements" : []
}
],
"keyword" : "struct"
},
"documentation" : [
[
"summary",
"A sequence consisting of all the elements contained in each segment\ncontained in some `Base` sequence.\n"
],
[
"discussion",
"The elements of this view are a concatenation of the elements of\neach sequence in the base.\n"
],
[
"discussion",
"The `joined` method is always lazy, but does not implicitly\nconfer laziness on algorithms applied to its result. In other\nwords, for ordinary sequences `s`:\n"
],
[
"discussion",
" - `s.joined()` does not create new storage\n - `s.joined().map(f)` maps eagerly and returns a new array\n - `s.lazy.joined().map(f)` maps lazily and returns a `LazyMapSequence`\n\n<!-- end list -->\n"
],
[
"discussion",
" - See also: `FlattenCollection`\n"
]
]
},
{
"documentation" : [
[
"summary",
"A single-precision, floating-point value type.\n"
]
],
"declaration" : {
"name" : "Float",
"methods" : [],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"An extended-precision, floating-point value type.\n"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "Float80",
"methods" : [],
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"documentation" : [
[
"summary",
"A type that iterates over a collection using its indices.\n"
],
[
"discussion",
"The `IndexingIterator` type is the default iterator for any collection that\ndoesn't declare its own. It acts as an iterator by using a collection's\nindices to step over each value in the collection. Most collections in the\nstandard library use `IndexingIterator` as their iterator.\n"
],
[
"discussion",
"By default, any custom collection type you create will inherit a\n`makeIterator()` method that returns an `IndexingIterator` instance,\nmaking it unnecessary to declare your own. When creating a custom\ncollection type, add the minimal requirements of the `Collection`\nprotocol: starting and ending indices and a subscript for accessing\nelements. With those elements defined, the inherited `makeIterator()`\nmethod satisfies the requirements of the `Sequence` protocol.\n"
],
[
"discussion",
"Here's an example of a type that declares the minimal requirements for a\ncollection. The `CollectionOfTwo` structure is a fixed-size collection\nthat always holds two elements of a specific type.\n"
],
[
"discussion",
"``` \n struct CollectionOfTwo<Element>: Collection {\n let elements: (Element, Element)\n\n init(_ first: Element, _ second: Element) {\n self.elements = (first, second)\n }\n\n var startIndex: Int { return 0 }\n var endIndex: Int { return 2 }\n\n subscript(index: Int) -> Element {\n switch index {\n case 0: return elements.0\n case 1: return elements.1\n default: fatalError(\"Index out of bounds.\")\n }\n }\n \n func index(after i: Int) -> Int {\n precondition(i < endIndex, \"Can't advance beyond endIndex\")\n return i + 1\n }\n }\n```\n"
],
[
"discussion",
"The `CollectionOfTwo` type uses the default iterator type,\n`IndexingIterator`, because it doesn't define its own `makeIterator()`\nmethod or `Iterator` associated type. This example shows how a\n`CollectionOfTwo` instance can be created holding the values of a point,\nand then iterated over using a `for`-`in` loop.\n"
],
[
"discussion",
"``` \n let point = CollectionOfTwo(15.0, 20.0)\n for element in point {\n print(element)\n }\n // Prints \"15.0\"\n // Prints \"20.0\"\n```\n"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"signature" : {
"input" : [],
"output" : "Elements._Element?"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "IndexingIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"keyword" : "func",
"name" : "next()",
"attributes" : []
}
],
"name" : "IndexingIterator",
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Elements",
"attributes" : []
}
],
"genericRequirements" : [
"Elements : _IndexableBase "
]
}
},
{
"declaration" : {
"keyword" : "struct",
"name" : "Int",
"methods" : [],
"attributes" : [],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A signed integer value type.\n"
],
[
"discussion",
"On 32-bit platforms, `Int` is the same size as `Int32`, and\non 64-bit platforms, `Int` is the same size as `Int64`.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A 16-bit signed integer value\ntype.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "Int16"
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "Int32"
},
"documentation" : [
[
"summary",
"A 32-bit signed integer value\ntype.\n"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "Int64"
},
"documentation" : [
[
"summary",
"A 64-bit signed integer value\ntype.\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "Int8",
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : []
},
"documentation" : [
[
"summary",
"An 8-bit signed integer value\ntype.\n"
]
]
},
{
"documentation" : [
[
"summary",
"An iterator that produces one or fewer instances of `Element`.\n"
]
],
"declaration" : {
"keyword" : "struct",
"name" : "IteratorOverOne",
"methods" : [
{
"context" : "IteratorOverOne",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"output" : "Element?",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "next()",
"keyword" : "func"
}
],
"attributes" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"name" : "next()",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Base.Element?",
"input" : []
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "IteratorSequence"
}
],
"name" : "IteratorSequence",
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : IteratorProtocol "
]
},
"documentation" : [
[
"summary",
"A sequence built around an iterator of type `Base`.\n"
],
[
"discussion",
"Useful mostly to recover the ability to use `for`...`in`,\ngiven just an iterator `i`:\n"
],
[
"discussion",
"``` \n for x in IteratorSequence(i) { ... }\n```\n"
]
]
},
{
"documentation" : [
[
"summary",
"An iterator that presents the elements of the sequences traversed\nby a base iterator, concatenated using a given separator.\n"
]
],
"declaration" : {
"attributes" : [],
"name" : "JoinedIterator",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "next()",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "JoinedIterator",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "Base.Element.Iterator.Element?"
}
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : IteratorProtocol, ",
"Base.Element : Sequence "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
]
}
},
{
"documentation" : [
[
"summary",
"A sequence that presents the elements of a base sequence of sequences\nconcatenated using a given separator.\n"
]
],
"declaration" : {
"methods" : [
{
"context" : "JoinedSequence",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "JoinedIterator<Base.Iterator>",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "makeIterator()",
"keyword" : "func"
}
],
"name" : "JoinedSequence",
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : Sequence, ",
"Base.Iterator.Element : Sequence "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"A collection containing the same elements as a `Base` collection,\nbut on which some operations such as `map` and `filter` are\nimplemented lazily.\n"
],
[
"discussion",
" - See also: `LazySequenceProtocol`, `LazyCollection`\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : BidirectionalCollection "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"attributes" : [],
"methods" : [],
"name" : "LazyBidirectionalCollection",
"keyword" : "struct"
}
},
{
"documentation" : [
[
"summary",
"A collection containing the same elements as a `Base` collection,\nbut on which some operations such as `map` and `filter` are\nimplemented lazily.\n"
],
[
"discussion",
" - See also: `LazySequenceProtocol`, `LazyCollection`\n"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "LazyCollection",
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"genericRequirements" : [
"Base : Collection "
]
}
},
{
"documentation" : [
[
"summary",
"A lazy `BidirectionalCollection` wrapper that includes the elements of an underlying\ncollection after any initial consecutive elements that satisfy a\npredicate.\n"
],
[
"note",
"The performance of accessing `startIndex`, `first`, or any methods\nthat depend on `startIndex` depends on how many elements satisfy the\npredicate at the start of the collection, and may not offer the usual\nperformance given by the `Collection` protocol. Be aware, therefore,\nthat general operations on `LazyDropWhileBidirectionalCollection` instances may not have the\ndocumented complexity."
]
],
"declaration" : {
"attributes" : [],
"name" : "LazyDropWhileBidirectionalCollection",
"methods" : [
{
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "LazyDropWhileBidirectionalCollection.Index"
}
],
"output" : "LazyDropWhileBidirectionalCollection.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "LazyDropWhileBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(after:)",
"attributes" : []
},
{
"keyword" : "func",
"name" : "index(before:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "LazyDropWhileBidirectionalCollection.Index",
"input" : [
{
"name" : "before",
"type" : "LazyDropWhileBidirectionalCollection.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyDropWhileBidirectionalCollection"
},
{
"signature" : {
"output" : "LazyDropWhileIterator<Base.Iterator>",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyDropWhileBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : []
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : BidirectionalCollection "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
]
}
},
{
"declaration" : {
"attributes" : [],
"name" : "LazyDropWhileCollection",
"methods" : [
{
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func",
"context" : "LazyDropWhileCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "LazyDropWhileCollection.Index",
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "LazyDropWhileCollection.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"attributes" : [],
"name" : "makeIterator()",
"keyword" : "func",
"context" : "LazyDropWhileCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [],
"output" : "LazyDropWhileIterator<Base.Iterator>"
},
"genericRequirements" : [],
"genericParameters" : []
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : Collection "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
]
},
"documentation" : [
[
"summary",
"A lazy `Collection` wrapper that includes the elements of an underlying\ncollection after any initial consecutive elements that satisfy a\npredicate.\n"
],
[
"note",
"The performance of accessing `startIndex`, `first`, or any methods\nthat depend on `startIndex` depends on how many elements satisfy the\npredicate at the start of the collection, and may not offer the usual\nperformance given by the `Collection` protocol. Be aware, therefore,\nthat general operations on `LazyDropWhileCollection` instances may not have the\ndocumented complexity."
]
]
},
{
"declaration" : {
"attributes" : [],
"name" : "LazyDropWhileIndex",
"methods" : [],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : Collection "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
]
},
"documentation" : [
[
"summary",
"A position in a `LazyDropWhileCollection` or\n`LazyDropWhileBidirectionalCollection` instance.\n"
]
]
},
{
"declaration" : {
"methods" : [
{
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "LazyDropWhileIterator",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Base.Element?",
"input" : []
},
"attributes" : [],
"keyword" : "func",
"name" : "next()"
}
],
"name" : "LazyDropWhileIterator",
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : IteratorProtocol "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"An iterator over the elements traversed by a base iterator that follow the\ninitial consecutive elements that satisfy a given predicate.\n"
],
[
"discussion",
"This is the associated iterator for the `LazyDropWhileSequence`,\n`LazyDropWhileCollection`, and `LazyDropWhileBidirectionalCollection`\ntypes.\n"
]
]
},
{
"declaration" : {
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : Sequence "
],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [],
"output" : "LazyDropWhileIterator<Base.Iterator>"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyDropWhileSequence",
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : []
}
],
"name" : "LazyDropWhileSequence",
"attributes" : []
},
"documentation" : [
[
"summary",
"A sequence whose elements consist of the elements that follow the initial\nconsecutive elements of some base sequence that satisfy a given predicate.\n"
]
]
},
{
"declaration" : {
"genericRequirements" : [
"Base : BidirectionalCollection "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "LazyFilterBidirectionalCollection",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "LazyFilterBidirectionalCollection.Index",
"attributes" : []
}
],
"output" : "LazyFilterBidirectionalCollection.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyFilterBidirectionalCollection",
"name" : "index(after:)",
"keyword" : "func",
"attributes" : []
},
{
"signature" : {
"input" : [
{
"type" : "inout LazyFilterBidirectionalCollection.Index",
"attributes" : [],
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "LazyFilterBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "formIndex(after:)",
"attributes" : []
},
{
"name" : "index(before:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "LazyFilterBidirectionalCollection.Index",
"attributes" : [],
"name" : "before"
}
],
"output" : "LazyFilterBidirectionalCollection.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyFilterBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"attributes" : [],
"name" : "formIndex(before:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyFilterBidirectionalCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "inout LazyFilterBidirectionalCollection.Index",
"attributes" : [],
"name" : "before"
}
]
}
},
{
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : [],
"signature" : {
"output" : "LazyFilterIterator<Base.Iterator>",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyFilterBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"A lazy `Collection` wrapper that includes the elements of an\nunderlying collection that satisfy a predicate.\n"
],
[
"note",
"The performance of accessing `startIndex`, `first`, any methods\nthat depend on `startIndex`, or of advancing a `LazyFilterIndex` depends\non how sparsely the filtering predicate is satisfied, and may not offer\nthe usual performance given by `Collection`. Be aware, therefore, that\ngeneral operations on `LazyFilterCollection` instances may not have the\ndocumented complexity."
]
]
},
{
"declaration" : {
"genericRequirements" : [
"Base : Collection "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "LazyFilterCollection",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "LazyFilterCollection.Index"
}
],
"output" : "LazyFilterCollection.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyFilterCollection",
"name" : "index(after:)",
"keyword" : "func",
"attributes" : []
},
{
"context" : "LazyFilterCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout LazyFilterCollection.Index"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)"
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [],
"output" : "LazyFilterIterator<Base.Iterator>"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyFilterCollection",
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : []
}
],
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"A lazy `Collection` wrapper that includes the elements of an\nunderlying collection that satisfy a predicate.\n"
],
[
"note",
"The performance of accessing `startIndex`, `first`, any methods\nthat depend on `startIndex`, or of advancing a `LazyFilterIndex` depends\non how sparsely the filtering predicate is satisfied, and may not offer\nthe usual performance given by `Collection`. Be aware, therefore, that\ngeneral operations on `LazyFilterCollection` instances may not have the\ndocumented complexity."
]
]
},
{
"documentation" : [
[
"summary",
"The `Index` used for subscripting a `LazyFilterCollection`.\n"
],
[
"discussion",
"The positions of a `LazyFilterIndex` correspond to those positions\n`p` in its underlying collection `c` such that `c[p]`\nsatisfies the predicate with which the `LazyFilterIndex` was\ninitialized.\n"
],
[
"note",
"The performance of advancing a `LazyFilterIndex`\ndepends on how sparsely the filtering predicate is satisfied,\nand may not offer the usual performance given by models of\n`Collection`."
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : Collection "
],
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "LazyFilterIndex"
}
},
{
"declaration" : {
"keyword" : "struct",
"name" : "LazyFilterIterator",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Base.Element?",
"input" : []
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "LazyFilterIterator",
"name" : "next()",
"keyword" : "func",
"attributes" : []
}
],
"attributes" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : IteratorProtocol "
],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"An iterator over the elements traversed by some base iterator that also\nsatisfy a given predicate.\n"
],
[
"note",
"This is the associated `Iterator` of `LazyFilterSequence`\nand `LazyFilterCollection`."
]
]
},
{
"declaration" : {
"name" : "LazyFilterSequence",
"methods" : [
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "LazyFilterIterator<Base.Iterator>",
"input" : []
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyFilterSequence",
"keyword" : "func",
"name" : "makeIterator()",
"attributes" : []
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : Sequence "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A sequence whose elements consist of the elements of some base\nsequence that also satisfy a given predicate.\n"
],
[
"note",
"`s.lazy.filter { ... }`, for an arbitrary sequence `s`,\nis a `LazyFilterSequence`."
]
]
},
{
"documentation" : [
[
"summary",
"A `Collection` whose elements consist of those in a `Base`\n`Collection` passed through a transform function returning `Element`.\nThese elements are computed lazily, each time they're read, by\ncalling the transform function on a base element.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
},
{
"attributes" : [],
"name" : "Element"
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : BidirectionalCollection "
],
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"keyword" : "func",
"name" : "index(after:)",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "LazyMapBidirectionalCollection.Index",
"attributes" : [],
"name" : "after"
}
],
"output" : "LazyMapBidirectionalCollection.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "LazyMapBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"context" : "LazyMapBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout LazyMapBidirectionalCollection.Index",
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapBidirectionalCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "LazyMapBidirectionalCollection.Index",
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "LazyMapBidirectionalCollection.Index"
}
]
}
},
{
"name" : "formIndex(before:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "inout LazyMapBidirectionalCollection.Index",
"attributes" : [],
"name" : "before"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyMapBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "LazyMapBidirectionalCollection.Index",
"attributes" : []
},
{
"attributes" : [],
"type" : "Base.IndexDistance",
"name" : "offsetBy"
}
],
"output" : "LazyMapBidirectionalCollection.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapBidirectionalCollection"
},
{
"signature" : {
"output" : "LazyMapBidirectionalCollection.Index?",
"input" : [
{
"attributes" : [],
"type" : "LazyMapBidirectionalCollection.Index",
"name" : "_"
},
{
"name" : "offsetBy",
"type" : "Base.IndexDistance",
"attributes" : []
},
{
"type" : "LazyMapBidirectionalCollection.Index",
"attributes" : [],
"name" : "limitedBy"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyMapBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"attributes" : []
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Base.IndexDistance",
"input" : [
{
"name" : "from",
"type" : "LazyMapBidirectionalCollection.Index",
"attributes" : []
},
{
"name" : "to",
"attributes" : [],
"type" : "LazyMapBidirectionalCollection.Index"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapBidirectionalCollection",
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapBidirectionalCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "LazyMapIterator<Base.Iterator, Element>",
"input" : []
},
"attributes" : [],
"keyword" : "func",
"name" : "makeIterator()"
}
],
"name" : "LazyMapBidirectionalCollection"
}
},
{
"documentation" : [
[
"summary",
"A `Collection` whose elements consist of those in a `Base`\n`Collection` passed through a transform function returning `Element`.\nThese elements are computed lazily, each time they're read, by\ncalling the transform function on a base element.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
},
{
"attributes" : [],
"name" : "Element"
}
],
"genericRequirements" : [
"Base : Collection "
],
"attributes" : [],
"keyword" : "struct",
"name" : "LazyMapCollection",
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "LazyMapCollection.Index",
"input" : [
{
"attributes" : [],
"type" : "LazyMapCollection.Index",
"name" : "after"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapCollection"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout LazyMapCollection.Index"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "LazyMapCollection.Index",
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "LazyMapCollection.Index"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "Base.IndexDistance"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)"
},
{
"signature" : {
"output" : "LazyMapCollection.Index?",
"input" : [
{
"attributes" : [],
"type" : "LazyMapCollection.Index",
"name" : "_"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "Base.IndexDistance"
},
{
"name" : "limitedBy",
"type" : "LazyMapCollection.Index",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyMapCollection",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"attributes" : []
},
{
"keyword" : "func",
"name" : "distance(from:to:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Base.IndexDistance",
"input" : [
{
"name" : "from",
"type" : "LazyMapCollection.Index",
"attributes" : []
},
{
"type" : "LazyMapCollection.Index",
"attributes" : [],
"name" : "to"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapCollection"
},
{
"signature" : {
"input" : [],
"output" : "LazyMapIterator<Base.Iterator, Element>"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyMapCollection",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : []
}
]
}
},
{
"documentation" : [
[
"summary",
"The `IteratorProtocol` used by `MapSequence` and `MapCollection`.\nProduces each element by passing the output of the `Base`\n`IteratorProtocol` through a transform function returning `Element`.\n"
]
],
"declaration" : {
"keyword" : "struct",
"name" : "LazyMapIterator",
"methods" : [
{
"context" : "LazyMapIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [],
"output" : "Element?"
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "next()",
"keyword" : "func"
}
],
"attributes" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
},
{
"attributes" : [],
"name" : "Element"
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : IteratorProtocol "
],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"A `Collection` whose elements consist of those in a `Base`\n`Collection` passed through a transform function returning `Element`.\nThese elements are computed lazily, each time they're read, by\ncalling the transform function on a base element.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : RandomAccessCollection "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
},
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"attributes" : [],
"name" : "LazyMapRandomAccessCollection",
"methods" : [
{
"context" : "LazyMapRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "LazyMapRandomAccessCollection.Index",
"input" : [
{
"name" : "after",
"type" : "LazyMapRandomAccessCollection.Index",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"attributes" : [],
"name" : "formIndex(after:)",
"keyword" : "func",
"context" : "LazyMapRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout LazyMapRandomAccessCollection.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "LazyMapRandomAccessCollection.Index",
"input" : [
{
"name" : "before",
"type" : "LazyMapRandomAccessCollection.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapRandomAccessCollection",
"keyword" : "func",
"name" : "index(before:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapRandomAccessCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "before",
"type" : "inout LazyMapRandomAccessCollection.Index",
"attributes" : []
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(before:)"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapRandomAccessCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "LazyMapRandomAccessCollection.Index"
},
{
"type" : "Base.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "LazyMapRandomAccessCollection.Index"
},
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyMapRandomAccessCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "LazyMapRandomAccessCollection.Index"
},
{
"name" : "offsetBy",
"type" : "Base.IndexDistance",
"attributes" : []
},
{
"name" : "limitedBy",
"type" : "LazyMapRandomAccessCollection.Index",
"attributes" : []
}
],
"output" : "LazyMapRandomAccessCollection.Index?"
}
},
{
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "LazyMapRandomAccessCollection.Index",
"name" : "from"
},
{
"name" : "to",
"attributes" : [],
"type" : "LazyMapRandomAccessCollection.Index"
}
],
"output" : "Base.IndexDistance"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "LazyMapRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "distance(from:to:)",
"attributes" : []
},
{
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : [],
"signature" : {
"output" : "LazyMapIterator<Base.Iterator, Element>",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "LazyMapRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"keyword" : "struct"
}
},
{
"declaration" : {
"name" : "LazyMapSequence",
"methods" : [
{
"signature" : {
"input" : [],
"output" : "LazyMapIterator<Base.Iterator, Element>"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "LazyMapSequence",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "makeIterator()",
"attributes" : []
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : Sequence "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
},
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A `Sequence` whose elements consist of those in a `Base`\n`Sequence` passed through a transform function returning `Element`.\nThese elements are computed lazily, each time they're read, by\ncalling the transform function on a base element.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A lazy `BidirectionalCollection` wrapper that includes the initial consecutive\nelements of an underlying collection that satisfy a predicate.\n"
],
[
"note",
"The performance of accessing `endIndex`, `last`, any methods that\ndepend on `endIndex`, or moving an index depends on how many elements\nsatisfy the predicate at the start of the collection, and may not offer\nthe usual performance given by the `Collection` protocol. Be aware,\ntherefore, that general operations on `LazyPrefixWhileBidirectionalCollection` instances may not have\nthe documented complexity."
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : BidirectionalCollection "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"attributes" : [],
"methods" : [
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyPrefixWhileBidirectionalCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "LazyPrefixWhileBidirectionalCollection.Index"
}
],
"output" : "LazyPrefixWhileBidirectionalCollection.Index"
},
"attributes" : [],
"keyword" : "func",
"name" : "index(after:)"
},
{
"signature" : {
"input" : [
{
"type" : "LazyPrefixWhileBidirectionalCollection.Index",
"attributes" : [],
"name" : "before"
}
],
"output" : "LazyPrefixWhileBidirectionalCollection.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "LazyPrefixWhileBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(before:)",
"attributes" : []
},
{
"context" : "LazyPrefixWhileBidirectionalCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "LazyPrefixWhileIterator<Base.Iterator>",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "makeIterator()",
"keyword" : "func"
}
],
"name" : "LazyPrefixWhileBidirectionalCollection",
"keyword" : "struct"
}
},
{
"documentation" : [
[
"summary",
"A lazy `Collection` wrapper that includes the initial consecutive\nelements of an underlying collection that satisfy a predicate.\n"
],
[
"note",
"The performance of accessing `endIndex`, `last`, any methods that\ndepend on `endIndex`, or moving an index depends on how many elements\nsatisfy the predicate at the start of the collection, and may not offer\nthe usual performance given by the `Collection` protocol. Be aware,\ntherefore, that general operations on `LazyPrefixWhileCollection` instances may not have\nthe documented complexity."
]
],
"declaration" : {
"keyword" : "struct",
"name" : "LazyPrefixWhileCollection",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "index(after:)",
"context" : "LazyPrefixWhileCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "LazyPrefixWhileCollection.Index"
}
],
"output" : "LazyPrefixWhileCollection.Index"
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "LazyPrefixWhileIterator<Base.Iterator>",
"input" : []
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyPrefixWhileCollection",
"keyword" : "func",
"name" : "makeIterator()",
"attributes" : []
}
],
"attributes" : [],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"genericRequirements" : [
"Base : Collection "
],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : Collection "
],
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "LazyPrefixWhileIndex"
},
"documentation" : [
[
"summary",
"A position in a `LazyPrefixWhileCollection` or\n`LazyPrefixWhileBidirectionalCollection` instance.\n"
]
]
},
{
"declaration" : {
"methods" : [
{
"attributes" : [],
"name" : "next()",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "LazyPrefixWhileIterator",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Base.Element?",
"input" : []
}
}
],
"name" : "LazyPrefixWhileIterator",
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : IteratorProtocol "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"An iterator over the initial elements traversed by a base iterator that\nsatisfy a given predicate.\n"
],
[
"discussion",
"This is the associated iterator for the `LazyPrefixWhileSequence`,\n`LazyPrefixWhileCollection`, and `LazyPrefixWhileBidirectionalCollection`\ntypes.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A sequence whose elements consist of the initial consecutive elements of\nsome base sequence that satisfy a given predicate.\n"
]
],
"declaration" : {
"attributes" : [],
"methods" : [
{
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "LazyPrefixWhileIterator<Base.Iterator>",
"input" : []
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "LazyPrefixWhileSequence"
}
],
"name" : "LazyPrefixWhileSequence",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : Sequence "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
]
}
},
{
"declaration" : {
"methods" : [],
"name" : "LazyRandomAccessCollection",
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : RandomAccessCollection "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A collection containing the same elements as a `Base` collection,\nbut on which some operations such as `map` and `filter` are\nimplemented lazily.\n"
],
[
"discussion",
" - See also: `LazySequenceProtocol`, `LazyCollection`\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [],
"name" : "LazySequence",
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"genericRequirements" : [
"Base : Sequence "
]
},
"documentation" : [
[
"summary",
"A sequence containing the same elements as a `Base` sequence, but\non which some operations such as `map` and `filter` are\nimplemented lazily.\n"
],
[
"discussion",
" - See also: `LazySequenceProtocol`\n"
]
]
},
{
"declaration" : {
"name" : "ManagedBufferPointer",
"methods" : [
{
"signature" : {
"output" : "R",
"throwsOrRethrowsKeyword" : "rethrows ",
"input" : [
{
"attributes" : [],
"type" : "(UnsafeMutablePointer<Header>) throws -> R",
"name" : "_"
}
]
},
"genericParameters" : [
{
"attributes" : [],
"name" : "R"
}
],
"genericRequirements" : [],
"context" : "ManagedBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "withUnsafeMutablePointerToHeader(_:)",
"attributes" : []
},
{
"genericParameters" : [
{
"name" : "R",
"attributes" : []
}
],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "(UnsafeMutablePointer<Element>) throws -> R"
}
],
"throwsOrRethrowsKeyword" : "rethrows ",
"output" : "R"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ManagedBufferPointer",
"keyword" : "func",
"name" : "withUnsafeMutablePointerToElements(_:)",
"attributes" : []
},
{
"context" : "ManagedBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "R",
"throwsOrRethrowsKeyword" : "rethrows ",
"input" : [
{
"name" : "_",
"type" : "(UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "R",
"attributes" : []
}
],
"attributes" : [],
"name" : "withUnsafeMutablePointers(_:)",
"keyword" : "func"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "isUniqueReference()",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "ManagedBufferPointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Bool",
"input" : []
}
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Header",
"attributes" : []
},
{
"attributes" : [],
"name" : "Element"
}
],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Contains a buffer object, and provides access to an instance of\n`Header` and contiguous storage for an arbitrary number of\n`Element` instances stored in that buffer.\n"
],
[
"discussion",
"For most purposes, the `ManagedBuffer` class works fine for this\npurpose, and can simply be used on its own. However, in cases\nwhere objects of various different classes must serve as storage,\n`ManagedBufferPointer` is needed.\n"
],
[
"discussion",
"A valid buffer class is non-`@objc`, with no declared stored\nproperties. Its `deinit` must destroy its\nstored `Header` and any constructed `Element`s.\n"
],
[
"discussion",
"## Example Buffer Class\n"
],
[
"discussion",
"``` \n class MyBuffer<Element> { // non-@objc\n typealias Manager = ManagedBufferPointer<(Int, String), Element>\n deinit {\n Manager(unsafeBufferObject: self).withUnsafeMutablePointers {\n (pointerToHeader, pointerToElements) -> Void in\n pointerToElements.deinitialize(count: self.count)\n pointerToHeader.deinitialize()\n }\n }\n\n // All properties are *computed* based on members of the Header\n var count: Int {\n return Manager(unsafeBufferObject: self).header.0\n }\n var name: String {\n return Manager(unsafeBufferObject: self).header.1\n }\n }\n```\n"
]
]
},
{
"declaration" : {
"name" : "Mirror",
"methods" : [],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Representation of the sub-structure and optional \"display style\"\nof any arbitrary subject instance.\n"
],
[
"discussion",
"Describes the parts---such as stored properties, collection\nelements, tuple elements, or the active enumeration case---that\nmake up a particular instance. May also supply a \"display style\"\nproperty that suggests how this structure might be rendered.\n"
],
[
"discussion",
"Mirrors are used by playgrounds and the debugger.\n"
]
]
},
{
"declaration" : {
"name" : "MutableBidirectionalSlice",
"methods" : [
{
"context" : "MutableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "MutableBidirectionalSlice.Index",
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "MutableBidirectionalSlice.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableBidirectionalSlice",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "inout MutableBidirectionalSlice.Index",
"attributes" : [],
"name" : "after"
}
]
}
},
{
"keyword" : "func",
"name" : "index(before:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "MutableBidirectionalSlice.Index"
}
],
"output" : "MutableBidirectionalSlice.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableBidirectionalSlice"
},
{
"signature" : {
"input" : [
{
"type" : "inout MutableBidirectionalSlice.Index",
"attributes" : [],
"name" : "before"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "formIndex(before:)",
"keyword" : "func",
"attributes" : []
},
{
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "MutableBidirectionalSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"type" : "MutableBidirectionalSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "MutableBidirectionalSlice.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "MutableBidirectionalSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"attributes" : [],
"type" : "MutableBidirectionalSlice.IndexDistance",
"name" : "offsetBy"
},
{
"name" : "limitedBy",
"attributes" : [],
"type" : "MutableBidirectionalSlice.Index"
}
],
"output" : "MutableBidirectionalSlice.Index?"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableBidirectionalSlice"
},
{
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "MutableBidirectionalSlice.Index"
},
{
"name" : "to",
"attributes" : [],
"type" : "MutableBidirectionalSlice.Index"
}
],
"output" : "MutableBidirectionalSlice.IndexDistance"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : _BidirectionalIndexable, ",
"Base : _MutableIndexable "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `MutableBidirectionalSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
],
[
"note",
"`MutableBidirectionalSlice` requires that the base collection's `subscript(_: Index)`\nsetter does not invalidate indices. If you are writing a collection and\nmutations need to invalidate indices, don't use `MutableBidirectionalSlice` as its\nsubsequence type. Instead, use the nonmutable `Slice` or define your own\nsubsequence type that takes your index invalidation requirements into\naccount."
]
]
},
{
"declaration" : {
"keyword" : "struct",
"methods" : [
{
"context" : "MutableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "MutableRandomAccessSlice.Index",
"input" : [
{
"type" : "MutableRandomAccessSlice.Index",
"attributes" : [],
"name" : "after"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"name" : "formIndex(after:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "inout MutableRandomAccessSlice.Index",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"signature" : {
"output" : "MutableRandomAccessSlice.Index",
"input" : [
{
"name" : "before",
"type" : "MutableRandomAccessSlice.Index",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(before:)",
"keyword" : "func",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRandomAccessSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "inout MutableRandomAccessSlice.Index",
"attributes" : [],
"name" : "before"
}
]
},
"attributes" : [],
"name" : "formIndex(before:)",
"keyword" : "func"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"context" : "MutableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "MutableRandomAccessSlice.Index",
"input" : [
{
"type" : "MutableRandomAccessSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "MutableRandomAccessSlice.IndexDistance"
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "MutableRandomAccessSlice.Index",
"attributes" : []
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "MutableRandomAccessSlice.IndexDistance"
},
{
"name" : "limitedBy",
"type" : "MutableRandomAccessSlice.Index",
"attributes" : []
}
],
"output" : "MutableRandomAccessSlice.Index?"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRandomAccessSlice",
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"attributes" : []
},
{
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "MutableRandomAccessSlice.Index",
"attributes" : [],
"name" : "from"
},
{
"name" : "to",
"type" : "MutableRandomAccessSlice.Index",
"attributes" : []
}
],
"output" : "MutableRandomAccessSlice.IndexDistance"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRandomAccessSlice"
}
],
"name" : "MutableRandomAccessSlice",
"attributes" : [],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"genericRequirements" : [
"Base : _MutableIndexable, ",
"Base : _RandomAccessIndexable "
],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `MutableRandomAccessSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
],
[
"note",
"`MutableRandomAccessSlice` requires that the base collection's `subscript(_: Index)`\nsetter does not invalidate indices. If you are writing a collection and\nmutations need to invalidate indices, don't use `MutableRandomAccessSlice` as its\nsubsequence type. Instead, use the nonmutable `Slice` or define your own\nsubsequence type that takes your index invalidation requirements into\naccount."
]
]
},
{
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `MutableRangeReplaceableBidirectionalSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
],
[
"note",
"`MutableRangeReplaceableBidirectionalSlice` requires that the base collection's `subscript(_: Index)`\nsetter does not invalidate indices. If you are writing a collection and\nmutations need to invalidate indices, don't use `MutableRangeReplaceableBidirectionalSlice` as its\nsubsequence type. Instead, use the nonmutable `Slice` or define your own\nsubsequence type that takes your index invalidation requirements into\naccount."
]
],
"declaration" : {
"genericRequirements" : [
"Base : _BidirectionalIndexable, ",
"Base : _MutableIndexable, ",
"Base : _RangeReplaceableIndexable "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
],
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"attributes" : []
}
],
"output" : "MutableRangeReplaceableBidirectionalSlice.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)",
"context" : "MutableRangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "inout MutableRangeReplaceableBidirectionalSlice.Index",
"attributes" : [],
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"attributes" : [],
"name" : "index(before:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "MutableRangeReplaceableBidirectionalSlice.Index",
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "MutableRangeReplaceableBidirectionalSlice.Index"
}
]
}
},
{
"keyword" : "func",
"name" : "formIndex(before:)",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "inout MutableRangeReplaceableBidirectionalSlice.Index",
"attributes" : [],
"name" : "before"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "MutableRangeReplaceableBidirectionalSlice.Index",
"input" : [
{
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"type" : "MutableRangeReplaceableBidirectionalSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableBidirectionalSlice"
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "MutableRangeReplaceableBidirectionalSlice.Index?",
"input" : [
{
"attributes" : [],
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"name" : "_"
},
{
"type" : "MutableRangeReplaceableBidirectionalSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
},
{
"name" : "limitedBy",
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "distance(from:to:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "MutableRangeReplaceableBidirectionalSlice.IndexDistance",
"input" : [
{
"attributes" : [],
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"name" : "from"
},
{
"name" : "to",
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"attributes" : []
}
]
}
},
{
"keyword" : "func",
"name" : "replaceSubrange(_:with:)",
"attributes" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Range<MutableRangeReplaceableBidirectionalSlice.Index>",
"name" : "_"
},
{
"type" : "C",
"attributes" : [],
"name" : "with"
}
]
},
"genericParameters" : [
{
"name" : "C",
"attributes" : []
}
],
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == Base._Element"
],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
]
},
{
"keyword" : "func",
"name" : "insert(_:at:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "Base._Element",
"attributes" : [],
"name" : "_"
},
{
"name" : "at",
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "MutableRangeReplaceableBidirectionalSlice"
},
{
"context" : "MutableRangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "S",
"name" : "contentsOf"
},
{
"name" : "at",
"attributes" : [],
"type" : "MutableRangeReplaceableBidirectionalSlice.Index"
}
]
},
"genericRequirements" : [
"S : Collection, ",
"S.Iterator.Element == Base._Element"
],
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"attributes" : [],
"name" : "insert(contentsOf:at:)",
"keyword" : "func"
},
{
"attributes" : [],
"name" : "remove(at:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Base._Element",
"input" : [
{
"attributes" : [],
"type" : "MutableRangeReplaceableBidirectionalSlice.Index",
"name" : "at"
}
]
}
},
{
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Range<MutableRangeReplaceableBidirectionalSlice.Index>",
"name" : "_"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableRangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"name" : "removeSubrange(_:)",
"keyword" : "func",
"attributes" : []
}
],
"name" : "MutableRangeReplaceableBidirectionalSlice",
"keyword" : "struct",
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `MutableRangeReplaceableRandomAccessSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
],
[
"note",
"`MutableRangeReplaceableRandomAccessSlice` requires that the base collection's `subscript(_: Index)`\nsetter does not invalidate indices. If you are writing a collection and\nmutations need to invalidate indices, don't use `MutableRangeReplaceableRandomAccessSlice` as its\nsubsequence type. Instead, use the nonmutable `Slice` or define your own\nsubsequence type that takes your index invalidation requirements into\naccount."
]
],
"declaration" : {
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : _MutableIndexable, ",
"Base : _RandomAccessIndexable, ",
"Base : _RangeReplaceableIndexable "
],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "MutableRangeReplaceableRandomAccessSlice",
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "MutableRangeReplaceableRandomAccessSlice.Index"
}
],
"output" : "MutableRangeReplaceableRandomAccessSlice.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableRandomAccessSlice"
},
{
"context" : "MutableRangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout MutableRangeReplaceableRandomAccessSlice.Index"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)"
},
{
"attributes" : [],
"name" : "index(before:)",
"keyword" : "func",
"context" : "MutableRangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "MutableRangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "before"
}
],
"output" : "MutableRangeReplaceableRandomAccessSlice.Index"
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "inout MutableRangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "before"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableRandomAccessSlice",
"keyword" : "func",
"name" : "formIndex(before:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableRandomAccessSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "MutableRangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "MutableRangeReplaceableRandomAccessSlice.IndexDistance"
}
],
"output" : "MutableRangeReplaceableRandomAccessSlice.Index"
},
"attributes" : [],
"name" : "index(_:offsetBy:)",
"keyword" : "func"
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "MutableRangeReplaceableRandomAccessSlice.Index",
"attributes" : []
},
{
"attributes" : [],
"type" : "MutableRangeReplaceableRandomAccessSlice.IndexDistance",
"name" : "offsetBy"
},
{
"attributes" : [],
"type" : "MutableRangeReplaceableRandomAccessSlice.Index",
"name" : "limitedBy"
}
],
"output" : "MutableRangeReplaceableRandomAccessSlice.Index?"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableRandomAccessSlice"
},
{
"context" : "MutableRangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "MutableRangeReplaceableRandomAccessSlice.IndexDistance",
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "MutableRangeReplaceableRandomAccessSlice.Index"
},
{
"name" : "to",
"type" : "MutableRangeReplaceableRandomAccessSlice.Index",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
},
{
"name" : "replaceSubrange(_:with:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Range<MutableRangeReplaceableRandomAccessSlice.Index>"
},
{
"attributes" : [],
"type" : "C",
"name" : "with"
}
]
},
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == Base._Element"
],
"genericParameters" : [
{
"name" : "C",
"attributes" : []
}
],
"context" : "MutableRangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
]
},
{
"context" : "MutableRangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Base._Element"
},
{
"name" : "at",
"attributes" : [],
"type" : "MutableRangeReplaceableRandomAccessSlice.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "insert(_:at:)",
"keyword" : "func"
},
{
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"genericRequirements" : [
"S : Collection, ",
"S.Iterator.Element == Base._Element"
],
"signature" : {
"input" : [
{
"type" : "S",
"attributes" : [],
"name" : "contentsOf"
},
{
"attributes" : [],
"type" : "MutableRangeReplaceableRandomAccessSlice.Index",
"name" : "at"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "MutableRangeReplaceableRandomAccessSlice",
"keyword" : "func",
"name" : "insert(contentsOf:at:)",
"attributes" : []
},
{
"signature" : {
"output" : "Base._Element",
"input" : [
{
"type" : "MutableRangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "at"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableRangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"name" : "remove(at:)",
"keyword" : "func",
"attributes" : []
},
{
"signature" : {
"input" : [
{
"type" : "Range<MutableRangeReplaceableRandomAccessSlice.Index>",
"attributes" : [],
"name" : "_"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableRangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"name" : "removeSubrange(_:)",
"keyword" : "func",
"attributes" : []
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `MutableRangeReplaceableSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
],
[
"note",
"`MutableRangeReplaceableSlice` requires that the base collection's `subscript(_: Index)`\nsetter does not invalidate indices. If you are writing a collection and\nmutations need to invalidate indices, don't use `MutableRangeReplaceableSlice` as its\nsubsequence type. Instead, use the nonmutable `Slice` or define your own\nsubsequence type that takes your index invalidation requirements into\naccount."
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : _MutableIndexable, ",
"Base : _RangeReplaceableIndexable "
],
"attributes" : [],
"keyword" : "struct",
"name" : "MutableRangeReplaceableSlice",
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "MutableRangeReplaceableSlice.Index",
"input" : [
{
"name" : "after",
"type" : "MutableRangeReplaceableSlice.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableSlice"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableSlice",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout MutableRangeReplaceableSlice.Index"
}
]
}
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "MutableRangeReplaceableSlice.Index",
"attributes" : []
},
{
"type" : "MutableRangeReplaceableSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "MutableRangeReplaceableSlice.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "MutableRangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableRangeReplaceableSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "MutableRangeReplaceableSlice.Index?",
"input" : [
{
"name" : "_",
"type" : "MutableRangeReplaceableSlice.Index",
"attributes" : []
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "MutableRangeReplaceableSlice.IndexDistance"
},
{
"name" : "limitedBy",
"type" : "MutableRangeReplaceableSlice.Index",
"attributes" : []
}
]
}
},
{
"context" : "MutableRangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "MutableRangeReplaceableSlice.IndexDistance",
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "MutableRangeReplaceableSlice.Index"
},
{
"name" : "to",
"attributes" : [],
"type" : "MutableRangeReplaceableSlice.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
},
{
"name" : "replaceSubrange(_:with:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == Base._Element"
],
"genericParameters" : [
{
"name" : "C",
"attributes" : []
}
],
"signature" : {
"input" : [
{
"type" : "Range<MutableRangeReplaceableSlice.Index>",
"attributes" : [],
"name" : "_"
},
{
"name" : "with",
"attributes" : [],
"type" : "C"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "MutableRangeReplaceableSlice"
},
{
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Base._Element"
},
{
"name" : "at",
"attributes" : [],
"type" : "MutableRangeReplaceableSlice.Index"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "MutableRangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"keyword" : "func",
"name" : "insert(_:at:)",
"attributes" : []
},
{
"attributes" : [],
"name" : "insert(contentsOf:at:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "MutableRangeReplaceableSlice",
"genericRequirements" : [
"S : Collection, ",
"S.Iterator.Element == Base._Element"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"signature" : {
"input" : [
{
"name" : "contentsOf",
"type" : "S",
"attributes" : []
},
{
"name" : "at",
"type" : "MutableRangeReplaceableSlice.Index",
"attributes" : []
}
]
}
},
{
"name" : "remove(at:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Base._Element",
"input" : [
{
"attributes" : [],
"type" : "MutableRangeReplaceableSlice.Index",
"name" : "at"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "MutableRangeReplaceableSlice"
},
{
"attributes" : [],
"name" : "removeSubrange(_:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "MutableRangeReplaceableSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Range<MutableRangeReplaceableSlice.Index>",
"name" : "_"
}
]
}
}
]
}
},
{
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `MutableSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
],
[
"note",
"`MutableSlice` requires that the base collection's `subscript(_: Index)`\nsetter does not invalidate indices. If you are writing a collection and\nmutations need to invalidate indices, don't use `MutableSlice` as its\nsubsequence type. Instead, use the nonmutable `Slice` or define your own\nsubsequence type that takes your index invalidation requirements into\naccount."
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : _MutableIndexable "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"attributes" : [],
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "MutableSlice.Index",
"attributes" : []
}
],
"output" : "MutableSlice.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableSlice"
},
{
"name" : "formIndex(after:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "inout MutableSlice.Index",
"attributes" : [],
"name" : "after"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableSlice"
},
{
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"output" : "MutableSlice.Index",
"input" : [
{
"type" : "MutableSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"name" : "offsetBy",
"type" : "MutableSlice.IndexDistance",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "MutableSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"context" : "MutableSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "MutableSlice.Index?",
"input" : [
{
"type" : "MutableSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"type" : "MutableSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
},
{
"attributes" : [],
"type" : "MutableSlice.Index",
"name" : "limitedBy"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)"
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "MutableSlice.Index"
},
{
"attributes" : [],
"type" : "MutableSlice.Index",
"name" : "to"
}
],
"output" : "MutableSlice.IndexDistance"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "MutableSlice",
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : []
}
],
"name" : "MutableSlice",
"keyword" : "struct"
}
},
{
"documentation" : [
[
"summary",
"A unique identifier for a class instance or metatype.\n"
],
[
"discussion",
"In Swift, only class instances and metatypes have unique identities. There\nis no notion of identity for structs, enums, functions, or tuples.\n"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "ObjectIdentifier",
"methods" : [],
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"documentation" : [
[
"summary",
"A wrapper around an opaque C pointer.\n"
],
[
"discussion",
"Opaque pointers are used to represent C pointers to types that\ncannot be represented in Swift, such as incomplete struct types.\n"
]
],
"declaration" : {
"keyword" : "struct",
"methods" : [],
"name" : "OpaquePointer",
"attributes" : [],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"genericRequirements" : [
"Base : _RandomAccessIndexable "
],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "RandomAccessSlice.Index"
}
],
"output" : "RandomAccessSlice.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RandomAccessSlice"
},
{
"name" : "formIndex(after:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout RandomAccessSlice.Index"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "RandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"signature" : {
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "RandomAccessSlice.Index"
}
],
"output" : "RandomAccessSlice.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(before:)",
"attributes" : []
},
{
"name" : "formIndex(before:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "before",
"type" : "inout RandomAccessSlice.Index",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "RandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"attributes" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "RandomAccessSlice.Index",
"name" : "_"
},
{
"attributes" : [],
"type" : "RandomAccessSlice.IndexDistance",
"name" : "offsetBy"
}
],
"output" : "RandomAccessSlice.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "RandomAccessSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"attributes" : [],
"type" : "RandomAccessSlice.IndexDistance",
"name" : "offsetBy"
},
{
"type" : "RandomAccessSlice.Index",
"attributes" : [],
"name" : "limitedBy"
}
],
"output" : "RandomAccessSlice.Index?"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RandomAccessSlice"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "distance(from:to:)",
"context" : "RandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "from",
"type" : "RandomAccessSlice.Index",
"attributes" : []
},
{
"attributes" : [],
"type" : "RandomAccessSlice.Index",
"name" : "to"
}
],
"output" : "RandomAccessSlice.IndexDistance"
},
"genericParameters" : [],
"genericRequirements" : []
}
],
"name" : "RandomAccessSlice",
"attributes" : []
},
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `RandomAccessSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
]
]
},
{
"declaration" : {
"attributes" : [],
"name" : "Range",
"methods" : [
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "Bound",
"attributes" : [],
"name" : "_"
}
],
"output" : "Bool"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Range",
"keyword" : "func",
"name" : "contains(_:)",
"attributes" : []
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Bound : Comparable "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Bound"
}
],
"inheritence" : []
},
"documentation" : [
[
"summary",
"A half-open interval over a comparable type, from a lower bound up to, but\nnot including, an upper bound.\n"
],
[
"discussion",
"You create `Range` instances by using the half-open range operator (`..<`).\n"
],
[
"discussion",
"``` \n let underFive = 0.0..<5.0\n```\n"
],
[
"discussion",
"You can use a `Range` instance to quickly check if a value is contained in\na particular range of values. For example:\n"
],
[
"discussion",
"``` \n print(underFive.contains(3.14)) // Prints \"true\"\n print(underFive.contains(6.28)) // Prints \"false\"\n print(underFive.contains(5.0)) // Prints \"false\"\n```\n"
],
[
"discussion",
"`Range` instances can represent an empty interval, unlike `ClosedRange`.\n"
],
[
"discussion",
"``` \n let empty = 0.0..<0.0\n print(empty.contains(0.0)) // Prints \"false\"\n print(empty.isEmpty) // Prints \"true\"\n```\n"
],
[
"seealso",
"`CountableRange`, `ClosedRange`, `CountableClosedRange`"
]
]
},
{
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `RangeReplaceableBidirectionalSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
]
],
"declaration" : {
"keyword" : "struct",
"methods" : [
{
"keyword" : "func",
"name" : "index(after:)",
"attributes" : [],
"signature" : {
"output" : "RangeReplaceableBidirectionalSlice.Index",
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "RangeReplaceableBidirectionalSlice.Index"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableBidirectionalSlice",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout RangeReplaceableBidirectionalSlice.Index"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)"
},
{
"signature" : {
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "RangeReplaceableBidirectionalSlice.Index"
}
],
"output" : "RangeReplaceableBidirectionalSlice.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "RangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(before:)",
"keyword" : "func",
"attributes" : []
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "before",
"type" : "inout RangeReplaceableBidirectionalSlice.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableBidirectionalSlice",
"keyword" : "func",
"name" : "formIndex(before:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableBidirectionalSlice",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "RangeReplaceableBidirectionalSlice.Index",
"input" : [
{
"name" : "_",
"type" : "RangeReplaceableBidirectionalSlice.Index",
"attributes" : []
},
{
"type" : "RangeReplaceableBidirectionalSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)"
},
{
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableBidirectionalSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "RangeReplaceableBidirectionalSlice.Index?",
"input" : [
{
"name" : "_",
"type" : "RangeReplaceableBidirectionalSlice.Index",
"attributes" : []
},
{
"type" : "RangeReplaceableBidirectionalSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
},
{
"attributes" : [],
"type" : "RangeReplaceableBidirectionalSlice.Index",
"name" : "limitedBy"
}
]
}
},
{
"attributes" : [],
"keyword" : "func",
"name" : "distance(from:to:)",
"context" : "RangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "RangeReplaceableBidirectionalSlice.IndexDistance",
"input" : [
{
"type" : "RangeReplaceableBidirectionalSlice.Index",
"attributes" : [],
"name" : "from"
},
{
"name" : "to",
"attributes" : [],
"type" : "RangeReplaceableBidirectionalSlice.Index"
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"attributes" : [],
"name" : "replaceSubrange(_:with:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "RangeReplaceableBidirectionalSlice",
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == Base._Element"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "C"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Range<RangeReplaceableBidirectionalSlice.Index>",
"name" : "_"
},
{
"name" : "with",
"attributes" : [],
"type" : "C"
}
]
}
},
{
"keyword" : "func",
"name" : "insert(_:at:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Base._Element",
"name" : "_"
},
{
"type" : "RangeReplaceableBidirectionalSlice.Index",
"attributes" : [],
"name" : "at"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "RangeReplaceableBidirectionalSlice"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "insert(contentsOf:at:)",
"context" : "RangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [
{
"name" : "contentsOf",
"attributes" : [],
"type" : "S"
},
{
"name" : "at",
"type" : "RangeReplaceableBidirectionalSlice.Index",
"attributes" : []
}
]
},
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"genericRequirements" : [
"S : Collection, ",
"S.Iterator.Element == Base._Element"
]
},
{
"name" : "remove(at:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "at",
"attributes" : [],
"type" : "RangeReplaceableBidirectionalSlice.Index"
}
],
"output" : "Base._Element"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "RangeReplaceableBidirectionalSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
]
},
{
"attributes" : [],
"name" : "removeSubrange(_:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "RangeReplaceableBidirectionalSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Range<RangeReplaceableBidirectionalSlice.Index>",
"name" : "_"
}
]
}
}
],
"name" : "RangeReplaceableBidirectionalSlice",
"attributes" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [
"Base : _BidirectionalIndexable, ",
"Base : _RangeReplaceableIndexable "
],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `RangeReplaceableRandomAccessSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
]
],
"declaration" : {
"name" : "RangeReplaceableRandomAccessSlice",
"methods" : [
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableRandomAccessSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "RangeReplaceableRandomAccessSlice.Index",
"attributes" : []
}
],
"output" : "RangeReplaceableRandomAccessSlice.Index"
},
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"signature" : {
"input" : [
{
"name" : "after",
"type" : "inout RangeReplaceableRandomAccessSlice.Index",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "formIndex(after:)",
"attributes" : []
},
{
"attributes" : [],
"name" : "index(before:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableRandomAccessSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"type" : "RangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "before"
}
],
"output" : "RangeReplaceableRandomAccessSlice.Index"
}
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(before:)",
"context" : "RangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "inout RangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "before"
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableRandomAccessSlice",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "RangeReplaceableRandomAccessSlice.Index"
},
{
"name" : "offsetBy",
"type" : "RangeReplaceableRandomAccessSlice.IndexDistance",
"attributes" : []
}
],
"output" : "RangeReplaceableRandomAccessSlice.Index"
},
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)"
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "RangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "_"
},
{
"type" : "RangeReplaceableRandomAccessSlice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
},
{
"attributes" : [],
"type" : "RangeReplaceableRandomAccessSlice.Index",
"name" : "limitedBy"
}
],
"output" : "RangeReplaceableRandomAccessSlice.Index?"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "RangeReplaceableRandomAccessSlice.IndexDistance",
"input" : [
{
"attributes" : [],
"type" : "RangeReplaceableRandomAccessSlice.Index",
"name" : "from"
},
{
"type" : "RangeReplaceableRandomAccessSlice.Index",
"attributes" : [],
"name" : "to"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableRandomAccessSlice"
},
{
"keyword" : "func",
"name" : "replaceSubrange(_:with:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Range<RangeReplaceableRandomAccessSlice.Index>"
},
{
"name" : "with",
"type" : "C",
"attributes" : []
}
]
},
"genericParameters" : [
{
"name" : "C",
"attributes" : []
}
],
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == Base._Element"
],
"context" : "RangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
]
},
{
"name" : "insert(_:at:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "Base._Element",
"attributes" : []
},
{
"name" : "at",
"type" : "RangeReplaceableRandomAccessSlice.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "RangeReplaceableRandomAccessSlice"
},
{
"attributes" : [],
"name" : "insert(contentsOf:at:)",
"keyword" : "func",
"context" : "RangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "S",
"name" : "contentsOf"
},
{
"name" : "at",
"attributes" : [],
"type" : "RangeReplaceableRandomAccessSlice.Index"
}
]
},
"genericRequirements" : [
"S : Collection, ",
"S.Iterator.Element == Base._Element"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
]
},
{
"context" : "RangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"output" : "Base._Element",
"input" : [
{
"attributes" : [],
"type" : "RangeReplaceableRandomAccessSlice.Index",
"name" : "at"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "remove(at:)",
"keyword" : "func"
},
{
"context" : "RangeReplaceableRandomAccessSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Range<RangeReplaceableRandomAccessSlice.Index>"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "removeSubrange(_:)",
"keyword" : "func"
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Base : _RandomAccessIndexable, ",
"Base : _RangeReplaceableIndexable "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : _RangeReplaceableIndexable "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : [],
"attributes" : [],
"name" : "RangeReplaceableSlice",
"methods" : [
{
"keyword" : "func",
"name" : "index(after:)",
"attributes" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "RangeReplaceableSlice.Index",
"name" : "after"
}
],
"output" : "RangeReplaceableSlice.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "inout RangeReplaceableSlice.Index"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableSlice",
"keyword" : "func",
"name" : "formIndex(after:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "RangeReplaceableSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "RangeReplaceableSlice.Index",
"input" : [
{
"name" : "_",
"type" : "RangeReplaceableSlice.Index",
"attributes" : []
},
{
"name" : "offsetBy",
"type" : "RangeReplaceableSlice.IndexDistance",
"attributes" : []
}
]
},
"attributes" : [],
"name" : "index(_:offsetBy:)",
"keyword" : "func"
},
{
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"context" : "RangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "RangeReplaceableSlice.Index",
"attributes" : []
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "RangeReplaceableSlice.IndexDistance"
},
{
"name" : "limitedBy",
"attributes" : [],
"type" : "RangeReplaceableSlice.Index"
}
],
"output" : "RangeReplaceableSlice.Index?"
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func",
"context" : "RangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "RangeReplaceableSlice.IndexDistance",
"input" : [
{
"attributes" : [],
"type" : "RangeReplaceableSlice.Index",
"name" : "from"
},
{
"type" : "RangeReplaceableSlice.Index",
"attributes" : [],
"name" : "to"
}
]
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"context" : "RangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [
{
"type" : "Range<RangeReplaceableSlice.Index>",
"attributes" : [],
"name" : "_"
},
{
"type" : "C",
"attributes" : [],
"name" : "with"
}
]
},
"genericParameters" : [
{
"name" : "C",
"attributes" : []
}
],
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == Base._Element"
],
"attributes" : [],
"keyword" : "func",
"name" : "replaceSubrange(_:with:)"
},
{
"signature" : {
"input" : [
{
"name" : "_",
"type" : "Base._Element",
"attributes" : []
},
{
"attributes" : [],
"type" : "RangeReplaceableSlice.Index",
"name" : "at"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"keyword" : "func",
"name" : "insert(_:at:)",
"attributes" : []
},
{
"name" : "insert(contentsOf:at:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [
"S : Collection, ",
"S.Iterator.Element == Base._Element"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"signature" : {
"input" : [
{
"name" : "contentsOf",
"type" : "S",
"attributes" : []
},
{
"type" : "RangeReplaceableSlice.Index",
"attributes" : [],
"name" : "at"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "RangeReplaceableSlice"
},
{
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "RangeReplaceableSlice",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Base._Element",
"input" : [
{
"type" : "RangeReplaceableSlice.Index",
"attributes" : [],
"name" : "at"
}
]
},
"attributes" : [],
"name" : "remove(at:)",
"keyword" : "func"
},
{
"keyword" : "func",
"name" : "removeSubrange(_:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "Range<RangeReplaceableSlice.Index>",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "RangeReplaceableSlice",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
]
}
],
"keyword" : "struct"
},
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `RangeReplaceableSlice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
]
]
},
{
"declaration" : {
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "Repeated",
"methods" : [],
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"A collection whose elements are all identical.\n"
],
[
"discussion",
"You create an instance of the `Repeated` collection by calling the\n`repeatElement(_:count:)` function. The following example creates a\ncollection containing the name \"Humperdinck\" repeated five times:\n"
],
[
"discussion",
"``` \n let repeatedName = repeatElement(\"Humperdinck\", count: 5)\n for name in repeatedName {\n print(name)\n }\n // \"Humperdinck\"\n // \"Humperdinck\"\n // \"Humperdinck\"\n // \"Humperdinck\"\n // \"Humperdinck\"\n```\n"
]
]
},
{
"declaration" : {
"genericRequirements" : [
"Base : BidirectionalCollection "
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
],
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "index(after:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ReversedCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "after",
"type" : "ReversedCollection.Index",
"attributes" : []
}
],
"output" : "ReversedCollection.Index"
}
},
{
"keyword" : "func",
"name" : "index(before:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "before",
"type" : "ReversedCollection.Index",
"attributes" : []
}
],
"output" : "ReversedCollection.Index"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "ReversedCollection",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"attributes" : [],
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"context" : "ReversedCollection",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "ReversedCollection.Index",
"attributes" : [],
"name" : "_"
},
{
"type" : "ReversedCollection.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "ReversedCollection.Index"
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"signature" : {
"output" : "ReversedCollection.Index?",
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "ReversedCollection.Index"
},
{
"type" : "ReversedCollection.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
},
{
"name" : "limitedBy",
"type" : "ReversedCollection.Index",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "ReversedCollection",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ReversedCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "ReversedCollection.IndexDistance",
"input" : [
{
"name" : "from",
"type" : "ReversedCollection.Index",
"attributes" : []
},
{
"name" : "to",
"attributes" : [],
"type" : "ReversedCollection.Index"
}
]
},
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
}
],
"name" : "ReversedCollection",
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"A collection that presents the elements of its base collection\nin reverse order.\n"
],
[
"note",
"This type is the result of `x.reversed()` where `x` is a\ncollection having bidirectional indices."
],
[
"discussion",
"The `reversed()` method is always lazy when applied to a collection\nwith bidirectional indices, but does not implicitly confer\nlaziness on algorithms applied to its result. In other words, for\nordinary collections `c` having bidirectional indices:\n"
],
[
"discussion",
" - `c.reversed()` does not create new storage\n - `c.reversed().map(f)` maps eagerly and returns a new array\n - `c.lazy.reversed().map(f)` maps lazily and returns a `LazyMapCollection`\n\n<!-- end list -->\n"
],
[
"discussion",
" - See also: `ReversedRandomAccessCollection`\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"name" : "ReversedIndex",
"methods" : [
{
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "ReversedIndex",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Bool",
"input" : [
{
"type" : "ReversedIndex<Base>",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "ReversedIndex<Base>",
"attributes" : [],
"name" : "rhs"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "==(lhs:rhs:)"
},
{
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "ReversedIndex",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "ReversedIndex<Base>"
},
{
"type" : "ReversedIndex<Base>",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "Bool"
},
"attributes" : [],
"keyword" : "func",
"name" : "<(lhs:rhs:)"
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : Collection "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
]
},
"documentation" : [
[
"summary",
"An index that traverses the same positions as an underlying index,\nwith inverted traversal direction.\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"name" : "ReversedRandomAccessCollection",
"methods" : [
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "ReversedRandomAccessCollection.Index",
"input" : [
{
"name" : "after",
"type" : "ReversedRandomAccessCollection.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ReversedRandomAccessCollection",
"keyword" : "func",
"name" : "index(after:)",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ReversedRandomAccessCollection",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "before",
"type" : "ReversedRandomAccessCollection.Index",
"attributes" : []
}
],
"output" : "ReversedRandomAccessCollection.Index"
}
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ReversedRandomAccessCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "ReversedRandomAccessCollection.Index",
"name" : "_"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "ReversedRandomAccessCollection.IndexDistance"
}
],
"output" : "ReversedRandomAccessCollection.Index"
},
"attributes" : [],
"name" : "index(_:offsetBy:)",
"keyword" : "func"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "ReversedRandomAccessCollection",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "ReversedRandomAccessCollection.Index"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "ReversedRandomAccessCollection.IndexDistance"
},
{
"type" : "ReversedRandomAccessCollection.Index",
"attributes" : [],
"name" : "limitedBy"
}
],
"output" : "ReversedRandomAccessCollection.Index?"
},
"attributes" : [],
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func"
},
{
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "ReversedRandomAccessCollection.Index"
},
{
"name" : "to",
"type" : "ReversedRandomAccessCollection.Index",
"attributes" : []
}
],
"output" : "ReversedRandomAccessCollection.IndexDistance"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "ReversedRandomAccessCollection",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : RandomAccessCollection "
],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"inheritence" : []
},
"documentation" : [
[
"summary",
"A collection that presents the elements of its base collection\nin reverse order.\n"
],
[
"note",
"This type is the result of `x.reversed()` where `x` is a\ncollection having random access indices."
]
]
},
{
"documentation" : [
[
"summary",
"An index that traverses the same positions as an underlying index,\nwith inverted traversal direction.\n"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "ReversedRandomAccessIndex<Base>",
"name" : "lhs"
},
{
"type" : "ReversedRandomAccessIndex<Base>",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "Bool"
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "ReversedRandomAccessIndex",
"name" : "==(lhs:rhs:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "<(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "ReversedRandomAccessIndex",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "ReversedRandomAccessIndex<Base>",
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "ReversedRandomAccessIndex<Base>"
}
],
"output" : "Bool"
}
}
],
"name" : "ReversedRandomAccessIndex",
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Base",
"attributes" : []
}
],
"genericRequirements" : [
"Base : RandomAccessCollection "
]
}
},
{
"documentation" : [
[
"summary",
"An unordered collection of unique elements.\n"
],
[
"discussion",
"You use a set instead of an array when you need to test efficiently for\nmembership and you aren't concerned with the order of the elements in the\ncollection, or when you need to ensure that each element appears only once\nin a collection.\n"
],
[
"discussion",
"You can create a set with any element type that conforms to the `Hashable`\nprotocol. By default, most types in the standard library are hashable,\nincluding strings, numeric and Boolean types, enumeration cases without\nassociated values, and even sets themselves.\n"
],
[
"discussion",
"Swift makes it as easy to create a new set as to create a new array. Simply\nassign an array literal to a variable or constant with the `Set` type\nspecified.\n"
],
[
"discussion",
"``` \n let ingredients: Set = [\"cocoa beans\", \"sugar\", \"cocoa butter\", \"salt\"]\n if ingredients.contains(\"sugar\") {\n print(\"No thanks, too sweet.\")\n }\n // Prints \"No thanks, too sweet.\"\n```\n"
],
[
"discussion",
"# Set Operations\n"
],
[
"discussion",
"Sets provide a suite of mathematical set operations. For example, you can\nefficiently test a set for membership of an element or check its\nintersection with another set:\n"
],
[
"discussion",
" - Use the `contains(_:)` method to test whether a set contains a specific\n element.\n - Use the \"equal to\" operator (`==`) to test whether two sets contain the\n same elements.\n - Use the `isSubset(of:)` method to test whether a set contains all the\n elements of another set or sequence.\n - Use the `isSuperset(of:)` method to test whether all elements of a set\n are contained in another set or sequence.\n - Use the `isStrictSubset(of:)` and `isStrictSuperset(of:)` methods to test\n whether a set is a subset or superset of, but not equal to, another set.\n - Use the `isDisjoint(with:)` method to test whether a set has any elements\n in common with another set.\n"
],
[
"discussion",
"You can also combine, exclude, or subtract the elements of two sets:\n"
],
[
"discussion",
" - Use the `union(_:)` method to create a new set with the elements of a set\n and another set or sequence.\n - Use the `intersection(_:)` method to create a new set with only the\n elements common to a set and another set or sequence.\n - Use the `symmetricDifference(_:)` method to create a new set with the\n elements that are in either a set or another set or sequence, but not in\n both.\n - Use the `subtracting(_:)` method to create a new set with the elements of\n a set that are not also in another set or sequence.\n"
],
[
"discussion",
"You can modify a set in place by using these methods' mutating\ncounterparts: `formUnion(_:)`, `formIntersection(_:)`,\n`formSymmetricDifference(_:)`, and `subtract(_:)`.\n"
],
[
"discussion",
"Set operations are not limited to use with other sets. Instead, you can\nperform set operations with another set, an array, or any other sequence\ntype.\n"
],
[
"discussion",
"``` \n var primes: Set = [2, 3, 5, 7]\n\n // Tests whether primes is a subset of a Range<Int>\n print(primes.isSubset(of: 0..<10))\n // Prints \"true\"\n\n // Performs an intersection with an Array<Int>\n let favoriteNumbers = [5, 7, 15, 21]\n print(primes.intersection(favoriteNumbers))\n // Prints \"[5, 7]\"\n```\n"
],
[
"discussion",
"# Sequence and Collection Operations\n"
],
[
"discussion",
"In addition to the `Set` type's set operations, you can use any nonmutating\nsequence or collection methods with a set.\n"
],
[
"discussion",
"``` \n if primes.isEmpty {\n print(\"No primes!\")\n } else {\n print(\"We have \\(primes.count) primes.\")\n }\n // Prints \"We have 4 primes.\"\n\n let primesSum = primes.reduce(0, +)\n // 'primesSum' == 17\n\n let primeStrings = primes.sorted().map(String.init)\n // 'primeStrings' == [\"2\", \"3\", \"5\", \"7\"]\n```\n"
],
[
"discussion",
"You can iterate through a set's unordered elements with a `for`-`in` loop.\n"
],
[
"discussion",
"``` \n for number in primes {\n print(number)\n }\n // Prints \"5\"\n // Prints \"7\"\n // Prints \"2\"\n // Prints \"3\"\n```\n"
],
[
"discussion",
"Many sequence and collection operations return an array or a type-erasing\ncollection wrapper instead of a set. To restore efficient set operations,\ncreate a new set from the result.\n"
],
[
"discussion",
"``` \n let morePrimes = primes.union([11, 13, 17, 19])\n\n let laterPrimes = morePrimes.filter { $0 > 10 }\n // 'laterPrimes' is of type Array<Int>\n\n let laterPrimesSet = Set(morePrimes.filter { $0 > 10 })\n // 'laterPrimesSet' is of type Set<Int>\n```\n"
],
[
"discussion",
"# Bridging Between Set and NSSet\n"
],
[
"discussion",
"You can bridge between `Set` and `NSSet` using the `as` operator. For\nbridging to be possible, the `Element` type of a set must be a class, an\n`@objc` protocol (a protocol imported from Objective-C or marked with the\n`@objc` attribute), or a type that bridges to a Foundation type.\n"
],
[
"discussion",
"Bridging from `Set` to `NSSet` always takes O(1) time and space. When the\nset's `Element` type is neither a class nor an `@objc` protocol, any\nrequired bridging of elements occurs at the first access of each element,\nso the first operation that uses the contents of the set (for example, a\nmembership test) can take O(*n*).\n"
],
[
"discussion",
"Bridging from `NSSet` to `Set` first calls the `copy(with:)` method\n(`- copyWithZone:` in Objective-C) on the set to get an immutable copy and\nthen performs additional Swift bookkeeping work that takes O(1) time. For\ninstances of `NSSet` that are already immutable, `copy(with:)` returns the\nsame set in constant time; otherwise, the copying performance is\nunspecified. The instances of `NSSet` and `Set` share buffer using the\nsame copy-on-write optimization that is used when two instances of `Set`\nshare buffer.\n"
],
[
"seealso",
"`Hashable`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"genericRequirements" : [
"Element : Hashable "
],
"attributes" : [],
"keyword" : "struct",
"name" : "Set",
"methods" : [
{
"name" : "index(after:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Set<Element>.Index",
"input" : [
{
"name" : "after",
"type" : "Set<Element>.Index",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Set"
},
{
"signature" : {
"output" : "Bool",
"input" : [
{
"attributes" : [],
"type" : "Element",
"name" : "_"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "Set",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "contains(_:)",
"keyword" : "func",
"attributes" : []
},
{
"signature" : {
"output" : "Set<Element>.Index?",
"input" : [
{
"name" : "of",
"attributes" : [],
"type" : "Set.Element"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "Set",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(of:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"name" : "insert(_:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "Set",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "(inserted: Bool, memberAfterInsert: Element)",
"input" : [
{
"name" : "_",
"type" : "Element",
"attributes" : []
}
]
}
},
{
"signature" : {
"output" : "Element?",
"input" : [
{
"attributes" : [],
"type" : "Element",
"name" : "with"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "Set",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"keyword" : "func",
"name" : "update(with:)",
"attributes" : []
},
{
"keyword" : "func",
"name" : "remove(_:)",
"attributes" : [],
"signature" : {
"output" : "Element?",
"input" : [
{
"attributes" : [],
"type" : "Element",
"name" : "_"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "Set",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
]
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Element",
"input" : [
{
"type" : "Set<Element>.Index",
"attributes" : [],
"name" : "at"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "Set",
"keyword" : "func",
"name" : "remove(at:)",
"attributes" : []
},
{
"signature" : {
"output" : "Set.Element",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "Set",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"keyword" : "func",
"name" : "removeFirst()",
"attributes" : []
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "SetIterator<Element>"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Set",
"keyword" : "func",
"name" : "makeIterator()",
"attributes" : []
},
{
"keyword" : "func",
"name" : "isSubset(of:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "of",
"type" : "S",
"attributes" : []
}
],
"output" : "Bool "
},
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"context" : "Set",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"attributes" : [],
"name" : "isStrictSubset(of:)",
"keyword" : "func",
"context" : "Set",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "of",
"type" : "S",
"attributes" : []
}
],
"output" : "Bool "
},
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
]
},
{
"context" : "Set",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "S",
"attributes" : [],
"name" : "of"
}
],
"output" : "Bool "
},
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"attributes" : [],
"name" : "isSuperset(of:)",
"keyword" : "func"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "isStrictSuperset(of:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Set",
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"signature" : {
"input" : [
{
"type" : "S",
"attributes" : [],
"name" : "of"
}
],
"output" : "Bool "
}
},
{
"attributes" : [],
"name" : "isDisjoint(with:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Set",
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"signature" : {
"output" : "Bool ",
"input" : [
{
"name" : "with",
"attributes" : [],
"type" : "S"
}
]
}
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Set",
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "S",
"attributes" : []
}
],
"output" : "Set<Set.Element> "
},
"attributes" : [],
"keyword" : "func",
"name" : "union(_:)"
},
{
"context" : "Set",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "S",
"attributes" : []
}
]
},
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"attributes" : [],
"keyword" : "func",
"name" : "formUnion(_:)"
},
{
"attributes" : [],
"name" : "subtracting(_:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Set",
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"signature" : {
"output" : "Set<Set.Element> ",
"input" : [
{
"type" : "S",
"attributes" : [],
"name" : "_"
}
]
}
},
{
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "S"
}
]
},
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"context" : "Set",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"name" : "subtract(_:)",
"keyword" : "func",
"attributes" : []
},
{
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "S"
}
],
"output" : "Set<Set.Element> "
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Set",
"keyword" : "func",
"name" : "intersection(_:)",
"attributes" : []
},
{
"name" : "formIntersection(_:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "S"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "Set"
},
{
"attributes" : [],
"name" : "symmetricDifference(_:)",
"keyword" : "func",
"context" : "Set",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "S",
"attributes" : [],
"name" : "_"
}
],
"output" : "Set<Set.Element> "
},
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "S"
}
]
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formSymmetricDifference(_:)",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "Set",
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"genericRequirements" : [
"S : Sequence, ",
"S.Iterator.Element == Element"
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "S",
"name" : "_"
}
]
}
}
]
}
},
{
"declaration" : {
"name" : "Index",
"methods" : [],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Used to access the members in an instance of `Set<Element>`.\n"
]
]
},
{
"documentation" : [
[
"summary",
"An iterator over the members of a `Set<Element>`.\n"
]
],
"declaration" : {
"attributes" : [],
"name" : "SetIterator",
"methods" : [
{
"context" : "SetIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"output" : "Element?",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "next()",
"keyword" : "func"
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Element : Hashable "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
]
}
},
{
"declaration" : {
"attributes" : [],
"methods" : [
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Slice.Index",
"input" : [
{
"type" : "Slice.Index",
"attributes" : [],
"name" : "after"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Slice",
"keyword" : "func",
"name" : "index(after:)",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)",
"context" : "Slice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Slice.Index",
"name" : "after"
}
]
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"signature" : {
"input" : [
{
"name" : "_",
"type" : "Slice.Index",
"attributes" : []
},
{
"name" : "offsetBy",
"type" : "Slice.IndexDistance",
"attributes" : []
}
],
"output" : "Slice.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "Slice",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"context" : "Slice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "Slice.Index",
"attributes" : [],
"name" : "_"
},
{
"type" : "Slice.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
},
{
"attributes" : [],
"type" : "Slice.Index",
"name" : "limitedBy"
}
],
"output" : "Slice.Index?"
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"context" : "Slice",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Slice.IndexDistance",
"input" : [
{
"type" : "Slice.Index",
"attributes" : [],
"name" : "from"
},
{
"type" : "Slice.Index",
"attributes" : [],
"name" : "to"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
}
],
"name" : "Slice",
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Base : _Indexable "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Base"
}
]
},
"documentation" : [
[
"summary",
"A view into a subsequence of elements of another collection.\n"
],
[
"discussion",
"A slice stores a base collection and the start and end indices of the view.\nIt does not copy the elements from the collection into separate storage.\nThus, creating a slice has O(1) complexity.\n"
],
[
"discussion",
"## Slices Share Indices\n"
],
[
"discussion",
"Indices of a slice can be used interchangeably with indices of the base\ncollection. An element of a slice is located under the same index in the\nslice and in the base collection, as long as neither the collection nor\nthe slice has been mutated since the slice was created.\n"
],
[
"discussion",
"For example, suppose you have an array holding the number of absences from\neach class during a session.\n"
],
[
"discussion",
"``` \n var absences = [0, 2, 0, 4, 0, 3, 1, 0]\n```\n"
],
[
"discussion",
"You're tasked with finding the day with the most absences in the second\nhalf of the session. To find the index of the day in question, follow\nthese setps:\n"
],
[
"discussion",
"1) Create a slice of the `absences` array that holds the second half of the\n days.\n2) Use the `max(by:)` method to determine the index of the day\n with the most absences.\n3) Print the result using the index found in step 2 on the original\n `absences` array.\n"
],
[
"discussion",
"Here's an implementation of those steps:\n"
],
[
"discussion",
"``` \n let secondHalf = absences.suffix(absences.count / 2)\n if let i = secondHalf.indices.max(by: { secondHalf[$0] < secondHalf[$1] }) {\n print(\"Highest second-half absences: \\(absences[i])\")\n }\n // Prints \"Highest second-half absences: 3\"\n```\n"
],
[
"discussion",
"## Slices Inherit Semantics\n"
],
[
"discussion",
"A slice inherits the value or reference semantics of its base collection.\nThat is, if a `Slice` instance is wrapped around a mutable\ncollection that has value semantics, such as an array, mutating the\noriginal collection would trigger a copy of that collection, and not\naffect the base collection stored inside of the slice.\n"
],
[
"discussion",
"For example, if you update the last element of the `absences` array from\n`0` to `2`, the `secondHalf` slice is unchanged.\n"
],
[
"discussion",
"``` \n absences[7] = 2\n print(absences)\n // Prints \"[0, 2, 0, 4, 0, 3, 1, 2]\"\n print(secondHalf)\n // Prints \"[0, 3, 1, 0]\"\n```\n"
],
[
"important",
"Use slices only for transient computation.\nA slice may hold a reference to the entire storage of a larger\ncollection, not just to the portion it presents, even after the base\ncollection's lifetime ends. Long-term storage of a slice may therefore\nprolong the lifetime of elements that are no longer otherwise\naccessible, which can erroneously appear to be memory leakage."
]
]
},
{
"documentation" : [
[
"summary",
"A string type designed to represent text that is known at compile time.\n"
],
[
"discussion",
"Instances of the `StaticString` type are immutable. `StaticString` provides\nlimited, pointer-based access to its contents, unlike Swift's more\ncommonly used `String` type. A static string can store its value as a\npointer to an ASCII code unit sequence, as a pointer to a UTF-8 code unit\nsequence, or as a single Unicode scalar value.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"name" : "StaticString",
"methods" : [
{
"attributes" : [],
"name" : "withUTF8Buffer(_:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "StaticString",
"genericRequirements" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "R"
}
],
"signature" : {
"output" : "R",
"input" : [
{
"type" : "(UnsafeBufferPointer<UInt8>) -> R",
"attributes" : [],
"name" : "_"
}
]
}
}
]
}
},
{
"documentation" : [
[
"summary",
"A `Sequence` of values formed by striding over a closed interval.\n"
]
],
"declaration" : {
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"genericRequirements" : [
"Element : Strideable "
],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "StrideThrough",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "makeIterator()",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "StrideThrough",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "StrideThroughIterator<Element>"
}
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"An iterator for `StrideThrough<Element>`.\n"
]
],
"declaration" : {
"attributes" : [],
"name" : "StrideThroughIterator",
"methods" : [
{
"context" : "StrideThroughIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"output" : "Element?",
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "next()",
"keyword" : "func"
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Element : Strideable "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
]
}
},
{
"declaration" : {
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : [
"Element : Strideable "
],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "StrideTo",
"methods" : [
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "StrideTo",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [],
"output" : "StrideToIterator<Element>"
},
"attributes" : [],
"name" : "makeIterator()",
"keyword" : "func"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"A `Sequence` of values formed by striding over a half-open interval.\n"
]
]
},
{
"documentation" : [
[
"summary",
"An iterator for `StrideTo<Element>`.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"genericRequirements" : [
"Element : Strideable "
],
"attributes" : [],
"keyword" : "struct",
"name" : "StrideToIterator",
"methods" : [
{
"context" : "StrideToIterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [],
"output" : "Element?"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "next()"
}
]
}
},
{
"documentation" : [
[
"summary",
"A Unicode string value.\n"
],
[
"discussion",
"A string is a series of characters, such as `\"Swift\"`. Strings in Swift are\nUnicode correct, locale insensitive, and designed to be efficient. The\n`String` type bridges with the Objective-C class `NSString` and offers\ninteroperability with C functions that works with strings.\n"
],
[
"discussion",
"You can create new strings using string literals or string interpolations.\nA string literal is a series of characters enclosed in quotes.\n"
],
[
"discussion",
"``` \n let greeting = \"Welcome!\"\n```\n"
],
[
"discussion",
"String interpolations are string literals that evaluate any included\nexpressions and convert the results to string form. String interpolations\nare an easy way to build a string from multiple pieces. Wrap each\nexpression in a string interpolation in parentheses, prefixed by a\nbackslash.\n"
],
[
"discussion",
"``` \n let name = \"Rosa\"\n let personalizedGreeting = \"Welcome, \\(name)!\"\n\n let price = 2\n let number = 3\n let cookiePrice = \"\\(number) cookies: $\\(price * number).\"\n```\n"
],
[
"discussion",
"Combine strings using the concatenation operator (`+`).\n"
],
[
"discussion",
"``` \n let longerGreeting = greeting + \" We're glad you're here!\"\n print(longerGreeting)\n // Prints \"Welcome! We're glad you're here!\"\n```\n"
],
[
"discussion",
"# Modifying and Comparing Strings\n"
],
[
"discussion",
"Strings always have value semantics. Modifying a copy of a string leaves\nthe original unaffected.\n"
],
[
"discussion",
"``` \n var otherGreeting = greeting\n otherGreeting += \" Have a nice time!\"\n print(otherGreeting)\n // Prints \"Welcome! Have a nice time!\"\n\n print(greeting)\n // Prints \"Welcome!\"\n```\n"
],
[
"discussion",
"Comparing strings for equality using the equal-to operator (`==`) or a\nrelational operator (like `<` and `>=`) is always performed using the\nUnicode canonical representation. This means that different\nrepresentations of a string compare as being equal.\n"
],
[
"discussion",
"``` \n let cafe1 = \"Cafe\\u{301}\"\n let cafe2 = \"Café\"\n print(cafe1 == cafe2)\n // Prints \"true\"\n```\n"
],
[
"discussion",
"The Unicode code point `\"\\u{301}\"` modifies the preceding character to\ninclude an accent, so `\"e\\u{301}\"` has the same canonical representation\nas the single Unicode code point `\"é\"`.\n"
],
[
"discussion",
"Basic string operations are not sensitive to locale settings. This ensures\nthat string comparisons and other operations always have a single, stable\nresult, allowing strings to be used as keys in `Dictionary` instances and\nfor other purposes.\n"
],
[
"discussion",
"# Representing Strings: Views\n"
],
[
"discussion",
"A string is not itself a collection. Instead, it has properties that\npresent its contents as meaningful collections. Each of these collections\nis a particular type of *view* of the string's visible and data\nrepresentation.\n"
],
[
"discussion",
"To demonstrate the different views available for every string, the\nfollowing examples use this `String` instance:\n"
],
[
"discussion",
"``` \n let cafe = \"Cafe\\u{301} du 🌍\"\n print(cafe)\n // Prints \"Café du 🌍\"\n```\n"
],
[
"discussion",
"## Character View\n"
],
[
"discussion",
"A string's `characters` property is a collection of *extended grapheme\nclusters*, which approximate human-readable characters. Many individual\ncharacters, such as \"é\", \"김\", and \"🇮🇳\", can be made up of multiple Unicode\ncode points. These code points are combined by Unicode's boundary\nalgorithms into extended grapheme clusters, represented by Swift's\n`Character` type. Each element of the `characters` view is represented by\na `Character` instance.\n"
],
[
"discussion",
"``` \n print(cafe.characters.count)\n // Prints \"9\"\n print(Array(cafe.characters))\n // Prints \"[\"C\", \"a\", \"f\", \"é\", \" \", \"d\", \"u\", \" \", \"🌍\"]\"\n```\n"
],
[
"discussion",
"Each visible character in the `cafe` string is a separate element of the\n`characters` view.\n"
],
[
"discussion",
"## Unicode Scalar View\n"
],
[
"discussion",
"A string's `unicodeScalars` property is a collection of Unicode scalar\nvalues, the 21-bit codes that are the basic unit of Unicode. Each scalar\nvalue is represented by a `UnicodeScalar` instance and is equivalent to a\nUTF-32 code unit.\n"
],
[
"discussion",
"``` \n print(cafe.unicodeScalars.count)\n // Prints \"10\"\n print(Array(cafe.unicodeScalars))\n // Prints \"[\"C\", \"a\", \"f\", \"e\", \"\\u{0301}\", \" \", \"d\", \"u\", \" \", \"\\u{0001F30D}\"]\"\n print(cafe.unicodeScalars.map { $0.value })\n // Prints \"[67, 97, 102, 101, 769, 32, 100, 117, 32, 127757]\"\n```\n"
],
[
"discussion",
"The `unicodeScalars` view's elements comprise each Unicode scalar value in\nthe `cafe` string. In particular, because `cafe` was declared using the\ndecomposed form of the `\"é\"` character, `unicodeScalars` contains the code\npoints for both the letter `\"e\"` (101) and the accent character `\"´\"`\n(769).\n"
],
[
"discussion",
"## UTF-16 View\n"
],
[
"discussion",
"A string's `utf16` property is a collection of UTF-16 code units, the\n16-bit encoding form of the string's Unicode scalar values. Each code unit\nis stored as a `UInt16` instance.\n"
],
[
"discussion",
"``` \n print(cafe.utf16.count)\n // Prints \"11\"\n print(Array(cafe.utf16))\n // Prints \"[67, 97, 102, 101, 769, 32, 100, 117, 32, 55356, 57101]\"\n```\n"
],
[
"discussion",
"The elements of the `utf16` view are the code units for the string when\nencoded in UTF-16.\n"
],
[
"discussion",
"The elements of this collection match those accessed through indexed\n`NSString` APIs.\n"
],
[
"discussion",
"``` \n let nscafe = cafe as NSString\n print(nscafe.length)\n // Prints \"11\"\n print(nscafe.character(at: 3))\n // Prints \"101\"\n```\n"
],
[
"discussion",
"## UTF-8 View\n"
],
[
"discussion",
"A string's `utf8` property is a collection of UTF-8 code units, the 8-bit\nencoding form of the string's Unicode scalar values. Each code unit is\nstored as a `UInt8` instance.\n"
],
[
"discussion",
"``` \n print(cafe.utf8.count)\n // Prints \"14\"\n print(Array(cafe.utf8))\n // Prints \"[67, 97, 102, 101, 204, 129, 32, 100, 117, 32, 240, 159, 140, 141]\"\n```\n"
],
[
"discussion",
"The elements of the `utf8` view are the code units for the string when\nencoded in UTF-8. This representation matches the one used when `String`\ninstances are passed to C APIs.\n"
],
[
"discussion",
"``` \n let cLength = strlen(cafe)\n print(cLength)\n // Prints \"14\"\n```\n"
],
[
"discussion",
"# Counting the Length of a String\n"
],
[
"discussion",
"When you need to know the length of a string, you must first consider what\nyou'll use the length for. Are you measuring the number of characters that\nwill be displayed on the screen, or are you measuring the amount of\nstorage needed for the string in a particular encoding? A single string\ncan have greatly differing lengths when measured by its different views.\n"
],
[
"discussion",
"For example, an ASCII character like the capital letter *A* is represented\nby a single element in each of its four views. The Unicode scalar value of\n*A* is `65`, which is small enough to fit in a single code unit in both\nUTF-16 and UTF-8.\n"
],
[
"discussion",
"``` \n let capitalA = \"A\"\n print(capitalA.characters.count)\n // Prints \"1\"\n print(capitalA.unicodeScalars.count)\n // Prints \"1\"\n print(capitalA.utf16.count)\n // Prints \"1\"\n print(capitalA.utf8.count)\n // Prints \"1\"\n```\n"
],
[
"discussion",
"On the other hand, an emoji flag character is constructed from a pair of\nUnicode scalars values, like `\"\\u{1F1F5}\"` and `\"\\u{1F1F7}\"`. Each of\nthese scalar values, in turn, is too large to fit into a single UTF-16 or\nUTF-8 code unit. As a result, each view of the string `\"🇵🇷\"` reports a\ndifferent length.\n"
],
[
"discussion",
"``` \n let flag = \"🇵🇷\"\n print(flag.characters.count)\n // Prints \"1\"\n print(flag.unicodeScalars.count)\n // Prints \"2\"\n print(flag.utf16.count)\n // Prints \"4\"\n print(flag.utf8.count)\n // Prints \"8\"\n```\n"
],
[
"discussion",
"To check whether a string is empty, use its `isEmpty` property instead\nof comparing the length of one of the views to `0`. Unlike `isEmpty`,\ncalculating a view's `count` property requires iterating through the\nelements of the string.\n"
],
[
"discussion",
"# Accessing String View Elements\n"
],
[
"discussion",
"To find individual elements of a string, use the appropriate view for your\ntask. For example, to retrieve the first word of a longer string, you can\nsearch the `characters` view for a space and then create a new string from\na prefix of the `characters` view up to that point.\n"
],
[
"discussion",
"``` \n let name = \"Marie Curie\"\n let firstSpace = name.characters.index(of: \" \")!\n let firstName = String(name.characters.prefix(upTo: firstSpace))\n print(firstName)\n // Prints \"Marie\"\n```\n"
],
[
"discussion",
"You can convert an index into one of a string's views to an index into\nanother view.\n"
],
[
"discussion",
"``` \n let firstSpaceUTF8 = firstSpace.samePosition(in: name.utf8)\n print(Array(name.utf8.prefix(upTo: firstSpaceUTF8)))\n // Prints \"[77, 97, 114, 105, 101]\"\n```\n"
],
[
"discussion",
"# Performance Optimizations\n"
],
[
"discussion",
"Although strings in Swift have value semantics, strings use a copy-on-write\nstrategy to store their data in a buffer. This buffer can then be shared\nby different copies of a string. A string's data is only copied lazily,\nupon mutation, when more than one string instance is using the same\nbuffer. Therefore, the first in any sequence of mutating operations may\ncost O(*n*) time and space.\n"
],
[
"discussion",
"When a string's contiguous storage fills up, a new buffer must be allocated\nand data must be moved to the new storage. String buffers use an\nexponential growth strategy that makes appending to a string a constant\ntime operation when averaged over many append operations.\n"
],
[
"discussion",
"# Bridging between String and NSString\n"
],
[
"discussion",
"Any `String` instance can be bridged to `NSString` using the type-cast\noperator (`as`), and any `String` instance that originates in Objective-C\nmay use an `NSString` instance as its storage. Because any arbitrary\nsubclass of `NSString` can become a `String` instance, there are no\nguarantees about representation or efficiency when a `String` instance is\nbacked by `NSString` storage. Because `NSString` is immutable, it is just\nas though the storage was shared by a copy: The first in any sequence of\nmutating operations causes elements to be copied into unique, contiguous\nstorage which may cost O(*n*) time and space, where *n* is the length of\nthe string's encoded representation (or more, if the underlying `NSString`\nhas unusual performance characteristics).\n"
],
[
"discussion",
"For more information about the Unicode terms used in this discussion, see\nthe [Unicode.org glossary](http://www.unicode.org/glossary/). In particular, this discussion\nmentions [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster),\n[Unicode scalar values](http://www.unicode.org/glossary/#unicode_scalar_value), and [canonical equivalence](http://www.unicode.org/glossary/#canonical_equivalent).\n"
],
[
"seealso",
"`String.CharacterView`, `String.UnicodeScalarView`,\n`String.UTF16View`, `String.UTF8View`"
]
],
"declaration" : {
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"methods" : [],
"name" : "String",
"attributes" : []
}
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "UTF16View",
"methods" : [
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UTF16View",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "String.UTF16View.Index",
"name" : "after"
}
],
"output" : "String.UTF16View.Index"
},
"attributes" : [],
"name" : "index(after:)",
"keyword" : "func"
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "String.UTF16View.Index",
"name" : "before"
}
],
"output" : "String.UTF16View.Index"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UTF16View",
"name" : "index(before:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UTF16View",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "String.UTF16View.Index",
"attributes" : []
},
{
"type" : "String.UTF16View.IndexDistance",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "String.UTF16View.Index"
}
},
{
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "String.UTF16View.Index",
"name" : "_"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "String.UTF16View.IndexDistance"
},
{
"name" : "limitedBy",
"type" : "String.UTF16View.Index",
"attributes" : []
}
],
"output" : "String.UTF16View.Index?"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UTF16View",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"context" : "UTF16View",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "String.UTF16View.Index",
"attributes" : [],
"name" : "from"
},
{
"name" : "to",
"type" : "String.UTF16View.Index",
"attributes" : []
}
],
"output" : "String.UTF16View.IndexDistance"
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "distance(from:to:)",
"keyword" : "func"
}
],
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : []
},
"documentation" : [
[
"summary",
"A view of a string's contents as a collection of UTF-16 code units.\n"
],
[
"discussion",
"You can access a string's view of UTF-16 code units by using its `utf16`\nproperty. A string's UTF-16 view encodes the string's Unicode scalar\nvalues as 16-bit integers.\n"
],
[
"discussion",
"``` \n let flowers = \"Flowers 💐\"\n for v in flowers.utf16 {\n print(v)\n }\n // 70\n // 108\n // 111\n // 119\n // 101\n // 114\n // 115\n // 32\n // 55357\n // 56464\n```\n"
],
[
"discussion",
"Unicode scalar values that make up a string's contents can be up to 21\nbits long. The longer scalar values may need two `UInt16` values for\nstorage. Those \"pairs\" of code units are called *surrogate pairs*.\n"
],
[
"discussion",
"``` \n let flowermoji = \"💐\"\n for v in flowermoji.unicodeScalars {\n print(v, v.value)\n }\n // 💐 128144\n\n for v in flowermoji.utf16 {\n print(v)\n }\n // 55357\n // 56464\n```\n"
],
[
"discussion",
"To convert a `String.UTF16View` instance back into a string, use the\n`String` type's `init(_:)` initializer.\n"
],
[
"discussion",
"``` \n let favemoji = \"My favorite emoji is 🎉\"\n if let i = favemoji.utf16.index(where: { $0 >= 128 }) {\n let asciiPrefix = String(favemoji.utf16.prefix(upTo: i))\n print(asciiPrefix)\n }\n // Prints \"My favorite emoji is \"\n```\n"
],
[
"discussion",
"# UTF16View Elements Match NSString Characters\n"
],
[
"discussion",
"The UTF-16 code units of a string's `utf16` view match the elements\naccessed through indexed `NSString` APIs.\n"
],
[
"discussion",
"``` \n print(flowers.utf16.count)\n // Prints \"10\"\n\n let nsflowers = flowers as NSString\n print(nsflowers.length)\n // Prints \"10\"\n```\n"
],
[
"discussion",
"Unlike `NSString`, however, `String.UTF16View` does not use integer\nindices. If you need to access a specific position in a UTF-16 view, use\nSwift's index manipulation methods. The following example accesses the\nfourth code unit in both the `flowers` and `nsflowers` strings:\n"
],
[
"discussion",
"``` \n print(nsflowers.character(at: 3))\n // Prints \"119\"\n\n let i = flowers.utf16.index(flowers.utf16.startIndex, offsetBy: 3)\n print(flowers.utf16[i])\n // Prints \"119\"\n```\n"
],
[
"discussion",
"Although the Swift overlay updates many Objective-C methods to return\nnative Swift indices and index ranges, some still return instances of\n`NSRange`. To convert an `NSRange` instance to a range of\n`String.UTF16View.Index`, follow these steps:\n"
],
[
"discussion",
"1. Use the `NSRange` type's `toRange` method to convert the instance to\n an optional range of `Int` values.\n2. Use your string's `utf16` view's index manipulation methods to convert\n the integer bounds to `String.UTF16View.Index` values.\n3. Create a new `Range` instance from the new index values.\n"
],
[
"discussion",
"Here's an implementation of those steps, showing how to retrieve a\nsubstring described by an `NSRange` instance from the middle of a\nstring.\n"
],
[
"discussion",
"``` \n let snowy = \"❄️ Let it snow! ☃️\"\n let nsrange = NSRange(location: 3, length: 12)\n if let r = nsrange.toRange() {\n let start = snowy.utf16.index(snowy.utf16.startIndex, offsetBy: r.lowerBound)\n let end = snowy.utf16.index(snowy.utf16.startIndex, offsetBy: r.upperBound)\n let substringRange = start..<end\n print(snowy.utf16[substringRange])\n }\n // Prints \"Let it snow!\"\n```\n"
]
]
},
{
"documentation" : [
[
"summary",
"A position in a string's collection of UTF-16 code units.\n"
],
[
"discussion",
"You can convert between indices of the different string views by using\nconversion initializers and the `samePosition(in:)` method overloads.\nFor example, the following code sample finds the index of the first\nspace in the string's character view and then converts that to the same\nposition in the UTF-16 view.\n"
],
[
"discussion",
"``` \n let hearts = \"Hearts <3 ♥︎ 💘\"\n if let i = hearts.characters.index(of: \" \") {\n let j = i.samePosition(in: hearts.utf16)\n print(Array(hearts.utf16.suffix(from: j)))\n print(hearts.utf16.suffix(from: j))\n }\n // Prints \"[32, 60, 51, 32, 9829, 65038, 32, 55357, 56472]\"\n // Prints \" <3 ♥︎ 💘\"\n```\n"
]
],
"declaration" : {
"keyword" : "struct",
"name" : "Index",
"methods" : [],
"attributes" : [],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"context" : "UTF16View",
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"A type that represents the indices that are valid for subscripting the\ncollection, in ascending order.\n"
]
],
"declaration" : {
"context" : "UTF16View",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : [],
"attributes" : [],
"methods" : [],
"name" : "Indices",
"keyword" : "struct"
}
},
{
"documentation" : [
[
"summary",
"A view of a string's contents as a collection of UTF-8 code units.\n"
],
[
"discussion",
"You can access a string's view of UTF-8 code units by using its `utf8`\nproperty. A string's UTF-8 view encodes the string's Unicode scalar\nvalues as 8-bit integers.\n"
],
[
"discussion",
"``` \n let flowers = \"Flowers 💐\"\n for v in flowers.utf8 {\n print(v)\n }\n // 70\n // 108\n // 111\n // 119\n // 101\n // 114\n // 115\n // 32\n // 240\n // 159\n // 146\n // 144\n```\n"
],
[
"discussion",
"A string's Unicode scalar values can be up to 21 bits in length. To\nrepresent those scalar values using 8-bit integers, more than one UTF-8\ncode unit is often required.\n"
],
[
"discussion",
"``` \n let flowermoji = \"💐\"\n for v in flowermoji.unicodeScalars {\n print(v, v.value)\n }\n // 💐 128144\n\n for v in flowermoji.utf8 {\n print(v)\n }\n // 240\n // 159\n // 146\n // 144\n```\n"
],
[
"discussion",
"In the encoded representation of a Unicode scalar value, each UTF-8 code\nunit after the first is called a *continuation byte*.\n"
],
[
"discussion",
"# UTF8View Elements Match Encoded C Strings\n"
],
[
"discussion",
"Swift streamlines interoperation with C string APIs by letting you pass a\n`String` instance to a function as an `Int8` or `UInt8` pointer. When you\ncall a C function using a `String`, Swift automatically creates a buffer\nof UTF-8 code units and passes a pointer to that buffer. The code units\nof that buffer match the code units in the string's `utf8` view.\n"
],
[
"discussion",
"The following example uses the C `strncmp` function to compare the\nbeginning of two Swift strings. The `strncmp` function takes two\n`const char*` pointers and an integer specifying the number of characters\nto compare. Because the strings are identical up to the 14th character,\ncomparing only those characters results in a return value of `0`.\n"
],
[
"discussion",
"``` \n let s1 = \"They call me 'Bell'\"\n let s2 = \"They call me 'Stacey'\"\n\n print(strncmp(s1, s2, 14))\n // Prints \"0\"\n print(String(s1.utf8.prefix(14)))\n // Prints \"They call me '\"\n```\n"
],
[
"discussion",
"Extending the compared character count to 15 includes the differing\ncharacters, so a nonzero result is returned.\n"
],
[
"discussion",
"``` \n print(strncmp(s1, s2, 15))\n // Prints \"-17\"\n print(String(s1.utf8.prefix(15)))\n // Prints \"They call me 'B\"\n```\n"
]
],
"declaration" : {
"attributes" : [],
"name" : "UTF8View",
"methods" : [
{
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "String.UTF8View.Index"
}
],
"output" : "String.UTF8View.Index"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UTF8View",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "index(after:)",
"keyword" : "func",
"attributes" : []
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : []
}
},
{
"documentation" : [
[
"summary",
"A position in a string's `UTF8View` instance.\n"
],
[
"discussion",
"You can convert between indices of the different string views by using\nconversion initializers and the `samePosition(in:)` method overloads.\nFor example, the following code sample finds the index of the first\nspace in the string's character view and then converts that to the same\nposition in the UTF-8 view.\n"
],
[
"discussion",
"``` \n let hearts = \"Hearts <3 ♥︎ 💘\"\n if let i = hearts.characters.index(of: \" \") {\n let j = i.samePosition(in: hearts.utf8)\n print(Array(hearts.utf8.prefix(upTo: j)))\n print(hearts.utf8.prefix(upTo: j))\n }\n // Prints \"[72, 101, 97, 114, 116, 115]\"\n // Prints \"Hearts\"\n```\n"
]
],
"declaration" : {
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UTF8View",
"methods" : [],
"name" : "Index",
"keyword" : "struct",
"attributes" : []
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "CharacterView",
"methods" : [],
"keyword" : "struct"
},
"documentation" : [
[
"summary",
"A view of a string's contents as a collection of characters.\n"
],
[
"discussion",
"In Swift, every string provides a view of its contents as characters. In\nthis view, many individual characters---for example, \"é\", \"김\", and\n\"🇮🇳\"---can be made up of multiple Unicode code points. These code points\nare combined by Unicode's boundary algorithms into *extended grapheme\nclusters*, represented by the `Character` type. Each element of a\n`CharacterView` collection is a `Character` instance.\n"
],
[
"discussion",
"``` \n let flowers = \"Flowers 💐\"\n for c in flowers.characters {\n print(c)\n }\n // F\n // l\n // o\n // w\n // e\n // r\n // s\n //\n // 💐\n```\n"
],
[
"discussion",
"You can convert a `String.CharacterView` instance back into a string\nusing the `String` type's `init(_:)` initializer.\n"
],
[
"discussion",
"``` \n let name = \"Marie Curie\"\n if let firstSpace = name.characters.index(of: \" \") {\n let firstName = String(name.characters.prefix(upTo: firstSpace))\n print(firstName)\n }\n // Prints \"Marie\"\n```\n"
]
]
},
{
"documentation" : [
[
"summary",
"A view of a string's contents as a collection of Unicode scalar values.\n"
],
[
"discussion",
"You can access a string's view of Unicode scalar values by using its\n`unicodeScalars` property. Unicode scalar values are the 21-bit codes\nthat are the basic unit of Unicode. Each scalar value is represented by\na `UnicodeScalar` instance and is equivalent to a UTF-32 code unit.\n"
],
[
"discussion",
"``` \n let flowers = \"Flowers 💐\"\n for v in flowers.unicodeScalars {\n print(v.value)\n }\n // 70\n // 108\n // 111\n // 119\n // 101\n // 114\n // 115\n // 32\n // 128144\n```\n"
],
[
"discussion",
"Some characters that are visible in a string are made up of more than one\nUnicode scalar value. In that case, a string's `unicodeScalars` view\ncontains more values than its `characters` view.\n"
],
[
"discussion",
"``` \n let flag = \"🇵🇷\"\n for c in flag.characters {\n print(c)\n }\n // 🇵🇷\n\n for v in flag.unicodeScalars {\n print(v.value)\n }\n // 127477\n // 127479\n```\n"
],
[
"discussion",
"You can convert a `String.UnicodeScalarView` instance back into a string\nusing the `String` type's `init(_:)` initializer.\n"
],
[
"discussion",
"``` \n let favemoji = \"My favorite emoji is 🎉\"\n if let i = favemoji.unicodeScalars.index(where: { $0.value >= 128 }) {\n let asciiPrefix = String(favemoji.unicodeScalars.prefix(upTo: i))\n print(asciiPrefix)\n }\n // Prints \"My favorite emoji is \"\n```\n"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"signature" : {
"output" : "String.UnicodeScalarView.Index",
"input" : [
{
"name" : "after",
"type" : "String.UnicodeScalarView.Index",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "UnicodeScalarView",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(after:)",
"attributes" : []
},
{
"context" : "UnicodeScalarView",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "String.UnicodeScalarView.Index",
"input" : [
{
"name" : "before",
"type" : "String.UnicodeScalarView.Index",
"attributes" : []
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)"
},
{
"name" : "makeIterator()",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [],
"output" : "String.UnicodeScalarView.Iterator"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnicodeScalarView"
}
],
"name" : "UnicodeScalarView",
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : []
}
},
{
"documentation" : [
[
"summary",
"A position in a string's `UnicodeScalars` view.\n"
],
[
"discussion",
"You can convert between indices of the different string views by using\nconversion initializers and the `samePosition(in:)` method overloads.\nThe following example finds the index of the solid heart pictograph in\nthe string's character view and then converts that to the same\nposition in the Unicode scalars view:\n"
],
[
"discussion",
"``` \n let hearts = \"Hearts <3 ♥︎ 💘\"\n let i = hearts.characters.index(of: \"♥︎\")!\n\n let j = i.samePosition(in: hearts.unicodeScalars)\n print(hearts.unicodeScalars.suffix(from: j))\n // Prints \"♥︎ 💘\"\n print(hearts.unicodeScalars[j].value)\n // Prints \"9829\"\n```\n"
]
],
"declaration" : {
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnicodeScalarView",
"keyword" : "struct",
"name" : "Index",
"methods" : [],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"An iterator over the Unicode scalars that make up a `UnicodeScalarView`\ncollection.\n"
]
],
"declaration" : {
"context" : "UnicodeScalarView",
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"name" : "Iterator",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "UnicodeScalar?",
"input" : []
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "UnicodeScalarView.Iterator",
"name" : "next()",
"keyword" : "func",
"attributes" : []
}
]
}
},
{
"documentation" : [
[
"summary",
"A position in a string's `CharacterView` instance.\n"
],
[
"discussion",
"You can convert between indices of the different string views by using\nconversion initializers and the `samePosition(in:)` method overloads.\nThe following example finds the index of the first space in the string's\ncharacter view and then converts that to the same position in the UTF-8\nview:\n"
],
[
"discussion",
"``` \n let hearts = \"Hearts <3 ♥︎ 💘\"\n if let i = hearts.characters.index(of: \" \") {\n let j = i.samePosition(in: hearts.utf8)\n print(Array(hearts.utf8.prefix(upTo: j)))\n }\n // Prints \"[72, 101, 97, 114, 116, 115]\"\n```\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"name" : "Index",
"methods" : []
}
},
{
"documentation" : [
[
"summary",
"An unsigned integer value type.\n"
],
[
"discussion",
"On 32-bit platforms, `UInt` is the same size as `UInt32`, and\non 64-bit platforms, `UInt` is the same size as `UInt64`.\n"
]
],
"declaration" : {
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "UInt",
"methods" : [],
"attributes" : []
}
},
{
"declaration" : {
"name" : "UInt16",
"methods" : [],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A 16-bit unsigned integer value\ntype.\n"
]
]
},
{
"declaration" : {
"methods" : [],
"name" : "UInt32",
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A 32-bit unsigned integer value\ntype.\n"
]
]
},
{
"declaration" : {
"keyword" : "struct",
"name" : "UInt64",
"methods" : [],
"attributes" : [],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A 64-bit unsigned integer value\ntype.\n"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : [],
"attributes" : [],
"methods" : [],
"name" : "UInt8",
"keyword" : "struct"
},
"documentation" : [
[
"summary",
"An 8-bit unsigned integer value\ntype.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A codec for translating between Unicode scalar values and UTF-16 code\nunits.\n"
]
],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "UTF16",
"methods" : [
{
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "UTF16",
"genericRequirements" : [
"I : IteratorProtocol, ",
"I.Element == UTF16.CodeUnit"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "I"
}
],
"signature" : {
"output" : "UnicodeDecodingResult ",
"input" : [
{
"attributes" : [],
"type" : "inout I",
"name" : "_"
}
]
},
"attributes" : [],
"name" : "decode(_:)",
"keyword" : "func"
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "UnicodeScalar",
"name" : "_"
},
{
"type" : "(UTF16.CodeUnit) -> Swift.Void",
"attributes" : [],
"name" : "into"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "UTF16",
"keyword" : "func",
"name" : "encode(_:into:)",
"attributes" : []
}
],
"keyword" : "struct",
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"A codec for translating between Unicode scalar values and UTF-32 code\nunits.\n"
]
],
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "UTF32",
"methods" : [
{
"keyword" : "func",
"name" : "decode(_:)",
"attributes" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "I"
}
],
"genericRequirements" : [
"I : IteratorProtocol, ",
"I.Element == UTF32.CodeUnit"
],
"signature" : {
"output" : "UnicodeDecodingResult ",
"input" : [
{
"type" : "inout I",
"attributes" : [],
"name" : "_"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "UTF32"
},
{
"attributes" : [],
"name" : "encode(_:into:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "UTF32",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "UnicodeScalar",
"attributes" : []
},
{
"type" : "(UTF32.CodeUnit) -> Swift.Void",
"attributes" : [],
"name" : "into"
}
]
}
}
],
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : []
}
},
{
"documentation" : [
[
"summary",
"A codec for translating between Unicode scalar values and UTF-8 code\nunits.\n"
]
],
"declaration" : {
"keyword" : "struct",
"name" : "UTF8",
"methods" : [
{
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout I",
"name" : "_"
}
],
"output" : "UnicodeDecodingResult "
},
"genericRequirements" : [
"I : IteratorProtocol, ",
"I.Element == UTF8.CodeUnit"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "I"
}
],
"context" : "UTF8",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"name" : "decode(_:)",
"keyword" : "func",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "UTF8",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "UnicodeScalar",
"attributes" : [],
"name" : "_"
},
{
"attributes" : [],
"type" : "(UTF8.CodeUnit) -> Swift.Void",
"name" : "into"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "encode(_:into:)"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "isContinuation(_:)",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "UTF8",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Bool",
"input" : [
{
"name" : "_",
"type" : "UTF8.CodeUnit",
"attributes" : []
}
]
}
}
],
"attributes" : [],
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"attributes" : [],
"name" : "UnfoldSequence",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "next()",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "UnfoldSequence",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "Element?"
}
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
},
{
"attributes" : [],
"name" : "State"
}
]
},
"documentation" : [
[
"summary",
"A sequence whose elements are produced via repeated applications of a\nclosure to some mutable state.\n"
],
[
"discussion",
"The elements of the sequence are computed lazily and the sequence may\npotentially be infinite in length.\n"
],
[
"discussion",
"Instances of `UnfoldSequence` are created with the functions\n`sequence(first:next:)` and `sequence(state:next:)`.\n"
],
[
"seealso",
"`sequence(first:next:)`, `sequence(state:next:)`"
]
]
},
{
"documentation" : [
[
"summary",
"A Unicode scalar value.\n"
],
[
"discussion",
"The `UnicodeScalar` type, representing a single Unicode scalar value, is\nthe element type of a string's `unicodeScalars` collection.\n"
],
[
"discussion",
"You can create a `UnicodeScalar` instance by using a string literal that\ncontains a single character representing exactly one Unicode scalar value.\n"
],
[
"discussion",
"``` \n let letterK: UnicodeScalar = \"K\"\n let kim: UnicodeScalar = \"김\"\n print(letterK, kim)\n // Prints \"K 김\"\n```\n"
],
[
"discussion",
"You can also create Unicode scalar values directly from their numeric\nrepresentation.\n"
],
[
"discussion",
"``` \n let airplane = UnicodeScalar(9992)\n print(airplane)\n // Prints \"✈︎\"\n```\n"
]
],
"declaration" : {
"name" : "UnicodeScalar",
"methods" : [
{
"attributes" : [],
"name" : "escaped(asASCII:)",
"keyword" : "func",
"context" : "UnicodeScalar",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "Bool",
"attributes" : [],
"name" : "asASCII"
}
],
"output" : "String"
},
"genericRequirements" : [],
"genericParameters" : []
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"modifiers" : [
{
"name" : "public"
}
],
"methods" : [],
"name" : "UTF16View",
"keyword" : "struct",
"attributes" : []
},
"documentation" : []
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [
"Instance : AnyObject "
],
"genericParameters" : [
{
"name" : "Instance",
"attributes" : []
}
],
"inheritence" : [],
"attributes" : [],
"name" : "Unmanaged",
"methods" : [
{
"attributes" : [],
"name" : "fromOpaque(_:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "Unmanaged",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "UnsafeRawPointer",
"attributes" : []
}
],
"output" : "Unmanaged<Instance>"
}
},
{
"attributes" : [],
"keyword" : "func",
"name" : "toOpaque()",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Unmanaged",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "UnsafeMutableRawPointer"
}
},
{
"attributes" : [],
"keyword" : "func",
"name" : "passRetained(_:)",
"context" : "Unmanaged",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"type" : "Instance",
"attributes" : []
}
],
"output" : "Unmanaged<Instance>"
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"context" : "Unmanaged",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"signature" : {
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Instance"
}
],
"output" : "Unmanaged<Instance>"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "passUnretained(_:)"
},
{
"keyword" : "func",
"name" : "takeUnretainedValue()",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Instance",
"input" : []
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Unmanaged"
},
{
"context" : "Unmanaged",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Instance",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "takeRetainedValue()"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "retain()",
"context" : "Unmanaged",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [],
"output" : "Unmanaged<Instance>"
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "release()",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Unmanaged",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : []
}
},
{
"keyword" : "func",
"name" : "autorelease()",
"attributes" : [],
"signature" : {
"output" : "Unmanaged<Instance>",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "Unmanaged",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"keyword" : "struct"
},
"documentation" : [
[
"summary",
"A type for propagating an unmanaged object reference.\n"
],
[
"discussion",
"When you use this type, you become partially responsible for\nkeeping the object alive.\n"
]
]
},
{
"documentation" : [
[
"summary",
"A non-owning collection interface to a buffer of\nelements stored contiguously in memory.\n"
],
[
"discussion",
"You can use an `UnsafeBufferPointer` instance in low level operations to eliminate\nuniqueness checks and, in release mode, bounds checks. Bounds checks are\nalways performed in debug mode.\n"
],
[
"discussion",
"# UnsafeBufferPointer Semantics\n"
],
[
"discussion",
"An `UnsafeBufferPointer` instance is a view into memory and does not own the memory\nthat it references. Copying a value of type `UnsafeBufferPointer` does not copy the\ninstances stored in the underlying memory. However, initializing another\ncollection with an `UnsafeBufferPointer` instance copies the instances out of the\nreferenced memory and into the new collection.\n"
],
[
"seealso",
"`UnsafePointer`, `UnsafeRawBufferPointer`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"attributes" : [],
"name" : "UnsafeBufferPointer",
"methods" : [
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"type" : "Int",
"attributes" : [],
"name" : "after"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeBufferPointer",
"name" : "index(after:)",
"keyword" : "func",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeBufferPointer",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Int",
"name" : "after"
}
]
},
"attributes" : [],
"name" : "formIndex(after:)",
"keyword" : "func"
},
{
"name" : "index(before:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "before"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeBufferPointer"
},
{
"attributes" : [],
"name" : "formIndex(before:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeBufferPointer",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"name" : "before",
"attributes" : [],
"type" : "inout Int"
}
]
}
},
{
"attributes" : [],
"name" : "index(_:offsetBy:)",
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeBufferPointer",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "_"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "Int"
}
],
"output" : "Int"
}
},
{
"signature" : {
"input" : [
{
"name" : "_",
"type" : "Int",
"attributes" : []
},
{
"attributes" : [],
"type" : "Int",
"name" : "offsetBy"
},
{
"name" : "limitedBy",
"type" : "Int",
"attributes" : []
}
],
"output" : "Int?"
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "UnsafeBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "index(_:offsetBy:limitedBy:)",
"attributes" : []
},
{
"keyword" : "func",
"name" : "distance(from:to:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"type" : "Int",
"attributes" : [],
"name" : "from"
},
{
"name" : "to",
"attributes" : [],
"type" : "Int"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeBufferPointer"
},
{
"keyword" : "func",
"name" : "makeIterator()",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "UnsafeBufferPointerIterator<Element>",
"input" : []
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeBufferPointer"
}
],
"keyword" : "struct"
}
},
{
"declaration" : {
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "struct",
"name" : "UnsafeBufferPointerIterator",
"methods" : [
{
"keyword" : "func",
"name" : "next()",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "Element?"
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "UnsafeBufferPointerIterator"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"An iterator for the elements in the buffer referenced by an\n`UnsafeBufferPointer` or `UnsafeMutableBufferPointer` instance.\n"
]
]
},
{
"declaration" : {
"name" : "UnsafeMutableBufferPointer",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "index(after:)",
"context" : "UnsafeMutableBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "after",
"attributes" : [],
"type" : "Int"
}
],
"output" : "Int"
},
"genericParameters" : [],
"genericRequirements" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableBufferPointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Int",
"name" : "after"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "formIndex(after:)"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableBufferPointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"name" : "before",
"type" : "Int",
"attributes" : []
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "index(before:)"
},
{
"keyword" : "func",
"name" : "formIndex(before:)",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "inout Int",
"attributes" : [],
"name" : "before"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "UnsafeMutableBufferPointer",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "index(_:offsetBy:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "Int",
"attributes" : [],
"name" : "_"
},
{
"type" : "Int",
"attributes" : [],
"name" : "offsetBy"
}
],
"output" : "Int"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableBufferPointer"
},
{
"name" : "index(_:offsetBy:limitedBy:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"output" : "Int?",
"input" : [
{
"name" : "_",
"attributes" : [],
"type" : "Int"
},
{
"name" : "offsetBy",
"attributes" : [],
"type" : "Int"
},
{
"attributes" : [],
"type" : "Int",
"name" : "limitedBy"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UnsafeMutableBufferPointer",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "from"
},
{
"name" : "to",
"attributes" : [],
"type" : "Int"
}
],
"output" : "Int"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableBufferPointer",
"name" : "distance(from:to:)",
"keyword" : "func",
"attributes" : []
},
{
"attributes" : [],
"keyword" : "func",
"name" : "makeIterator()",
"context" : "UnsafeMutableBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "UnsafeBufferPointerIterator<Element>",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : []
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A non-owning collection interface to a buffer of mutable\nelements stored contiguously in memory.\n"
],
[
"discussion",
"You can use an `UnsafeMutableBufferPointer` instance in low level operations to eliminate\nuniqueness checks and, in release mode, bounds checks. Bounds checks are\nalways performed in debug mode.\n"
],
[
"discussion",
"# UnsafeMutableBufferPointer Semantics\n"
],
[
"discussion",
"An `UnsafeMutableBufferPointer` instance is a view into memory and does not own the memory\nthat it references. Copying a value of type `UnsafeMutableBufferPointer` does not copy the\ninstances stored in the underlying memory. However, initializing another\ncollection with an `UnsafeMutableBufferPointer` instance copies the instances out of the\nreferenced memory and into the new collection.\n"
],
[
"seealso",
"`UnsafeMutablePointer`, `UnsafeMutableRawBufferPointer`"
]
]
},
{
"declaration" : {
"attributes" : [],
"keyword" : "struct",
"name" : "UnsafeMutablePointer",
"methods" : [
{
"keyword" : "func",
"name" : "allocate(capacity:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "UnsafeMutablePointer<Pointee>",
"input" : [
{
"name" : "capacity",
"attributes" : [],
"type" : "Int"
}
]
},
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"context" : "UnsafeMutablePointer"
},
{
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "capacity"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "UnsafeMutablePointer",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "deallocate(capacity:)",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutablePointer",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Pointee",
"input" : []
},
"attributes" : [],
"name" : "move()",
"keyword" : "func"
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "UnsafePointer<Pointee>",
"name" : "from"
},
{
"name" : "count",
"type" : "Int",
"attributes" : []
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutablePointer",
"name" : "assign(from:count:)",
"keyword" : "func",
"attributes" : []
},
{
"signature" : {
"input" : [
{
"type" : "UnsafeMutablePointer<Pointee>",
"attributes" : [],
"name" : "from"
},
{
"name" : "count",
"attributes" : [],
"type" : "Int"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UnsafeMutablePointer",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "moveInitialize(from:count:)",
"keyword" : "func",
"attributes" : []
},
{
"keyword" : "func",
"name" : "initialize(from:count:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "from",
"type" : "UnsafePointer<Pointee>",
"attributes" : []
},
{
"name" : "count",
"attributes" : [],
"type" : "Int"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutablePointer"
},
{
"context" : "UnsafeMutablePointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "C",
"name" : "from"
}
]
},
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == Pointee"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "C"
}
],
"attributes" : [
{
"name" : "available",
"tokens" : [],
"argument" : "*, deprecated, message: \"it will be removed in Swift 4.0. Please use 'UnsafeMutableBufferPointer.initialize(from:)' instead\""
}
],
"name" : "initialize(from:)",
"keyword" : "func"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "moveAssign(from:count:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutablePointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "UnsafeMutablePointer<Pointee>",
"attributes" : [],
"name" : "from"
},
{
"type" : "Int",
"attributes" : [],
"name" : "count"
}
]
}
},
{
"genericRequirements" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
},
{
"name" : "Result",
"attributes" : []
}
],
"signature" : {
"input" : [
{
"name" : "to",
"type" : "T.Type",
"attributes" : []
},
{
"type" : "Int",
"attributes" : [],
"name" : "capacity"
},
{
"type" : "(UnsafeMutablePointer<T>) throws -> Result",
"attributes" : [],
"name" : "_"
}
],
"throwsOrRethrowsKeyword" : "rethrows ",
"output" : "Result"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutablePointer",
"name" : "withMemoryRebound(to:capacity:_:)",
"keyword" : "func",
"attributes" : []
},
{
"signature" : {
"output" : "UnsafeMutablePointer<Pointee>",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "UnsafeMutablePointer",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "successor()",
"attributes" : []
},
{
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "UnsafeMutablePointer<Pointee>",
"input" : []
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutablePointer",
"keyword" : "func",
"name" : "predecessor()",
"attributes" : []
},
{
"context" : "UnsafeMutablePointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "UnsafeMutablePointer<Pointee>",
"name" : "to"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "distance(to:)"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutablePointer",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "UnsafeMutablePointer<Pointee>",
"input" : [
{
"name" : "by",
"attributes" : [],
"type" : "Int"
}
]
},
"attributes" : [],
"name" : "advanced(by:)",
"keyword" : "func"
}
],
"modifiers" : [
{
"name" : "public"
}
],
"genericParameters" : [
{
"name" : "Pointee",
"attributes" : []
}
],
"inheritence" : [],
"genericRequirements" : []
},
"documentation" : [
[
"summary",
"A pointer for accessing and manipulating data of a\nspecific type.\n"
],
[
"discussion",
"You use instances of the `UnsafeMutablePointer` type to access data of a\nspecific type in memory. The type of data that a pointer can access is the\npointer's `Pointee` type. `UnsafeMutablePointer` provides no automated\nmemory management or alignment guarantees. You are responsible for\nhandling the life cycle of any memory you work with through unsafe\npointers to avoid leaks or undefined behavior.\n"
],
[
"discussion",
"Memory that you manually manage can be either *untyped* or *bound* to a\nspecific type. You use the `UnsafeMutablePointer` type to access and\nmanage memory that has been bound to a specific type.\n"
],
[
"discussion",
"# Understanding a Pointer's Memory State\n"
],
[
"discussion",
"The memory referenced by an `UnsafeMutablePointer` instance can be in\none of several states. Many pointer operations must only be applied to\npointers with memory in a specific state---you must keep track of the\nstate of the memory you are working with and understand the changes to\nthat state that different operations perform. Memory can be untyped and\nuninitialized, bound to a type and uninitialized, or bound to a type and\ninitialized to a value. Finally, memory that was allocated previously may\nhave been deallocated, leaving existing pointers referencing unallocated\nmemory.\n"
],
[
"discussion",
"## Uninitialized Memory\n"
],
[
"discussion",
"Memory that has just been allocated through a typed pointer or has been\ndeinitialized is in an *uninitialized* state. Uninitialized memory must be\ninitialized before it can be accessed for reading.\n"
],
[
"discussion",
"You can use methods like `initialize(to:count:)`, `initialize(from:)`, and\n`moveInitializeMemory(from:count)` to initialize the memory referenced by\na pointer with a value or series of values.\n"
],
[
"discussion",
"## Initialized Memory\n"
],
[
"discussion",
"*Initialized* memory has a value that can be read using a pointer's\n`pointee` property or through subscript notation. In the following\nexample, `ptr` is a pointer to memory initialized with a value of `23`:\n"
],
[
"discussion",
"``` \n let ptr: UnsafeMutablePointer<Int> = ...\n // ptr.pointee == 23\n // ptr[0] == 23\n```\n"
],
[
"discussion",
"# Accessing a Pointer's Memory as a Different Type\n"
],
[
"discussion",
"When you access memory through an `UnsafeMutablePointer` instance, the\n`Pointee` type must be consistent with the bound type of the memory. If\nyou do need to access memory that is bound to one type as a different\ntype, Swift's pointer types provide type-safe ways to temporarily or\npermanently change the bound type of the memory, or to load typed\ninstances directly from raw memory.\n"
],
[
"discussion",
"An `UnsafeMutablePointer<UInt8>` instance allocated with eight bytes of\nmemory, `uint8Pointer`, will be used for the examples below.\n"
],
[
"discussion",
"``` \n let uint8Pointer = UnsafeMutablePointer<UInt8>.allocate(capacity: 8)\n uint8Pointer.initialize(from: [39, 77, 111, 111, 102, 33, 39, 0])\n```\n"
],
[
"discussion",
"When you only need to temporarily access a pointer's memory as a different\ntype, use the `withMemoryRebound(to:capacity:)` method. For example, you\ncan use this method to call an API that expects a pointer to a different\ntype that is layout compatible with your pointer's `Pointee`. The following\ncode temporarily rebinds the memory that `uint8Pointer` references from\n`UInt8` to `Int8` to call the imported C `strlen` function.\n"
],
[
"discussion",
"``` \n // Imported from C\n func strlen(_ __s: UnsafePointer<Int8>!) -> UInt\n\n let length = uint8Pointer.withMemoryRebound(to: Int8.self, capacity: 8) {\n return strlen($0)\n }\n // length == 7\n```\n"
],
[
"discussion",
"When you need to permanently rebind memory to a different type, first\nobtain a raw pointer to the memory and then call the\n`bindMemory(to:capacity:)` method on the raw pointer. The following\nexample binds the memory referenced by `uint8Pointer` to one instance of\nthe `UInt64` type:\n"
],
[
"discussion",
"``` \n let uint64Pointer = UnsafeMutableRawPointer(uint64Pointer)\n .bindMemory(to: UInt64.self, capacity: 1)\n```\n"
],
[
"discussion",
"After rebinding the memory referenced by `uint8Pointer` to `UInt64`,\naccessing that pointer's referenced memory as a `UInt8` instance is\nundefined.\n"
],
[
"discussion",
"``` \n var fullInteger = uint64Pointer.pointee // OK\n var firstByte = uint8Pointer.pointee // undefined\n```\n"
],
[
"discussion",
"Alternatively, you can access the same memory as a different type without\nrebinding through untyped memory access, so long as the bound type and the\ndestination type are trivial types. Convert your pointer to an\n`UnsafeMutableRawPointer` instance and then use the raw pointer's\n`load(fromByteOffset:as:)` and `storeBytes(of:toByteOffset:as:)` methods\nto read and write values.\n"
],
[
"discussion",
"``` \n let rawPointer = UnsafeMutableRawPointer(uint64Pointer)\n fullInteger = rawPointer.load(as: UInt64.self) // OK\n firstByte = rawPointer.load(as: UInt8.self) // OK\n```\n"
],
[
"discussion",
"# Performing Typed Pointer Arithmetic\n"
],
[
"discussion",
"Pointer arithmetic with a typed pointer is counted in strides of the\npointer's `Pointee` type. When you add to or subtract from an `UnsafeMutablePointer`\ninstance, the result is a new pointer of the same type, offset by that\nnumber of instances of the `Pointee` type.\n"
],
[
"discussion",
"``` \n // 'intPointer' points to memory initialized with [10, 20, 30, 40]\n let intPointer: UnsafeMutablePointer<Int> = ...\n\n // Load the first value in memory\n let x = intPointer.pointee\n // x == 10\n\n // Load the third value in memory\n let offsetPointer = intPointer + 2\n let y = offsetPointer.pointee\n // y == 30\n```\n"
],
[
"discussion",
"You can also use subscript notation to access the value in memory at a\nspecific offset.\n"
],
[
"discussion",
"``` \n let z = intPointer[2]\n // z == 30\n```\n"
],
[
"discussion",
"# Implicit Casting and Bridging\n"
],
[
"discussion",
"When calling a function or method with an `UnsafeMutablePointer` parameter, you can pass\nan instance of that specific pointer type or use Swift's implicit bridging\nto pass a compatible pointer.\n"
],
[
"discussion",
"For example, the `printInt(atAddress:)` function in the following code\nsample expects an `UnsafeMutablePointer<Int>` instance as its first parameter:\n"
],
[
"discussion",
"``` \n func printInt(atAddress p: UnsafeMutablePointer<Int>) {\n print(p.pointee)\n }\n```\n"
],
[
"discussion",
"As is typical in Swift, you can call the `printInt(atAddress:)` function\nwith an `UnsafeMutablePointer` instance. This example passes `intPointer`, a mutable\npointer to an `Int` value, to `print(address:)`.\n"
],
[
"discussion",
"``` \n printInt(atAddress: intPointer)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"Alternatively, you can use Swift's *implicit bridging* to pass a pointer to\nan instance or to the elements of an array. The following example passes a\npointer to the `value` variable by using inout syntax:\n"
],
[
"discussion",
"``` \n var value: Int = 23\n printInt(atAddress: &value)\n // Prints \"23\"\n```\n"
],
[
"discussion",
"A mutable pointer to the elements of an array is implicitly created when\nyou pass the array using inout syntax. This example uses implicit bridging\nto pass a pointer to the elements of `numbers` when calling\n`printInt(atAddress:)`.\n"
],
[
"discussion",
"``` \n var numbers = [5, 10, 15, 20]\n printInt(atAddress: &numbers)\n // Prints \"5\"\n```\n"
],
[
"discussion",
"However you call `printInt(atAddress:)`, Swift's type safety guarantees\nthat you can only pass a pointer to the type required by the function---in\nthis case, a pointer to an `Int`.\n"
],
[
"important",
"The pointer created through implicit bridging of an instance\nor of an array's elements is only valid during the execution of the\ncalled function. Escaping the pointer to use after the execution of the\nfunction is undefined behavior. In particular, do not use implicit\nbridging when calling an `UnsafeMutablePointer` initializer.\n\n var number = 5\n let numberPointer = UnsafeMutablePointer<Int>(&number)\n // Accessing 'numberPointer' is undefined behavior."
]
]
},
{
"declaration" : {
"keyword" : "struct",
"name" : "UnsafeMutableRawBufferPointer",
"methods" : [
{
"name" : "allocate(count:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "Int",
"attributes" : [],
"name" : "count"
}
],
"output" : "UnsafeMutableRawBufferPointer"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UnsafeMutableRawBufferPointer",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
]
},
{
"name" : "deallocate()",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : []
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UnsafeMutableRawBufferPointer",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"signature" : {
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "UnsafeRawBufferPointer"
}
]
},
"genericParameters" : [],
"genericRequirements" : [],
"context" : "UnsafeMutableRawBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "copyBytes(from:)",
"attributes" : []
},
{
"keyword" : "func",
"name" : "copyBytes(from:)",
"attributes" : [],
"signature" : {
"input" : [
{
"name" : "from",
"attributes" : [],
"type" : "C"
}
]
},
"genericParameters" : [
{
"attributes" : [],
"name" : "C"
}
],
"genericRequirements" : [
"C : Collection, ",
"C.Iterator.Element == UInt8"
],
"context" : "UnsafeMutableRawBufferPointer",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"keyword" : "func",
"name" : "makeIterator()",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [],
"output" : "UnsafeMutableRawBufferPointer.Iterator"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableRawBufferPointer"
},
{
"signature" : {
"input" : [
{
"name" : "as",
"attributes" : [],
"type" : "S.Iterator.Element.Type"
},
{
"type" : "S",
"attributes" : [],
"name" : "from"
}
],
"output" : "(unwritten: S.Iterator, initialized: UnsafeMutableBufferPointer<S.Iterator.Element>) "
},
"genericRequirements" : [
"S : Sequence"
],
"genericParameters" : [
{
"name" : "S",
"attributes" : []
}
],
"context" : "UnsafeMutableRawBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"name" : "initializeMemory(as:from:)",
"keyword" : "func",
"attributes" : []
}
],
"attributes" : [],
"genericParameters" : [],
"inheritence" : [],
"genericRequirements" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A mutable nonowning collection interface to the bytes in a\nregion of memory.\n"
],
[
"discussion",
"You can use an `UnsafeMutableRawBufferPointer` instance in low-level operations to eliminate\nuniqueness checks and release mode bounds checks. Bounds checks are always\nperformed in debug mode.\n"
],
[
"discussion",
"An `UnsafeMutableRawBufferPointer` instance is a view of the raw bytes in a region of memory.\nEach byte in memory is viewed as a `UInt8` value independent of the type\nof values held in that memory. Reading from and writing to memory through\na raw buffer are untyped operations. Accessing this collection's bytes\ndoes not bind the underlying memory to `UInt8`.\n"
],
[
"discussion",
"In addition to its collection interface, an `UnsafeMutableRawBufferPointer` instance also supports\nthe following methods provided by `UnsafeMutableRawPointer`, including\nbounds checks in debug mode:\n"
],
[
"discussion",
" - `load(fromByteOffset:as:)`\n - `storeBytes(of:toByteOffset:as:)`\n - `copyBytes(from:count:)`\n"
],
[
"discussion",
"To access the underlying memory through typed operations, the memory must\nbe bound to a trivial type.\n"
],
[
"note",
"A *trivial type* can be copied bit for bit with no indirection\nor reference-counting operations. Generally, native Swift types that do\nnot contain strong or weak references or other forms of indirection are\ntrivial, as are imported C structs and enums. Copying memory that\ncontains values of nontrivial types can only be done safely with a typed\npointer. Copying bytes directly from nontrivial, in-memory values does\nnot produce valid copies and can only be done by calling a C API, such as\n`memmove()`."
],
[
"discussion",
"# UnsafeMutableRawBufferPointer Semantics\n"
],
[
"discussion",
"An `UnsafeMutableRawBufferPointer` instance is a view into memory and does not own the memory\nthat it references. Copying a variable or constant of type `UnsafeMutableRawBufferPointer` does\nnot copy the underlying memory. However, initializing another collection\nwith an `UnsafeMutableRawBufferPointer` instance copies bytes out of the referenced memory and\ninto the new collection.\n"
],
[
"discussion",
"The following example uses `someBytes`, an `UnsafeMutableRawBufferPointer` instance, to\ndemonstrate the difference between assigning a buffer pointer and using a\nbuffer pointer as the source for another collection's elements. Here, the\nassignment to `destBytes` creates a new, nonowning buffer pointer\ncovering the first `n` bytes of the memory that `someBytes`\nreferences---nothing is copied:\n"
],
[
"discussion",
"``` \n var destBytes = someBytes[0..<n]\n```\n"
],
[
"discussion",
"Next, the bytes referenced by `destBytes` are copied into `byteArray`, a\nnew `[UInt]` array, and then the remainder of `someBytes` is appended to\n`byteArray`:\n"
],
[
"discussion",
"``` \n var byteArray: [UInt8] = Array(destBytes)\n byteArray += someBytes[n..<someBytes.count]\n```\n"
],
[
"discussion",
"Assigning into a ranged subscript of an `{$Self}` instance copies bytes\ninto the memory. The next `n` bytes of the memory that `someBytes`\nreferences are copied in this code:\n"
],
[
"discussion",
"``` \n destBytes[0..<n] = someBytes[n..<(n + n)]\n```\n"
],
[
"seealso",
"`UnsafeMutableRawPointer`, `UnsafeMutableBufferPointer`"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableRawBufferPointer",
"inheritence" : [],
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "struct",
"methods" : [
{
"attributes" : [],
"name" : "next()",
"keyword" : "func",
"context" : "UnsafeMutableRawBufferPointer.Iterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"input" : [],
"output" : "UInt8?"
},
"genericRequirements" : [],
"genericParameters" : []
}
],
"name" : "Iterator"
},
"documentation" : [
[
"summary",
"An iterator over the bytes viewed by a raw buffer pointer.\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"name" : "UnsafeMutableRawPointer",
"methods" : [
{
"signature" : {
"output" : "UnsafeMutableRawPointer",
"input" : [
{
"name" : "bytes",
"attributes" : [],
"type" : "Int"
},
{
"name" : "alignedTo",
"attributes" : [],
"type" : "Int"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UnsafeMutableRawPointer",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "static"
}
],
"name" : "allocate(bytes:alignedTo:)",
"keyword" : "func",
"attributes" : []
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableRawPointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "bytes"
},
{
"name" : "alignedTo",
"type" : "Int",
"attributes" : []
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "deallocate(bytes:alignedTo:)"
},
{
"name" : "bindMemory(to:capacity:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"signature" : {
"output" : "UnsafeMutablePointer<T>",
"input" : [
{
"attributes" : [],
"type" : "T.Type",
"name" : "to"
},
{
"attributes" : [],
"type" : "Int",
"name" : "capacity"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableRawPointer"
},
{
"attributes" : [],
"name" : "assumingMemoryBound(to:)",
"keyword" : "func",
"context" : "UnsafeMutableRawPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "UnsafeMutablePointer<T>",
"input" : [
{
"name" : "to",
"attributes" : [],
"type" : "T.Type"
}
]
},
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
]
},
{
"signature" : {
"output" : "UnsafeMutablePointer<T>",
"input" : [
{
"name" : "as",
"attributes" : [],
"type" : "T.Type"
},
{
"attributes" : [],
"type" : "UnsafePointer<T>",
"name" : "from"
},
{
"type" : "Int",
"attributes" : [],
"name" : "count"
}
]
},
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"genericRequirements" : [],
"context" : "UnsafeMutableRawPointer",
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"name" : "initializeMemory(as:from:count:)",
"attributes" : []
},
{
"attributes" : [
{
"name" : "available",
"tokens" : [],
"argument" : "*, deprecated, message: \"it will be removed in Swift 4.0. Please use 'UnsafeMutableRawBufferPointer.initialize(from:)' instead\""
}
],
"keyword" : "func",
"name" : "initializeMemory(as:from:)",
"context" : "UnsafeMutableRawPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "as",
"type" : "C.Iterator.Element.Type",
"attributes" : []
},
{
"type" : "C",
"attributes" : [],
"name" : "from"
}
],
"output" : "UnsafeMutablePointer<C.Iterator.Element> "
},
"genericParameters" : [
{
"name" : "C",
"attributes" : []
}
],
"genericRequirements" : [
"C : Collection"
]
},
{
"name" : "moveInitializeMemory(as:from:count:)",
"keyword" : "func",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "T.Type",
"name" : "as"
},
{
"name" : "from",
"attributes" : [],
"type" : "UnsafeMutablePointer<T>"
},
{
"name" : "count",
"type" : "Int",
"attributes" : []
}
],
"output" : "UnsafeMutablePointer<T>"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableRawPointer"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "copyBytes(from:count:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableRawPointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "UnsafeRawPointer",
"name" : "from"
},
{
"attributes" : [],
"type" : "Int",
"name" : "count"
}
]
}
},
{
"context" : "UnsafeMutableRawPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Int",
"input" : [
{
"attributes" : [],
"type" : "UnsafeMutableRawPointer",
"name" : "to"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"name" : "distance(to:)",
"keyword" : "func"
},
{
"keyword" : "func",
"name" : "advanced(by:)",
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "by",
"attributes" : [],
"type" : "Int"
}
],
"output" : "UnsafeMutableRawPointer"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeMutableRawPointer"
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : []
},
"documentation" : [
[
"summary",
"A raw pointer for accessing and manipulating\nuntyped data.\n"
],
[
"discussion",
"The `UnsafeMutableRawPointer` type provides no automated memory management, no type safety,\nand no alignment guarantees. You are responsible for handling the life\ncycle of any memory you work with through unsafe pointers, to avoid leaks\nor undefined behavior.\n"
],
[
"discussion",
"Memory that you manually manage can be either *untyped* or *bound* to a\nspecific type. You use the `UnsafeMutableRawPointer` type to access and\nmanage raw bytes in memory, whether or not that memory has been bound to a\nspecific type.\n"
],
[
"discussion",
"# Understanding a Pointer's Memory State\n"
],
[
"discussion",
"The memory referenced by an `UnsafeMutableRawPointer` instance can be in one of several\nstates. Many pointer operations must only be applied to pointers with\nmemory in a specific state---you must keep track of the state of the\nmemory you are working with and understand the changes to that state that\ndifferent operations perform. Memory can be untyped and uninitialized,\nbound to a type and uninitialized, or bound to a type and initialized to a\nvalue. Finally, memory that was allocated previously may have been\ndeallocated, leaving existing pointers referencing unallocated memory.\n"
],
[
"discussion",
"## Raw, Uninitialized Memory\n"
],
[
"discussion",
"Raw memory that has just been allocated is in an *uninitialized, untyped*\nstate. Uninitialized memory must be initialized with values of a type\nbefore it can be used with any typed operations.\n"
],
[
"discussion",
"You can use methods like `initializeMemory(as:from:)` and\n`moveInitializeMemory(as:from:count)` to bind raw memory to a type and\ninitialize it with a value or series of values. To bind uninitialized\nmemory to a type without initializing it, use the `bindMemory(to:count:)`\nmethod. These methods all return typed pointers for further typed access\nto the memory.\n"
],
[
"discussion",
"## Typed Memory\n"
],
[
"discussion",
"Memory that has been bound to a type, whether it is initialized or\nuninitialized, is typically accessed using typed pointers---instances of\n`UnsafePointer` and `UnsafeMutablePointer`. Initialization, assignment,\nand deinitialization can be performed using `UnsafeMutablePointer`\nmethods.\n"
],
[
"discussion",
"Memory that has been bound to a type can be rebound to a different type\nonly after it has been deinitialized or if the bound type is a *trivial\ntype*. Deinitializing typed memory does not unbind that memory's type. The\ndeinitialized memory can be reinitialized with values of the same type,\nbound to a new type, or deallocated.\n"
],
[
"note",
"A trivial type can be copied bit for bit with no indirection or\nreference-counting operations. Generally, native Swift types that do not\ncontain strong or weak references or other forms of indirection are\ntrivial, as are imported C structs and enumerations."
],
[
"discussion",
"When reading from or writing to memory as raw\nbytes when that memory is bound to a type, you must ensure that you\nsatisfy any alignment requirements.\nWriting to typed memory as raw bytes must only be performed when the bound\ntype is a trivial type.\n"
],
[
"discussion",
"# Raw Pointer Arithmetic\n"
],
[
"discussion",
"Pointer arithmetic with raw pointers is performed at the byte level. When\nyou add to or subtract from a raw pointer, the result is a new raw pointer\noffset by that number of bytes. The following example allocates four bytes\nof memory and stores `0xFF` in all four bytes:\n"
],
[
"discussion",
"``` \n let bytesPointer = UnsafeMutableRawPointer.allocate(bytes: 4, alignedTo: 1)\n bytesPointer.storeBytes(of: 0xFFFF_FFFF, as: UInt32.self)\n\n // Load a value from the memory referenced by 'bytesPointer'\n let x = bytesPointer.load(as: UInt8.self) // 255\n\n // Load a value from the last two allocated bytes\n let offsetPointer = bytesPointer + 2\n let y = offsetPointer.load(as: UInt16.self) // 65535\n```\n"
],
[
"discussion",
"The code above stores the value `0xFFFF_FFFF` into the four newly allocated\nbytes, and then loads the first byte as a `UInt8` instance and the third\nand fourth bytes as a `UInt16` instance.\n"
],
[
"discussion",
"Always remember to deallocate any memory that you allocate yourself.\n"
],
[
"discussion",
"``` \n bytesPointer.deallocate(bytes: 4, alignedTo: 1)\n```\n"
],
[
"discussion",
"# Implicit Casting and Bridging\n"
],
[
"discussion",
"When calling a function or method with an `UnsafeMutableRawPointer` parameter, you can pass\nan instance of that specific pointer type, pass an instance of a\ncompatible pointer type, or use Swift's implicit bridging to pass a\ncompatible pointer.\n"
],
[
"discussion",
"For example, the `print(address:as:)` function in the following code sample\ntakes an `UnsafeMutableRawPointer` instance as its first parameter:\n"
],
[
"discussion",
"``` \n func print<T>(address p: UnsafeMutableRawPointer, as type: T.Type) {\n let value = p.load(as: type)\n print(value)\n }\n```\n"
],
[
"discussion",
"As is typical in Swift, you can call the `print(address:as:)` function with\nan `UnsafeMutableRawPointer` instance. This example passes `rawPointer` as the initial\nparameter.\n"
],
[
"discussion",
"``` \n // 'rawPointer' points to memory initialized with `Int` values.\n let rawPointer: UnsafeMutableRawPointer = ...\n print(address: rawPointer, as: Int.self)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"Because typed pointers can be implicitly cast to raw pointers when passed\nas a parameter, you can also call `print(address:as:)` with any mutable\ntyped pointer instance.\n"
],
[
"discussion",
"``` \n let intPointer: UnsafeMutablePointer<Int> = ...\n print(address: intPointer, as: Int.self)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"Alternatively, you can use Swift's *implicit bridging* to pass a pointer to\nan instance or to the elements of an array. Use inout syntax to implicitly\ncreate a pointer to an instance of any type. The following example uses\nimplicit bridging to pass a pointer to `value` when calling\n`print(address:as:)`:\n"
],
[
"discussion",
"``` \n var value: Int = 23\n print(address: &value, as: Int.self)\n // Prints \"23\"\n```\n"
],
[
"discussion",
"A mutable pointer to the elements of an array is implicitly created when\nyou pass the array using inout syntax. This example uses implicit bridging\nto pass a pointer to the elements of `numbers` when calling\n`print(address:as:)`.\n"
],
[
"discussion",
"``` \n var numbers = [5, 10, 15, 20]\n print(address: &numbers, as: Int.self)\n // Prints \"5\"\n```\n"
],
[
"important",
"The pointer created through implicit bridging of an instance\nor of an array's elements is only valid during the execution of the\ncalled function. Escaping the pointer to use after the execution of the\nfunction is undefined behavior. In particular, do not use implicit\nbridging when calling an `UnsafeMutableRawPointer` initializer.\n\n var number = 5\n let numberPointer = UnsafeMutableRawPointer(&number)\n // Accessing 'numberPointer' is undefined behavior."
]
]
},
{
"declaration" : {
"name" : "UnsafePointer",
"methods" : [
{
"genericParameters" : [
{
"name" : "T",
"attributes" : []
},
{
"name" : "Result",
"attributes" : []
}
],
"genericRequirements" : [],
"signature" : {
"output" : "Result",
"input" : [
{
"attributes" : [],
"type" : "T.Type",
"name" : "to"
},
{
"name" : "capacity",
"attributes" : [],
"type" : "Int"
},
{
"type" : "(UnsafePointer<T>) throws -> Result",
"attributes" : [],
"name" : "_"
}
],
"throwsOrRethrowsKeyword" : "rethrows "
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafePointer",
"keyword" : "func",
"name" : "withMemoryRebound(to:capacity:_:)",
"attributes" : []
},
{
"context" : "UnsafePointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "UnsafePointer<Pointee>",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "successor()"
},
{
"context" : "UnsafePointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [],
"output" : "UnsafePointer<Pointee>"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "predecessor()"
},
{
"attributes" : [],
"keyword" : "func",
"name" : "distance(to:)",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafePointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"type" : "UnsafePointer<Pointee>",
"attributes" : [],
"name" : "to"
}
]
}
},
{
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "by"
}
],
"output" : "UnsafePointer<Pointee>"
},
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafePointer",
"name" : "advanced(by:)",
"keyword" : "func",
"attributes" : []
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Pointee"
}
],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A pointer for accessing data of a\nspecific type.\n"
],
[
"discussion",
"You use instances of the `UnsafePointer` type to access data of a\nspecific type in memory. The type of data that a pointer can access is the\npointer's `Pointee` type. `UnsafePointer` provides no automated\nmemory management or alignment guarantees. You are responsible for\nhandling the life cycle of any memory you work with through unsafe\npointers to avoid leaks or undefined behavior.\n"
],
[
"discussion",
"Memory that you manually manage can be either *untyped* or *bound* to a\nspecific type. You use the `UnsafePointer` type to access and\nmanage memory that has been bound to a specific type.\n"
],
[
"discussion",
"# Understanding a Pointer's Memory State\n"
],
[
"discussion",
"The memory referenced by an `UnsafePointer` instance can be in\none of several states. Many pointer operations must only be applied to\npointers with memory in a specific state---you must keep track of the\nstate of the memory you are working with and understand the changes to\nthat state that different operations perform. Memory can be untyped and\nuninitialized, bound to a type and uninitialized, or bound to a type and\ninitialized to a value. Finally, memory that was allocated previously may\nhave been deallocated, leaving existing pointers referencing unallocated\nmemory.\n"
],
[
"discussion",
"## Uninitialized Memory\n"
],
[
"discussion",
"Memory that has just been allocated through a typed pointer or has been\ndeinitialized is in an *uninitialized* state. Uninitialized memory must be\ninitialized before it can be accessed for reading.\n"
],
[
"discussion",
"## Initialized Memory\n"
],
[
"discussion",
"*Initialized* memory has a value that can be read using a pointer's\n`pointee` property or through subscript notation. In the following\nexample, `ptr` is a pointer to memory initialized with a value of `23`:\n"
],
[
"discussion",
"``` \n let ptr: UnsafePointer<Int> = ...\n // ptr.pointee == 23\n // ptr[0] == 23\n```\n"
],
[
"discussion",
"# Accessing a Pointer's Memory as a Different Type\n"
],
[
"discussion",
"When you access memory through an `UnsafePointer` instance, the\n`Pointee` type must be consistent with the bound type of the memory. If\nyou do need to access memory that is bound to one type as a different\ntype, Swift's pointer types provide type-safe ways to temporarily or\npermanently change the bound type of the memory, or to load typed\ninstances directly from raw memory.\n"
],
[
"discussion",
"An `UnsafePointer<UInt8>` instance allocated with eight bytes of\nmemory, `uint8Pointer`, will be used for the examples below.\n"
],
[
"discussion",
"``` \n let uint8Pointer: UnsafePointer<UInt8> = fetchEightBytes()\n```\n"
],
[
"discussion",
"When you only need to temporarily access a pointer's memory as a different\ntype, use the `withMemoryRebound(to:capacity:)` method. For example, you\ncan use this method to call an API that expects a pointer to a different\ntype that is layout compatible with your pointer's `Pointee`. The following\ncode temporarily rebinds the memory that `uint8Pointer` references from\n`UInt8` to `Int8` to call the imported C `strlen` function.\n"
],
[
"discussion",
"``` \n // Imported from C\n func strlen(_ __s: UnsafePointer<Int8>!) -> UInt\n\n let length = uint8Pointer.withMemoryRebound(to: Int8.self, capacity: 8) {\n return strlen($0)\n }\n // length == 7\n```\n"
],
[
"discussion",
"When you need to permanently rebind memory to a different type, first\nobtain a raw pointer to the memory and then call the\n`bindMemory(to:capacity:)` method on the raw pointer. The following\nexample binds the memory referenced by `uint8Pointer` to one instance of\nthe `UInt64` type:\n"
],
[
"discussion",
"``` \n let uint64Pointer = UnsafeRawPointer(uint64Pointer)\n .bindMemory(to: UInt64.self, capacity: 1)\n```\n"
],
[
"discussion",
"After rebinding the memory referenced by `uint8Pointer` to `UInt64`,\naccessing that pointer's referenced memory as a `UInt8` instance is\nundefined.\n"
],
[
"discussion",
"``` \n var fullInteger = uint64Pointer.pointee // OK\n var firstByte = uint8Pointer.pointee // undefined\n```\n"
],
[
"discussion",
"Alternatively, you can access the same memory as a different type without\nrebinding through untyped memory access, so long as the bound type and the\ndestination type are trivial types. Convert your pointer to an\n`UnsafeRawPointer` instance and then use the raw pointer's\n`load(fromByteOffset:as:)` method to read values.\n"
],
[
"discussion",
"``` \n let rawPointer = UnsafeRawPointer(uint64Pointer)\n fullInteger = rawPointer.load(as: UInt64.self) // OK\n firstByte = rawPointer.load(as: UInt8.self) // OK\n```\n"
],
[
"discussion",
"# Performing Typed Pointer Arithmetic\n"
],
[
"discussion",
"Pointer arithmetic with a typed pointer is counted in strides of the\npointer's `Pointee` type. When you add to or subtract from an `UnsafePointer`\ninstance, the result is a new pointer of the same type, offset by that\nnumber of instances of the `Pointee` type.\n"
],
[
"discussion",
"``` \n // 'intPointer' points to memory initialized with [10, 20, 30, 40]\n let intPointer: UnsafePointer<Int> = ...\n\n // Load the first value in memory\n let x = intPointer.pointee\n // x == 10\n\n // Load the third value in memory\n let offsetPointer = intPointer + 2\n let y = offsetPointer.pointee\n // y == 30\n```\n"
],
[
"discussion",
"You can also use subscript notation to access the value in memory at a\nspecific offset.\n"
],
[
"discussion",
"``` \n let z = intPointer[2]\n // z == 30\n```\n"
],
[
"discussion",
"# Implicit Casting and Bridging\n"
],
[
"discussion",
"When calling a function or method with an `UnsafePointer` parameter, you can pass\nan instance of that specific pointer type, pass an instance of a\ncompatible pointer type, or use Swift's implicit bridging to pass a\ncompatible pointer.\n"
],
[
"discussion",
"For example, the `printInt(atAddress:)` function in the following code\nsample expects an `UnsafePointer<Int>` instance as its first parameter:\n"
],
[
"discussion",
"``` \n func printInt(atAddress p: UnsafePointer<Int>) {\n print(p.pointee)\n }\n```\n"
],
[
"discussion",
"As is typical in Swift, you can call the `printInt(atAddress:)` function\nwith an `UnsafePointer` instance. This example passes `intPointer`, a pointer to\nan `Int` value, to `print(address:)`.\n"
],
[
"discussion",
"``` \n printInt(atAddress: intPointer)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"Because a mutable typed pointer can be implicitly cast to an immutable\npointer with the same `Pointee` type when passed as a parameter, you can\nalso call `printInt(atAddress:)` with an `UnsafeMutablePointer` instance.\n"
],
[
"discussion",
"``` \n let mutableIntPointer = UnsafeMutablePointer(mutating: intPointer)\n printInt(atAddress: mutableIntPointer)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"Alternatively, you can use Swift's *implicit bridging* to pass a pointer to\nan instance or to the elements of an array. The following example passes a\npointer to the `value` variable by using inout syntax:\n"
],
[
"discussion",
"``` \n var value: Int = 23\n printInt(atAddress: &value)\n // Prints \"23\"\n```\n"
],
[
"discussion",
"An immutable pointer to the elements of an array is implicitly created when\nyou pass the array as an argument. This example uses implicit bridging to\npass a pointer to the elements of `numbers` when calling\n`printInt(atAddress:)`.\n"
],
[
"discussion",
"``` \n let numbers = [5, 10, 15, 20]\n printInt(atAddress: numbers)\n // Prints \"5\"\n```\n"
],
[
"discussion",
"You can also use inout syntax to pass a mutable pointer to the elements of\nan array. Because `printInt(atAddress:)` requires an immutable pointer,\nalthough this is syntactically valid, it isn't necessary.\n"
],
[
"discussion",
"``` \n var mutableNumbers = numbers\n printInt(atAddress: &mutableNumbers)\n```\n"
],
[
"discussion",
"However you call `printInt(atAddress:)`, Swift's type safety guarantees\nthat you can only pass a pointer to the type required by the function---in\nthis case, a pointer to an `Int`.\n"
],
[
"important",
"The pointer created through implicit bridging of an instance\nor of an array's elements is only valid during the execution of the\ncalled function. Escaping the pointer to use after the execution of the\nfunction is undefined behavior. In particular, do not use implicit\nbridging when calling an `UnsafePointer` initializer.\n\n var number = 5\n let numberPointer = UnsafePointer<Int>(&number)\n // Accessing 'numberPointer' is undefined behavior."
]
]
},
{
"declaration" : {
"attributes" : [],
"name" : "UnsafeRawBufferPointer",
"methods" : [
{
"attributes" : [],
"name" : "deallocate()",
"keyword" : "func",
"context" : "UnsafeRawBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : []
},
"genericRequirements" : [],
"genericParameters" : []
},
{
"context" : "UnsafeRawBufferPointer",
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [],
"output" : "UnsafeRawBufferPointer.Iterator"
},
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"keyword" : "func",
"name" : "makeIterator()"
}
],
"keyword" : "struct",
"modifiers" : [
{
"name" : "public"
}
],
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : []
},
"documentation" : [
[
"summary",
"A nonowning collection interface to the bytes in a\nregion of memory.\n"
],
[
"discussion",
"You can use an `UnsafeRawBufferPointer` instance in low-level operations to eliminate\nuniqueness checks and release mode bounds checks. Bounds checks are always\nperformed in debug mode.\n"
],
[
"discussion",
"An `UnsafeRawBufferPointer` instance is a view of the raw bytes in a region of memory.\nEach byte in memory is viewed as a `UInt8` value independent of the type\nof values held in that memory. Reading from memory through a raw buffer is\nan untyped operation.\n"
],
[
"discussion",
"In addition to its collection interface, an `UnsafeRawBufferPointer` instance also supports\nthe `load(fromByteOffset:as:)` method provided by `UnsafeRawPointer`,\nincluding bounds checks in debug mode.\n"
],
[
"discussion",
"To access the underlying memory through typed operations, the memory must\nbe bound to a trivial type.\n"
],
[
"note",
"A *trivial type* can be copied bit for bit with no indirection\nor reference-counting operations. Generally, native Swift types that do\nnot contain strong or weak references or other forms of indirection are\ntrivial, as are imported C structs and enums. Copying memory that\ncontains values of nontrivial types can only be done safely with a typed\npointer. Copying bytes directly from nontrivial, in-memory values does\nnot produce valid copies and can only be done by calling a C API, such as\n`memmove()`."
],
[
"discussion",
"# UnsafeRawBufferPointer Semantics\n"
],
[
"discussion",
"An `UnsafeRawBufferPointer` instance is a view into memory and does not own the memory\nthat it references. Copying a variable or constant of type `UnsafeRawBufferPointer` does\nnot copy the underlying memory. However, initializing another collection\nwith an `UnsafeRawBufferPointer` instance copies bytes out of the referenced memory and\ninto the new collection.\n"
],
[
"discussion",
"The following example uses `someBytes`, an `UnsafeRawBufferPointer` instance, to\ndemonstrate the difference between assigning a buffer pointer and using a\nbuffer pointer as the source for another collection's elements. Here, the\nassignment to `destBytes` creates a new, nonowning buffer pointer\ncovering the first `n` bytes of the memory that `someBytes`\nreferences---nothing is copied:\n"
],
[
"discussion",
"``` \n var destBytes = someBytes[0..<n]\n```\n"
],
[
"discussion",
"Next, the bytes referenced by `destBytes` are copied into `byteArray`, a\nnew `[UInt]` array, and then the remainder of `someBytes` is appended to\n`byteArray`:\n"
],
[
"discussion",
"``` \n var byteArray: [UInt8] = Array(destBytes)\n byteArray += someBytes[n..<someBytes.count]\n```\n"
],
[
"seealso",
"`UnsafeRawPointer`, `UnsafeBufferPointer`"
]
]
},
{
"declaration" : {
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "next()",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"context" : "UnsafeRawBufferPointer.Iterator",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "UInt8?",
"input" : []
}
}
],
"name" : "Iterator",
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"inheritence" : [],
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeRawBufferPointer"
},
"documentation" : [
[
"summary",
"An iterator over the bytes viewed by a raw buffer pointer.\n"
]
]
},
{
"declaration" : {
"genericRequirements" : [],
"inheritence" : [],
"genericParameters" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "UnsafeRawPointer",
"methods" : [
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeRawPointer",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "bytes",
"attributes" : [],
"type" : "Int"
},
{
"name" : "alignedTo",
"type" : "Int",
"attributes" : []
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "deallocate(bytes:alignedTo:)"
},
{
"keyword" : "func",
"name" : "bindMemory(to:capacity:)",
"attributes" : [],
"signature" : {
"output" : "UnsafePointer<T>",
"input" : [
{
"name" : "to",
"attributes" : [],
"type" : "T.Type"
},
{
"name" : "capacity",
"type" : "Int",
"attributes" : []
}
]
},
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [],
"context" : "UnsafeRawPointer",
"modifiers" : [
{
"name" : "public"
}
]
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeRawPointer",
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [],
"signature" : {
"output" : "UnsafePointer<T>",
"input" : [
{
"attributes" : [],
"type" : "T.Type",
"name" : "to"
}
]
},
"attributes" : [],
"keyword" : "func",
"name" : "assumingMemoryBound(to:)"
},
{
"modifiers" : [
{
"name" : "public"
}
],
"context" : "UnsafeRawPointer",
"genericRequirements" : [],
"genericParameters" : [],
"signature" : {
"output" : "Int",
"input" : [
{
"type" : "UnsafeRawPointer",
"attributes" : [],
"name" : "to"
}
]
},
"attributes" : [],
"name" : "distance(to:)",
"keyword" : "func"
},
{
"name" : "advanced(by:)",
"keyword" : "func",
"attributes" : [],
"signature" : {
"input" : [
{
"type" : "Int",
"attributes" : [],
"name" : "by"
}
],
"output" : "UnsafeRawPointer"
},
"genericRequirements" : [],
"genericParameters" : [],
"context" : "UnsafeRawPointer",
"modifiers" : [
{
"name" : "public"
}
]
}
],
"keyword" : "struct",
"attributes" : []
},
"documentation" : [
[
"summary",
"A raw pointer for accessing\nuntyped data.\n"
],
[
"discussion",
"The `UnsafeRawPointer` type provides no automated memory management, no type safety,\nand no alignment guarantees. You are responsible for handling the life\ncycle of any memory you work with through unsafe pointers, to avoid leaks\nor undefined behavior.\n"
],
[
"discussion",
"Memory that you manually manage can be either *untyped* or *bound* to a\nspecific type. You use the `UnsafeRawPointer` type to access and\nmanage raw bytes in memory, whether or not that memory has been bound to a\nspecific type.\n"
],
[
"discussion",
"# Understanding a Pointer's Memory State\n"
],
[
"discussion",
"The memory referenced by an `UnsafeRawPointer` instance can be in one of several\nstates. Many pointer operations must only be applied to pointers with\nmemory in a specific state---you must keep track of the state of the\nmemory you are working with and understand the changes to that state that\ndifferent operations perform. Memory can be untyped and uninitialized,\nbound to a type and uninitialized, or bound to a type and initialized to a\nvalue. Finally, memory that was allocated previously may have been\ndeallocated, leaving existing pointers referencing unallocated memory.\n"
],
[
"discussion",
"## Raw, Uninitialized Memory\n"
],
[
"discussion",
"Raw memory that has just been allocated is in an *uninitialized, untyped*\nstate. Uninitialized memory must be initialized with values of a type\nbefore it can be used with any typed operations.\n"
],
[
"discussion",
"To bind uninitialized memory to a type without initializing it, use the\n`bindMemory(to:count:)` method. This method returns a typed pointer\nfor further typed access to the memory.\n"
],
[
"discussion",
"## Typed Memory\n"
],
[
"discussion",
"Memory that has been bound to a type, whether it is initialized or\nuninitialized, is typically accessed using typed pointers---instances of\n`UnsafePointer` and `UnsafeMutablePointer`. Initialization, assignment,\nand deinitialization can be performed using `UnsafeMutablePointer`\nmethods.\n"
],
[
"discussion",
"Memory that has been bound to a type can be rebound to a different type\nonly after it has been deinitialized or if the bound type is a *trivial\ntype*. Deinitializing typed memory does not unbind that memory's type. The\ndeinitialized memory can be reinitialized with values of the same type,\nbound to a new type, or deallocated.\n"
],
[
"note",
"A trivial type can be copied bit for bit with no indirection or\nreference-counting operations. Generally, native Swift types that do not\ncontain strong or weak references or other forms of indirection are\ntrivial, as are imported C structs and enumerations."
],
[
"discussion",
"When reading from memory as raw\nbytes when that memory is bound to a type, you must ensure that you\nsatisfy any alignment requirements.\n"
],
[
"discussion",
"# Raw Pointer Arithmetic\n"
],
[
"discussion",
"Pointer arithmetic with raw pointers is performed at the byte level. When\nyou add to or subtract from a raw pointer, the result is a new raw pointer\noffset by that number of bytes. The following example allocates four bytes\nof memory and stores `0xFF` in all four bytes:\n"
],
[
"discussion",
"``` \n let bytesPointer = UnsafeMutableRawPointer.allocate(bytes: 4, alignedTo: 1)\n bytesPointer.storeBytes(of: 0xFFFF_FFFF, as: UInt32.self)\n\n // Load a value from the memory referenced by 'bytesPointer'\n let x = bytesPointer.load(as: UInt8.self) // 255\n\n // Load a value from the last two allocated bytes\n let offsetPointer = bytesPointer + 2\n let y = offsetPointer.load(as: UInt16.self) // 65535\n```\n"
],
[
"discussion",
"The code above stores the value `0xFFFF_FFFF` into the four newly allocated\nbytes, and then loads the first byte as a `UInt8` instance and the third\nand fourth bytes as a `UInt16` instance.\n"
],
[
"discussion",
"Always remember to deallocate any memory that you allocate yourself.\n"
],
[
"discussion",
"``` \n bytesPointer.deallocate(bytes: 4, alignedTo: 1)\n```\n"
],
[
"discussion",
"# Implicit Casting and Bridging\n"
],
[
"discussion",
"When calling a function or method with an `UnsafeRawPointer` parameter, you can pass\nan instance of that specific pointer type, pass an instance of a\ncompatible pointer type, or use Swift's implicit bridging to pass a\ncompatible pointer.\n"
],
[
"discussion",
"For example, the `print(address:as:)` function in the following code sample\ntakes an `UnsafeRawPointer` instance as its first parameter:\n"
],
[
"discussion",
"``` \n func print<T>(address p: UnsafeRawPointer, as type: T.Type) {\n let value = p.load(as: type)\n print(value)\n }\n```\n"
],
[
"discussion",
"As is typical in Swift, you can call the `print(address:as:)` function with\nan `UnsafeRawPointer` instance. This example passes `rawPointer` as the initial\nparameter.\n"
],
[
"discussion",
"``` \n // 'rawPointer' points to memory initialized with `Int` values.\n let rawPointer: UnsafeRawPointer = ...\n print(address: rawPointer, as: Int.self)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"Because typed pointers can be implicitly cast to raw pointers when passed\nas a parameter, you can also call `print(address:as:)` with any mutable or\nimmutable typed pointer instance.\n"
],
[
"discussion",
"``` \n let intPointer: UnsafePointer<Int> = ...\n print(address: intPointer, as: Int.self)\n // Prints \"42\"\n\n let mutableIntPointer = UnsafeMutablePointer(mutating: intPointer)\n print(address: mutableIntPointer, as: Int.self)\n // Prints \"42\"\n```\n"
],
[
"discussion",
"Alternatively, you can use Swift's *implicit bridging* to pass a pointer to\nan instance or to the elements of an array. Use inout syntax to implicitly\ncreate a pointer to an instance of any type. The following example uses\nimplicit bridging to pass a pointer to `value` when calling\n`print(address:as:)`:\n"
],
[
"discussion",
"``` \n var value: Int = 23\n print(address: &value, as: Int.self)\n // Prints \"23\"\n```\n"
],
[
"discussion",
"An immutable pointer to the elements of an array is implicitly created when\nyou pass the array as an argument. This example uses implicit bridging to\npass a pointer to the elements of `numbers` when calling\n`print(address:as:)`.\n"
],
[
"discussion",
"``` \n let numbers = [5, 10, 15, 20]\n print(address: numbers, as: Int.self)\n // Prints \"5\"\n```\n"
],
[
"discussion",
"You can also use inout syntax to pass a mutable pointer to the elements of\nan array. Because `print(address:as:)` requires an immutable pointer,\nalthough this is syntactically valid, it isn't necessary.\n"
],
[
"discussion",
"``` \n var mutableNumbers = numbers\n print(address: &mutableNumbers, as: Int.self)\n```\n"
],
[
"important",
"The pointer created through implicit bridging of an instance\nor of an array's elements is only valid during the execution of the\ncalled function. Escaping the pointer to use after the execution of the\nfunction is undefined behavior. In particular, do not use implicit\nbridging when calling an `UnsafeRawPointer` initializer.\n\n var number = 5\n let numberPointer = UnsafeRawPointer(&number)\n // Accessing 'numberPointer' is undefined behavior."
]
]
},
{
"documentation" : [
[
"summary",
"An iterator for `Zip2Sequence`.\n"
]
],
"declaration" : {
"genericRequirements" : [
"Iterator1 : IteratorProtocol, ",
"Iterator2 : IteratorProtocol "
],
"inheritence" : [],
"genericParameters" : [
{
"name" : "Iterator1",
"attributes" : []
},
{
"attributes" : [],
"name" : "Iterator2"
}
],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "Zip2Iterator",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "next()",
"context" : "Zip2Iterator",
"modifiers" : [
{
"name" : "public"
},
{
"name" : "mutating"
}
],
"signature" : {
"output" : "Zip2Iterator.Element?",
"input" : []
},
"genericParameters" : [],
"genericRequirements" : []
}
],
"keyword" : "struct",
"attributes" : []
}
},
{
"declaration" : {
"name" : "Zip2Sequence",
"methods" : [
{
"attributes" : [],
"keyword" : "func",
"name" : "makeIterator()",
"modifiers" : [
{
"name" : "public"
}
],
"context" : "Zip2Sequence",
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Zip2Sequence.Iterator",
"input" : []
}
}
],
"keyword" : "struct",
"attributes" : [],
"genericRequirements" : [
"Sequence1 : Sequence, ",
"Sequence2 : Sequence "
],
"inheritence" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "Sequence1"
},
{
"attributes" : [],
"name" : "Sequence2"
}
],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"A sequence of pairs built out of two underlying sequences.\n"
],
[
"discussion",
"In a `Zip2Sequence` instance, the elements of the *i*th pair are the *i*th\nelements of each underlying sequence. To create a `Zip2Sequence` instance,\nuse the `zip(_:_:)` function.\n"
],
[
"discussion",
"The following example uses the `zip(_:_:)` function to iterate over an\narray of strings and a countable range at the same time:\n"
],
[
"discussion",
"``` \n let words = [\"one\", \"two\", \"three\", \"four\"]\n let numbers = 1...4\n\n for (word, number) in zip(words, numbers) {\n print(\"\\(word): \\(number)\")\n }\n // Prints \"one: 1\"\n // Prints \"two: 2\n // Prints \"three: 3\"\n // Prints \"four: 4\"\n```\n"
],
[
"seealso",
"`zip(_:_:)`"
]
]
}
],
"variables" : [],
"functions" : [
{
"documentation" : [
[
"summary",
"Returns `true` if the arrays do not contain the same elements.\n"
]
],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "ArraySlice<Element>"
},
{
"name" : "rhs",
"type" : "ArraySlice<Element>",
"attributes" : []
}
],
"output" : "Bool "
},
"name" : "!=(lhs:rhs:)",
"genericParameters" : [
{
"name" : "Element",
"attributes" : []
}
],
"genericRequirements" : [
"Element : Equatable"
]
}
},
{
"declaration" : {
"genericRequirements" : [
"A : Equatable, ",
"B : Equatable"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "A"
},
{
"name" : "B",
"attributes" : []
}
],
"name" : "!=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "(A, B)"
},
{
"attributes" : [],
"type" : "(A, B)",
"name" : "rhs"
}
],
"output" : "Bool "
},
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether any corresponding components of\nthe two tuples are not equal.\n"
],
[
"discussion",
"For two tuples to compare as equal, each corresponding pair of components\nmust be equal. The following example compares tuples made up of 2\ncomponents:\n"
],
[
"discussion",
"``` \n let a = (\"a\", 1)\n let b = (\"a\", 1)\n print(a != b)\n // Prints \"false\"\n\n let c = (\"a\", 2)\n print(a != c)\n // Prints \"true\"\n```\n"
],
[
"parameters",
{
"rhs" : "Another tuple of elements of the same type as `lhs`.",
"lhs" : "A tuple of `Equatable` elements."
}
]
]
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "(A, B, C)",
"attributes" : []
},
{
"type" : "(A, B, C)",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "Bool "
},
"keyword" : "func",
"name" : "!=(lhs:rhs:)",
"genericParameters" : [
{
"name" : "A",
"attributes" : []
},
{
"name" : "B",
"attributes" : []
},
{
"name" : "C",
"attributes" : []
}
],
"genericRequirements" : [
"A : Equatable, ",
"B : Equatable, ",
"C : Equatable"
]
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether any corresponding components of\nthe two tuples are not equal.\n"
],
[
"discussion",
"For two tuples to compare as equal, each corresponding pair of components\nmust be equal. The following example compares tuples made up of 3\ncomponents:\n"
],
[
"discussion",
"``` \n let a = (\"a\", 1, 2)\n let b = (\"a\", 1, 2)\n print(a != b)\n // Prints \"false\"\n\n let c = (\"a\", 1, 3)\n print(a != c)\n // Prints \"true\"\n```\n"
],
[
"parameters",
{
"lhs" : "A tuple of `Equatable` elements.",
"rhs" : "Another tuple of elements of the same type as `lhs`."
}
]
]
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Bool ",
"input" : [
{
"name" : "lhs",
"type" : "(A, B, C, D)",
"attributes" : []
},
{
"type" : "(A, B, C, D)",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "!=(lhs:rhs:)",
"genericParameters" : [
{
"attributes" : [],
"name" : "A"
},
{
"attributes" : [],
"name" : "B"
},
{
"attributes" : [],
"name" : "C"
},
{
"attributes" : [],
"name" : "D"
}
],
"genericRequirements" : [
"A : Equatable, ",
"B : Equatable, ",
"C : Equatable, ",
"D : Equatable"
]
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether any corresponding components of\nthe two tuples are not equal.\n"
],
[
"discussion",
"For two tuples to compare as equal, each corresponding pair of components\nmust be equal. The following example compares tuples made up of 4\ncomponents:\n"
],
[
"discussion",
"``` \n let a = (\"a\", 1, 2, 3)\n let b = (\"a\", 1, 2, 3)\n print(a != b)\n // Prints \"false\"\n\n let c = (\"a\", 1, 2, 4)\n print(a != c)\n // Prints \"true\"\n```\n"
],
[
"parameters",
{
"lhs" : "A tuple of `Equatable` elements.",
"rhs" : "Another tuple of elements of the same type as `lhs`."
}
]
]
},
{
"declaration" : {
"genericRequirements" : [
"Element : Equatable"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"name" : "!=(lhs:rhs:)",
"signature" : {
"output" : "Bool ",
"input" : [
{
"attributes" : [],
"type" : "ContiguousArray<Element>",
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "ContiguousArray<Element>",
"attributes" : []
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Returns `true` if the arrays do not contain the same elements.\n"
]
]
},
{
"declaration" : {
"genericRequirements" : [
"Element : Equatable"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "Element"
}
],
"name" : "!=(lhs:rhs:)",
"signature" : {
"output" : "Bool ",
"input" : [
{
"name" : "lhs",
"type" : "[Element]",
"attributes" : []
},
{
"type" : "[Element]",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Returns `true` if the arrays do not contain the same elements.\n"
]
]
},
{
"documentation" : [
[
"summary",
"Returns `false` iff `t0` is identical to `t1`; i.e. if they are both\n`nil` or they both represent the same type.\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "!=(t0:t1:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "t0",
"type" : "Any.Type?",
"attributes" : []
},
{
"attributes" : [],
"type" : "Any.Type?",
"name" : "t1"
}
],
"output" : "Bool"
}
}
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether the right-hand-side argument is\nnot `nil`.\n"
],
[
"discussion",
"You can use this not-equal-to operator (`!=`) to test whether an optional\ninstance is not `nil` even when the wrapped value's type does not conform\nto the `Equatable` protocol.\n"
],
[
"discussion",
"The following example declares the `stream` variable as an optional\ninstance of a hypothetical `DataStream` type. Although `DataStream` is not\nan `Equatable` type, this operator allows checking whether `stream` wraps\na value and is therefore not `nil`.\n"
],
[
"discussion",
"``` \n var stream: DataStream? = fetchDataStream()\n if nil != stream {\n print(\"The data stream has been configured.\")\n }\n // Prints \"The data stream has been configured.\"\n```\n"
],
[
"parameters",
{
"lhs" : "A `nil` literal.",
"rhs" : "A value to compare to `nil`."
}
]
],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"name" : "!=(lhs:rhs:)",
"signature" : {
"input" : [
{
"type" : "_OptionalNilComparisonType",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "T?",
"attributes" : []
}
],
"output" : "Bool"
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : RawRepresentable, ",
"T.RawValue : Equatable"
],
"signature" : {
"output" : "Bool ",
"input" : [
{
"type" : "T",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "!=(lhs:rhs:)"
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether the two arguments are not equal.\n"
],
[
"parameters",
{
"lhs" : "A raw-representable instance.",
"rhs" : "A second raw-representable instance."
}
]
]
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "!=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "Bool ",
"input" : [
{
"attributes" : [],
"type" : "T",
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "T"
}
]
},
"genericRequirements" : [
"T : Equatable, ",
"T : RawRepresentable, ",
"T.RawValue : Equatable"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
]
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether the two arguments are not equal.\n"
],
[
"parameters",
{
"lhs" : "A raw-representable instance.",
"rhs" : "A second raw-representable instance."
}
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [
"T : Equatable"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"name" : "!=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "Bool ",
"input" : [
{
"name" : "lhs",
"type" : "T",
"attributes" : []
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
}
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether two values are not equal.\n"
],
[
"discussion",
"Inequality is the inverse of equality. For any values `a` and `b`, `a != b`\nimplies that `a == b` is `false`.\n"
],
[
"discussion",
"This is the default implementation of the not-equal-to operator (`!=`)\nfor any type that conforms to `Equatable`.\n"
],
[
"parameters",
{
"lhs" : "A value to compare.",
"rhs" : "Another value to compare."
}
]
]
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "UInt8"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "UInt8"
}
],
"output" : "Bool"
},
"name" : "!=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether the left-hand-side argument is\nnot `nil`.\n"
],
[
"discussion",
"You can use this not-equal-to operator (`!=`) to test whether an optional\ninstance is not `nil` even when the wrapped value's type does not conform\nto the `Equatable` protocol.\n"
],
[
"discussion",
"The following example declares the `stream` variable as an optional\ninstance of a hypothetical `DataStream` type. Although `DataStream` is not\nan `Equatable` type, this operator allows checking whether `stream` wraps\na value and is therefore not `nil`.\n"
],
[
"discussion",
"``` \n var stream: DataStream? = fetchDataStream()\n if stream != nil {\n print(\"The data stream has been configured.\")\n }\n // Prints \"The data stream has been configured.\"\n```\n"
],
[
"parameters",
{
"lhs" : "A value to compare to `nil`.",
"rhs" : "A `nil` literal."
}
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"name" : "!=(lhs:rhs:)",
"signature" : {
"output" : "Bool",
"input" : [
{
"name" : "lhs",
"type" : "T?",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "_OptionalNilComparisonType"
}
]
},
"keyword" : "func"
}
},
{
"declaration" : {
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : Equatable"
],
"signature" : {
"output" : "Bool ",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "T?"
},
{
"type" : "T?",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "!=(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether two optional instances are not\nequal.\n"
],
[
"discussion",
"Use this not-equal-to operator (`!=`) to compare any two optional instances\nof a type that conforms to the `Equatable` protocol. The comparison\nreturns `true` if only one of the arguments is `nil` or if the two\narguments wrap values that are not equal. The comparison returns `false`\nif both arguments are `nil` or if the two arguments wrap values that are\nequal.\n"
],
[
"discussion",
"``` \n let group1 = [2, 4, 6, 8, 10]\n let group2 = [1, 3, 5, 7, 9]\n if group1.first != group2.first {\n print(\"The two groups start differently.\")\n }\n // Prints \"The two groups start differently.\"\n```\n"
],
[
"discussion",
"You can also use this operator to compare a non-optional value to an\noptional that wraps the same type. The non-optional value is wrapped as an\noptional before the comparison is made. In this example, the\n`numberToMatch` constant is wrapped as an optional before comparing to the\noptional `numberFromString`:\n"
],
[
"discussion",
"``` \n let numberToFind: Int = 23\n let numberFromString: Int? = Int(\"not-a-number\") // nil\n if numberToFind != numberFromString {\n print(\"No match.\")\n }\n // Prints \"No match.\"\n```\n"
],
[
"parameters",
{
"lhs" : "An optional value to compare.",
"rhs" : "Another optional value to compare."
}
]
]
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"signature" : {
"output" : "Bool ",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "T"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
},
"name" : "!=(lhs:rhs:)",
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"genericRequirements" : [
"T : BinaryInteger"
]
}
},
{
"declaration" : {
"name" : "!=(lhs:rhs:)",
"signature" : {
"input" : [
{
"type" : "Int8",
"attributes" : [],
"name" : "lhs"
},
{
"attributes" : [],
"type" : "Int8",
"name" : "rhs"
}
],
"output" : "Bool"
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
]
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "!=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "Bool",
"input" : [
{
"attributes" : [],
"type" : "UInt16",
"name" : "lhs"
},
{
"type" : "UInt16",
"attributes" : [],
"name" : "rhs"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "!=(lhs:rhs:)",
"signature" : {
"output" : "Bool",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int16"
},
{
"name" : "rhs",
"type" : "Int16",
"attributes" : []
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"declaration" : {
"name" : "!=(lhs:rhs:)",
"signature" : {
"output" : "Bool ",
"input" : [
{
"type" : "T",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "U",
"attributes" : []
}
]
},
"keyword" : "func",
"genericRequirements" : [
"T : BinaryInteger, ",
"U : BinaryInteger"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
},
{
"attributes" : [],
"name" : "U"
}
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "!=(lhs:rhs:)",
"signature" : {
"output" : "Bool",
"input" : [
{
"attributes" : [],
"type" : "UInt32",
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "UInt32"
}
]
},
"keyword" : "func"
},
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
]
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
"output" : "Bool",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int"
}
]
},
"name" : "!=(lhs:rhs:)"
}
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int32"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int32"
}
],
"output" : "Bool"
},
"name" : "!=(lhs:rhs:)"
}
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether any corresponding components of\nthe two tuples are not equal.\n"
],
[
"discussion",
"For two tuples to compare as equal, each corresponding pair of components\nmust be equal. The following example compares tuples made up of 5\ncomponents:\n"
],
[
"discussion",
"``` \n let a = (\"a\", 1, 2, 3, 4)\n let b = (\"a\", 1, 2, 3, 4)\n print(a != b)\n // Prints \"false\"\n\n let c = (\"a\", 1, 2, 3, 5)\n print(a != c)\n // Prints \"true\"\n```\n"
],
[
"parameters",
{
"lhs" : "A tuple of `Equatable` elements.",
"rhs" : "Another tuple of elements of the same type as `lhs`."
}
]
],
"declaration" : {
"genericRequirements" : [
"A : Equatable, ",
"B : Equatable, ",
"C : Equatable, ",
"D : Equatable, ",
"E : Equatable"
],
"genericParameters" : [
{
"name" : "A",
"attributes" : []
},
{
"attributes" : [],
"name" : "B"
},
{
"attributes" : [],
"name" : "C"
},
{
"attributes" : [],
"name" : "D"
},
{
"name" : "E",
"attributes" : []
}
],
"name" : "!=(lhs:rhs:)",
"signature" : {
"output" : "Bool ",
"input" : [
{
"name" : "lhs",
"type" : "(A, B, C, D, E)",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "(A, B, C, D, E)"
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether any corresponding components of\nthe two tuples are not equal.\n"
],
[
"discussion",
"For two tuples to compare as equal, each corresponding pair of components\nmust be equal. The following example compares tuples made up of 6\ncomponents:\n"
],
[
"discussion",
"``` \n let a = (\"a\", 1, 2, 3, 4, 5)\n let b = (\"a\", 1, 2, 3, 4, 5)\n print(a != b)\n // Prints \"false\"\n\n let c = (\"a\", 1, 2, 3, 4, 6)\n print(a != c)\n // Prints \"true\"\n```\n"
],
[
"parameters",
{
"lhs" : "A tuple of `Equatable` elements.",
"rhs" : "Another tuple of elements of the same type as `lhs`."
}
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "A"
},
{
"attributes" : [],
"name" : "B"
},
{
"name" : "C",
"attributes" : []
},
{
"attributes" : [],
"name" : "D"
},
{
"name" : "E",
"attributes" : []
},
{
"name" : "F",
"attributes" : []
}
],
"genericRequirements" : [
"A : Equatable, ",
"B : Equatable, ",
"C : Equatable, ",
"D : Equatable, ",
"E : Equatable, ",
"F : Equatable"
],
"signature" : {
"input" : [
{
"type" : "(A, B, C, D, E, F)",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "(A, B, C, D, E, F)",
"attributes" : []
}
],
"output" : "Bool "
},
"keyword" : "func",
"name" : "!=(lhs:rhs:)"
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "!=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "Bool",
"input" : [
{
"name" : "lhs",
"type" : "UInt64",
"attributes" : []
},
{
"name" : "rhs",
"type" : "UInt64",
"attributes" : []
}
]
}
},
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
]
},
{
"declaration" : {
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int64",
"name" : "lhs"
},
{
"attributes" : [],
"type" : "Int64",
"name" : "rhs"
}
],
"output" : "Bool"
},
"keyword" : "func",
"name" : "!=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
]
},
{
"documentation" : [
[
"summary",
"Returns a Boolean value that indicates whether\nthe two arguments have unequal values.\n"
],
[
"seealso",
"`Equatable`, `Comparable`"
]
],
"declaration" : {
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "UInt"
},
{
"name" : "rhs",
"type" : "UInt",
"attributes" : []
}
],
"output" : "Bool"
},
"keyword" : "func",
"name" : "!=(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"declaration" : {
"signature" : {
"output" : "Bool",
"input" : [
{
"attributes" : [],
"type" : "AnyObject?",
"name" : "lhs"
},
{
"attributes" : [],
"type" : "AnyObject?",
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "!==(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Returns a Boolean value indicating whether two references point to\ndifferent object instances.\n"
],
[
"discussion",
"This operator tests whether two instances have different identities, not\ndifferent values. For value inequality, see the not-equal-to operator\n(`!=`) and the `Equatable` protocol.\n"
],
[
"parameters",
{
"rhs" : "Another reference to compare.",
"lhs" : "A reference to compare."
}
],
[
"seealso",
"`Equatable`, `===`, `!=`"
]
]
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "%(lhs:rhs:)",
"signature" : {
"output" : "Int",
"input" : [
{
"name" : "lhs",
"type" : "Int",
"attributes" : []
},
{
"attributes" : [],
"type" : "Int",
"name" : "rhs"
}
]
},
"keyword" : "func"
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "%(lhs:rhs:)",
"signature" : {
"input" : [
{
"type" : "UInt",
"attributes" : [],
"name" : "lhs"
},
{
"attributes" : [],
"type" : "UInt",
"name" : "rhs"
}
],
"output" : "UInt"
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : []
}
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "%(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int64"
},
{
"type" : "Int64",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "Int64"
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : []
}
},
{
"declaration" : {
"name" : "%(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "UInt64",
"input" : [
{
"name" : "lhs",
"type" : "UInt64",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "UInt64"
}
]
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "%(lhs:rhs:)",
"signature" : {
"output" : "Int32",
"input" : [
{
"attributes" : [],
"type" : "Int32",
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int32"
}
]
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : []
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "%(lhs:rhs:)",
"signature" : {
"input" : [
{
"type" : "UInt32",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "UInt32"
}
],
"output" : "UInt32"
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "%(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "Int16",
"input" : [
{
"name" : "lhs",
"type" : "Int16",
"attributes" : []
},
{
"name" : "rhs",
"type" : "Int16",
"attributes" : []
}
]
}
}
},
{
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "%(lhs:rhs:)",
"signature" : {
"input" : [
{
"type" : "UInt16",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "UInt16",
"attributes" : []
}
],
"output" : "UInt16"
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : []
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [
"T : _IntegerArithmetic"
],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"name" : "%(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "T"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "T "
}
},
"documentation" : [
[
"summary",
"Divides `lhs` and `rhs`, returning the remainder and trapping in case of\narithmetic overflow (except in -Ounchecked builds).\n"
]
]
},
{
"declaration" : {
"signature" : {
"output" : "Int8",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int8"
},
{
"attributes" : [],
"type" : "Int8",
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "%(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"declaration" : {
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
"output" : "UInt8",
"input" : [
{
"type" : "UInt8",
"attributes" : [],
"name" : "lhs"
},
{
"attributes" : [],
"type" : "UInt8",
"name" : "rhs"
}
]
},
"name" : "%(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "T",
"attributes" : []
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "T "
},
"name" : "%(lhs:rhs:)",
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"genericRequirements" : [
"T : BinaryInteger"
]
}
},
{
"documentation" : [],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [
"T : BinaryInteger"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"name" : "%=(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "inout T"
},
{
"attributes" : [],
"type" : "T",
"name" : "rhs"
}
]
},
"keyword" : "func"
}
},
{
"documentation" : [
[
"summary",
"Divides `lhs` and `rhs` and stores the remainder in `lhs`, trapping in\ncase of arithmetic overflow (except in -Ounchecked builds).\n"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [
"T : _IntegerArithmetic"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"name" : "%=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout T",
"name" : "lhs"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
}
}
},
{
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Int16",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int16"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int16"
}
]
},
"keyword" : "func",
"name" : "&(lhs:rhs:)"
}
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "&(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "T",
"attributes" : []
},
{
"name" : "rhs",
"type" : "T",
"attributes" : []
}
],
"output" : "T "
},
"keyword" : "func",
"genericRequirements" : [
"T : FixedWidthInteger"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
]
}
},
{
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"name" : "&(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "Int32",
"attributes" : []
},
{
"type" : "Int32",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "Int32"
},
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "&(lhs:rhs:)",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "UInt64",
"name" : "lhs"
},
{
"attributes" : [],
"type" : "UInt64",
"name" : "rhs"
}
],
"output" : "UInt64"
},
"keyword" : "func"
}
},
{
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "Int64",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int64"
}
],
"output" : "Int64"
},
"name" : "&(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "&(lhs:rhs:)",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "UInt",
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "UInt",
"attributes" : []
}
],
"output" : "UInt"
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int",
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "Int",
"attributes" : []
}
],
"output" : "Int"
},
"keyword" : "func",
"name" : "&(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "&(lhs:rhs:)",
"signature" : {
"output" : "UInt16",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "UInt16"
},
{
"type" : "UInt16",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "&(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "Int8",
"attributes" : []
},
{
"name" : "rhs",
"type" : "Int8",
"attributes" : []
}
],
"output" : "Int8"
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : []
},
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"declaration" : {
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "UInt8",
"input" : [
{
"name" : "lhs",
"type" : "UInt8",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "UInt8"
}
]
},
"keyword" : "func",
"name" : "&(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"documentation" : [
[
"summary",
"Returns the intersection of bits set in the two arguments.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "&(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "UInt32",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "UInt32"
}
],
"output" : "UInt32"
}
}
},
{
"documentation" : [
[
"summary",
"Multiplies `lhs` and `rhs`, silently discarding any overflow.\n"
]
],
"declaration" : {
"name" : "&*(lhs:rhs:)",
"signature" : {
"output" : "T ",
"input" : [
{
"attributes" : [],
"type" : "T",
"name" : "lhs"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"genericRequirements" : [
"T : _IntegerArithmetic"
],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : FixedWidthInteger"
],
"signature" : {
"input" : [
{
"type" : "T",
"attributes" : [],
"name" : "lhs"
},
{
"attributes" : [],
"type" : "T",
"name" : "rhs"
}
],
"output" : "T "
},
"keyword" : "func",
"name" : "&*(lhs:rhs:)"
},
"documentation" : []
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "&+(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "T",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "T"
}
],
"output" : "T "
},
"keyword" : "func",
"genericRequirements" : [
"T : _IntegerArithmetic"
],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
]
},
"documentation" : [
[
"summary",
"Adds `lhs` and `rhs`, silently discarding any overflow.\n"
]
]
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "T ",
"input" : [
{
"type" : "T",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "T"
}
]
},
"keyword" : "func",
"name" : "&+(lhs:rhs:)",
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"genericRequirements" : [
"T : FixedWidthInteger"
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [
"T : _IntegerArithmetic"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"name" : "&-(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "T ",
"input" : [
{
"attributes" : [],
"type" : "T",
"name" : "lhs"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
}
},
"documentation" : [
[
"summary",
"Subtracts `lhs` and `rhs`, silently discarding any overflow.\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "&-(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "T",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "T",
"attributes" : []
}
],
"output" : "T "
},
"genericRequirements" : [
"T : FixedWidthInteger"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
]
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "&<<(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "T"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "T "
},
"genericRequirements" : [
"T : FixedWidthInteger"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
]
}
},
{
"declaration" : {
"genericRequirements" : [
"T : FixedWidthInteger, ",
"U : BinaryInteger"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
},
{
"name" : "U",
"attributes" : []
}
],
"name" : "&<<(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"output" : "T ",
"input" : [
{
"type" : "T",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "U",
"attributes" : [],
"name" : "rhs"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : []
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"genericRequirements" : [
"T : FixedWidthInteger"
],
"keyword" : "func",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout T",
"name" : "lhs"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
},
"name" : "&<<=(lhs:rhs:)"
},
"documentation" : []
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
},
{
"name" : "U",
"attributes" : []
}
],
"genericRequirements" : [
"T : FixedWidthInteger, ",
"U : BinaryInteger"
],
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "inout T",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "U",
"attributes" : [],
"name" : "rhs"
}
]
},
"name" : "&<<=(lhs:rhs:)"
},
"documentation" : []
},
{
"declaration" : {
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout T",
"attributes" : []
},
{
"attributes" : [],
"type" : "T",
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "&=(lhs:rhs:)",
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"genericRequirements" : [
"T : FixedWidthInteger"
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"declaration" : {
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "inout Int",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "Int",
"attributes" : [],
"name" : "rhs"
}
]
},
"name" : "&=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "inout UInt",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "UInt"
}
]
},
"name" : "&=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "inout Int64"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int64"
}
]
},
"keyword" : "func",
"name" : "&=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"type" : "inout UInt64",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "UInt64",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "&=(lhs:rhs:)"
},
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"declaration" : {
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout Int32",
"attributes" : []
},
{
"attributes" : [],
"type" : "Int32",
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "&=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"declaration" : {
"name" : "&=(lhs:rhs:)",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout UInt32",
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "UInt32",
"attributes" : []
}
]
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "&=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Int16",
"name" : "lhs"
},
{
"attributes" : [],
"type" : "Int16",
"name" : "rhs"
}
]
},
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "&=(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout UInt16",
"attributes" : []
},
{
"attributes" : [],
"type" : "UInt16",
"name" : "rhs"
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
]
},
{
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "&=(lhs:rhs:)",
"signature" : {
"input" : [
{
"type" : "inout Int8",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "Int8",
"attributes" : []
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"Calculates the intersection of bits set in the two arguments\nand stores the result in the first argument.\n"
],
[
"seealso",
"`BitwiseOperations`"
]
],
"declaration" : {
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout UInt8",
"attributes" : []
},
{
"name" : "rhs",
"type" : "UInt8",
"attributes" : []
}
]
},
"name" : "&=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [
[
"summary",
"Calculates the intersections of bits sets in the two arguments and stores\nthe result in the first argument.\n"
],
[
"parameters",
{
"rhs" : "Another value.",
"lhs" : "A value to update with the intersections of bits set in the two"
}
]
],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [
"T : BitwiseOperations"
],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"name" : "&=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout T",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "T"
}
]
}
}
},
{
"declaration" : {
"name" : "&>>(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "T"
},
{
"type" : "U",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "T "
},
"genericRequirements" : [
"T : FixedWidthInteger, ",
"U : BinaryInteger"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
},
{
"attributes" : [],
"name" : "U"
}
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "T ",
"input" : [
{
"type" : "T",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "T"
}
]
},
"keyword" : "func",
"name" : "&>>(lhs:rhs:)",
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : FixedWidthInteger"
]
}
},
{
"documentation" : [],
"declaration" : {
"name" : "&>>=(lhs:rhs:)",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout T",
"name" : "lhs"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "T"
}
]
},
"keyword" : "func",
"genericRequirements" : [
"T : FixedWidthInteger"
],
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout T",
"attributes" : []
},
{
"name" : "rhs",
"type" : "U",
"attributes" : []
}
]
},
"name" : "&>>=(lhs:rhs:)",
"genericParameters" : [
{
"name" : "T",
"attributes" : []
},
{
"attributes" : [],
"name" : "U"
}
],
"genericRequirements" : [
"T : FixedWidthInteger, ",
"U : BinaryInteger"
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "*(lhs:rhs:)",
"signature" : {
"output" : "Float80",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Float80"
},
{
"type" : "Float80",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : []
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "Int8",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "Int8",
"attributes" : []
}
],
"output" : "Int8"
},
"name" : "*(lhs:rhs:)"
}
},
{
"documentation" : [],
"declaration" : {
"signature" : {
"output" : "UInt8",
"input" : [
{
"attributes" : [],
"type" : "UInt8",
"name" : "lhs"
},
{
"attributes" : [],
"type" : "UInt8",
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "*(lhs:rhs:)",
"signature" : {
"output" : "UInt16",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "UInt16"
},
{
"type" : "UInt16",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func"
},
"documentation" : []
},
{
"declaration" : {
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"output" : "Int16",
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int16"
},
{
"type" : "Int16",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "*(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "UInt32",
"attributes" : [],
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "UInt32",
"attributes" : []
}
],
"output" : "UInt32"
},
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [],
"declaration" : {
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int32"
},
{
"type" : "Int32",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "Int32"
},
"name" : "*(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "UInt64",
"input" : [
{
"attributes" : [],
"type" : "UInt64",
"name" : "lhs"
},
{
"type" : "UInt64",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "Int64",
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "Int64",
"attributes" : []
}
],
"output" : "Int64"
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
"output" : "UInt",
"input" : [
{
"name" : "lhs",
"type" : "UInt",
"attributes" : []
},
{
"attributes" : [],
"type" : "UInt",
"name" : "rhs"
}
]
},
"name" : "*(lhs:rhs:)"
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "Int"
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int"
}
],
"output" : "Int"
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "T"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
],
"output" : "T "
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [
{
"name" : "T",
"attributes" : []
}
],
"genericRequirements" : [
"T : FloatingPoint"
]
}
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"output" : "Float",
"input" : [
{
"type" : "Float",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "Float",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"documentation" : [],
"declaration" : {
"genericRequirements" : [],
"genericParameters" : [],
"name" : "*(lhs:rhs:)",
"signature" : {
"output" : "Double",
"input" : [
{
"name" : "lhs",
"type" : "Double",
"attributes" : []
},
{
"name" : "rhs",
"type" : "Double",
"attributes" : []
}
]
},
"keyword" : "func",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [
[
"summary",
"Multiplies `lhs` and `rhs`, returning the result and trapping in case of\narithmetic overflow (except in -Ounchecked builds).\n"
]
],
"declaration" : {
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "T",
"name" : "lhs"
},
{
"attributes" : [],
"type" : "T",
"name" : "rhs"
}
],
"output" : "T "
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : _IntegerArithmetic"
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
}
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "T",
"attributes" : []
},
{
"attributes" : [],
"type" : "T",
"name" : "rhs"
}
],
"output" : "T "
},
"keyword" : "func",
"name" : "*(lhs:rhs:)",
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : Arithmetic"
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "*=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout UInt",
"name" : "lhs"
},
{
"attributes" : [],
"type" : "UInt",
"name" : "rhs"
}
]
}
},
"documentation" : []
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericRequirements" : [],
"genericParameters" : [],
"name" : "*=(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "inout UInt64"
},
{
"attributes" : [],
"type" : "UInt64",
"name" : "rhs"
}
]
},
"keyword" : "func"
},
"documentation" : []
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "*=(lhs:rhs:)",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "inout T"
},
{
"name" : "rhs",
"type" : "T",
"attributes" : []
}
]
},
"keyword" : "func",
"genericRequirements" : [
"T : Arithmetic"
],
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
]
},
"documentation" : []
},
{
"declaration" : {
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "inout T",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "T",
"attributes" : [],
"name" : "rhs"
}
]
},
"name" : "*=(lhs:rhs:)",
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : _IntegerArithmetic"
],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : [
[
"summary",
"Multiplies `lhs` and `rhs` and stores the result in `lhs`, trapping in\ncase of arithmetic overflow (except in -Ounchecked builds).\n"
]
]
},
{
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"signature" : {
"input" : [
{
"type" : "inout Float80",
"attributes" : [],
"name" : "lhs"
},
{
"type" : "Float80",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"name" : "*=(lhs:rhs:)",
"keyword" : "func",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Double",
"name" : "lhs"
},
{
"name" : "rhs",
"type" : "Double",
"attributes" : []
}
]
},
"genericRequirements" : [],
"genericParameters" : []
}
},
{
"declaration" : {
"name" : "*=(lhs:rhs:)",
"signature" : {
"input" : [
{
"attributes" : [],
"type" : "inout Float",
"name" : "lhs"
},
{
"type" : "Float",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"genericRequirements" : [],
"genericParameters" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "inout T"
},
{
"attributes" : [],
"type" : "T",
"name" : "rhs"
}
]
},
"name" : "*=(lhs:rhs:)",
"genericParameters" : [
{
"attributes" : [],
"name" : "T"
}
],
"genericRequirements" : [
"T : FloatingPoint"
]
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
"input" : [
{
"type" : "inout Int",
"attributes" : [],
"name" : "lhs"
},
{
"attributes" : [],
"type" : "Int",
"name" : "rhs"
}
]
},
"name" : "*=(lhs:rhs:)"
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "lhs",
"attributes" : [],
"type" : "inout Int64"
},
{
"type" : "Int64",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*=(lhs:rhs:)",
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : []
}
},
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
],
"keyword" : "func",
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout Int32",
"attributes" : []
},
{
"name" : "rhs",
"attributes" : [],
"type" : "Int32"
}
]
},
"name" : "*=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : []
}
},
{
"declaration" : {
"modifiers" : [
{
"name" : "public"
}
],
"attributes" : [],
"genericParameters" : [],
"genericRequirements" : [],
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout UInt32",
"attributes" : []
},
{
"type" : "UInt32",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*=(lhs:rhs:)"
},
"documentation" : []
},
{
"declaration" : {
"signature" : {
"input" : [
{
"name" : "lhs",
"type" : "inout Int16",
"attributes" : []
},
{
"type" : "Int16",
"attributes" : [],
"name" : "rhs"
}
]
},
"keyword" : "func",
"name" : "*=(lhs:rhs:)",
"genericParameters" : [],
"genericRequirements" : [],
"attributes" : [],
"modifiers" : [
{
"name" : "public"
}
]
},
"documentation" : []
},
{
"documentation" : [],
"declaration" : {
"genericParameters" : [],
"genericRequirements" : [],
"keyword" : "func",
"signature" : {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment