StructDeclSyntax
io.joern.swiftsrc2cpg.parser.SwiftNodeSyntax.StructDeclSyntax
case class StructDeclSyntax(json: Value) extends DeclSyntax, DeclGroup, NamedDecl, WithAttributes, WithGenericParameters, WithModifiers
Documentation
A struct
declaration
An example of a struct declaration is
struct SomeStruct {
let someMember: String
var anotherMember: Int
func foo() {
print(someMember)
}
mutating func bar() {
anotherMember = 42
}
}
A struct declaration may be declared without any members.
struct EmptyStruct {
}
A struct declaration may include a type inheritance clause listing one or more protocols the struct conforms to.
The example below uses Hashable and Equatable protocols whose members are automatically synthesized by the compiler if the struct contains stored members that are themselves Hashable
and Equatable
.
struct AdvancedStruct: Hashable, Equatable {
let someMember: String
var anotherMember: Int
}
A struct declaration may include a generic parameter clause as well as a generic where clause.
struct Stack<Element> {
var items: [Element] = []
mutating func push(_ item: Element) {
items.append(item)
}
mutating func pop() -> Element {
return items.removeLast()
}
}
Children
attributes
:AttributeListSyntax
modifiers
:DeclModifierListSyntax
structKeyword
:struct
name
:<identifier>
genericParameterClause
:GenericParameterClauseSyntax
?inheritanceClause
:InheritanceClauseSyntax
?genericWhereClause
:GenericWhereClauseSyntax
?memberBlock
:MemberBlockSyntax
Nowhere contained in
Attributes
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait WithModifierstrait WithGenericParameterstrait WithAttributestrait NamedDecltrait DeclGrouptrait DeclSyntaxtrait SwiftNodeclass Objecttrait Matchableclass Any
Members list
In this article