- Define properties to strore values
- Define properties to provide functionality
- Define subscripts to provide access to their
- Values using subscript syntax
- Define initializers to set up their initial state
- Be extended to expand their functionality beyond
- A default implemention
- Conform to protocols to provide standard functionality of acertain kind
What are the differences between struct and class in swift:
- Inheritance enables one class to inherit the characteristics another
class nameClass{
//class definition goes here
}
struct nameStruct{
//structure definition goes here
}
Here’s an example of a structure note and a class note:
class Square{
var with = 0
var height = 0
}
struct Product{
var weight = 0
var price = 0
}
Classes are an concept of data structures: like datastructures, they can contain data members but they can also contain functions are members
swift do not inherit from a universal Class you define without specifying a superclass automatically become base classes for you to build upon
Note of Structures:
Structures are always copied when they are passed around in your code ,and do not use reference counting
Choosing between classes and structure:
Choosing between classes and structures We consider creating a structure when one or more of the following conditions apply:The structure's primary purpose is to encapsulate a few relatively simple data valuesIt is reasonable to expect that the encapsulated values will be copied rather than referenced when we assign or pass around an instance of the structureAny properties stored by the structure are themselves value types, which would also be expected to be copied rather than referencedThe structure does not need to inherit properties or behavior from anotherexisting typeExample of good candidates for structures include the following:Subclassing subclassing in the act of basing a new class on an new class on an existing class the subclassing characteristics to subclassthe indelicate that class has a superclass,write the superclass name after the original class name,separated by colon:
class Rectangle:Square{
Comments
please post any question and comment right here so that i can support for you
Post a Comment