Structures in Objective C and Swift

Structure is a complex data type which contains individual elements which defer in type. 
There are many situations in programming where discrete types have to be identified together as one unit. In this situations we make use of Struct.

Structs are used to represent a record, Suppose you want to keep track of your books in a Library. you might want to track the following attributes about each book.

Struct Book {
Title
Author 
Subject
Book ID
};

Struck Person {
Name
Age
Height
Weight
Gender
Color
};

Individual elements of Struct are referred to as members

Unlike Objective C, classes in Swift, structures can have methods, properties, initializers, and conform to protocols. The main difference between classes and structures is that classes are passed by reference, while structs are passed by value.

2 comments: