How the peripheral data is structured in Bluetooth connection?

The peripheral data is represented in the form of services and characteristics. Each peripheral device may offer more than one service. Each service is distinguished from the other by the use of UUID(Unique Numeric ID). Services is a collection of data and associated information for accomplishing a function or feature of a device. Characteristics provide further information about peripheral device and may contain properties, values and descriptors. Like service, characteristics also contain UUID which helps differentiate one from the other.

Swift: Computed property getter and setter

Computed property provides a getter and optional setter. When we try to access the computed property, the getter code is called. When we set a new value or modify the value of a computed property the setter code is called. The setter code is optional.

In the below code, we we try to read the computed property, the getter code is called. When we try to insert a value to modify the computed property, the setter code is called.

Swift: Computed property example code

Below is a simple computed property written as a part of Struct instance.

Swift: Similarities and differences between Structures and Classes

Swift provides as with two basic constructs: Structures and Classes which are the building blocks of our code. Structures are value type. Classes are reference types.Structures and classes have the following similar characteristics:

  • We can define methods
  • We can define properties
  • We can define subscripts
  • We can define initializers
  • We can extend them to perform additional functions
  • We can make them┬áconform to any protocols as needed

In addition to the above aspects, Classes also have the following characteristics:

  • We can define deinitializers
  • We can perform type casting
  • We can inherit properties and methods from another class(Inheritance)
  • We can perform reference counting

 

Swift: Stored properties of variable struct instances

A stored property is a constant or variable that is stored as a part of an instance of a particular class or structure. Stored properties can be variable stored properties(var) or constant stored properties(let). We can set default value for a stored property as a part of its definition or set and modify the initial value during initialization for both constant and variable stored properties. Once values are set for constant stored properties they cannot be changed.