Syntax

Swift Define a Struct Syntax

In Swift, define a struct: defines a value type — struct Point { var x: Double var y: Double }

Quick Answer

Syntax
struct Point { var x: Double var y: Double }
SwiftSyntax

Define a Struct

Code example
struct Point { var x: Double var y: Double }

Defines a value type.

Learn More

How to define a struct in Swift

  1. Open your Swift file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Swift Define a Struct Syntax

Use struct Point { var x: Double var y: Double }.

Related Syntax References

Frequently asked questions

What is the Swift syntax for define a struct?

Use this pattern: struct Point { var x: Double var y: Double }

Can I copy this Swift code example?

Yes. Use Copy code and adapt the example to your program.

Is this Swift syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify