In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article analyzes "what is the basic definition of classes in big data". The content is detailed and easy to understand. Friends who are interested in "what is the basic definition of class in big data" can follow the editor's train of thought to read it slowly and deeply. I hope it will be helpful to everyone after reading. Let's follow the editor to learn more about "what is the basic definition of classes in big data".
/ *
Basic definition of class
Structures and classes in Swift are very similar, but there are differences.
A class is an abstraction with the same properties and methods
Format:
Class class name {
Properties and methods of the class
}
, /
Class Rect {
Var width:Double = 0.0
Var height:Double = 0.0
Func show ()-> Void {
Print ("width =\ (width) height =\ (height)")
}
}
/ / the class does not have an one-by-one constructor
/ / var R1 = Rect (width: 10.0, height: 10.0)
Var R1 = Rect ()
R1.show ()
Var R2 = R1
R2.show ()
/ / the class is a reference type, and the assignment between structures is actually a storage control that points R2 to R1, so they only want the same piece of storage, and modifying one of them will affect the other.
R1.width = 99
R1.show ()
R2.show ()
/ *
Identity operator, which is used to determine whether it is the same instance, that is, whether it points to the same storage space
=
, /
Var R3 = Rect ()
If R1 = R3
{
Print ("pointing to the same piece of storage")
}
Second, the definition of the class
Import UIKit
Class Student: NSObject {
/ / 1. Attribute
/ / 1 > Storage Properties
/ / Note 1: in development, if it is an object or structure, it is usually defined as an optional type without an assignment.
Var name: String?
/ / Note 2: in development, if it is a basic attribute type, such as the int type, if there is no assignment, it is usually directly given a default value of 0
Var age: Int = 0
Var chineseScore: Double = 0.0
Var mathScore: Double = 0.0
/ / 2 > calculation Properties
/ *
Var average: Double {
Get {
Return (chineseScore + mathScore) * 0.5
}
/ / the set method is rarely written (by default, there is a system variable in the set method: newValue. The newly passed value is in newValue)
Set {
Self.average = newValue
}
}
, /
/ / if the calculated property is read-only, get {} can be omitted
Var average: Double {
Return (chineseScore + mathScore) * 0.5
}
/ / 3 > (understand) class properties
/ / Note:
/ / * Class attributes are decorated with static
/ / * Class properties can only be accessed through the class
Static var courseCount = 0
}
/ / create an object of the class
Let stu: Student = Student ()
Stu.name = "yz"
Stu.age = 11
Stu.chineseScore = 61.5
Stu.mathScore = 97.8
If let tempName = stu.name {
Print ("name is\ (stu.name!), age is\ (stu.age), Chinese score:\ (stu.chineseScore), Mathematics score:\ (stu.mathScore)")
}
/ / get the average score of the yz teacher
Print (stu.average)
Student.courseCount = 2
Print (Student.courseCount)
Class Person: NSObject {
Var name: String?
Var age: Int = 0
Var height: Double = 0.0
}
Let p = Person ()
/ / Note: instead of calling the set method, you can directly get the attribute to assign a value to it.
P.name = "why"
P.age = 18
P.height = 1.88
Third, type conversion
/ *
Swift does not allow implicit type conversions, but you can use display type conversions (cast)
OC:
Int intValue = 10
Double doubleValue = (double) intValue
Swift:
, /
Var intValue:Int = 10
Var doubleValue:Double
DoubleValue = Double (intValue)
/ / Note: Double () does not modify the value of intValue, but generates a temporary value from the value of intValue to assign to doubleValue
Print (intValue)
Print (doubleValue)
This is the end of the basic definition of the class in big data. I hope the above content can improve everyone. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.