Use of objects and structures in SWIFT

  • Object
class Student{


var name: String = "";
var age: Int = 0;

init(name: String ,age:Int) {
self.name
= name
self.age
= age
}
}

let stu
= Student(name: "xiao< span style="color: #800000;">", age: 18)
print(
"Name: \(stu.name)")//Name : Xia

  • Structure
struct Person{
    
    var name: String = "";
    var age: Int = 0;
    
    init(name: String ,age:Int) {
        self.name = name
        self.age = age
    }
}

let person = Person(name: "xiao", age: 18)
print("Name: \(person.name)")//Name: xiao

The structure body does not need to consider the reference count. The joint body is a value assignment, that is, a is assigned to b. If you change b, then a remains unchanged, for example

p>

let person = Person(name: "xiao", age: 18)
print("Name: \(person.name)")//Name: xiao
var per1 = person;
per1.name = "da"

print("Name: \(person.name)")//Name: xiao

class Student{


var name: String = "";
var age: Int = 0;

init(name: String ,age:Int) {
self.name
= name
self.age
= age
}
}

let stu
= Student(name: "xiao< span style="color: #800000;">", age: 18)
print(
"Name: \(stu.name)")//Name : Xia

struct Person{
    
    var name: String = "";
    var age: Int = 0;
    
    init(name: String ,age:Int) {
        self.name = name
        self.age = age
    }
}

let person = Person(name: "xiao", age: 18)
print("Name: \(person.name)")//Name: xiao

let person = Person(name: "xiao", age: 18)
print("Name: \(person.name)")//Name: xiao
var per1 = person;
per1.name = "da"

print("Name: \(person.name)")//Name: xiao

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4132 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.