I
I
Igor2021-01-17 21:57:47
Arrays
Igor, 2021-01-17 21:57:47

Swift. When forming an array, __lldb_expr is added, what does this mean?

Good afternoon.
I asked myself the question of learning the language, I am taking courses.
This is not the first time I have encountered the following problem when working with arrays:
600487a5f28c3952201940.png
I don’t understand where this value comes from. I would be grateful for a hint.

The code:

spoiler
//: [Previous](@previous)

import Foundation

class Animal {
    var gender: String
    
    init(gender: String){

        self.gender = gender
    }
}

class Dog: Animal {
    var name: String
    var color: String
    var size: Int
    
    init(name: String, color: String, size: Int, gender: String){
        self.name = name
        self.color = color
        self.size = size
        super.init(gender: gender)
        
    }
}

class Cat: Animal {
    var name: String
    var color: String
    var size: Int
    
    init(name: String, color: String, size: Int, gender: String){
        self.name = name
        self.color = color
        self.size = size
        super.init(gender: gender)
        
    }
}
//: [Next](@next)
var myAnimal = [Animal]()
myAnimal.append(Dog(name: "Doggi", color: "Red", size: 3, gender: "man"))
myAnimal.append(Dog(name: "Sharik", color: "Write", size: 4, gender: "man"))
myAnimal.append(Dog(name: "Bobik", color: "Black", size: 5, gender: "man"))
myAnimal.append(Cat(name: "Fandorin", color: "Black", size: 3, gender: "man"))

var myAnimalTwo = [Animal]()
myAnimalTwo.append(Dog(name: "Doggi", color: "Red", size: 3, gender: "man"))
myAnimalTwo.append(Dog(name: "Sharik", color: "Write", size: 4, gender: "man"))
myAnimalTwo.append(Dog(name: "Bobik", color: "Black", size: 5, gender: "man"))
myAnimalTwo.append(Cat(name: "Mysya", color: "Black", size: 3, gender: "man"))

var animalAny = [AnyObject]()

for item in myAnimal{
    animalAny.append(item)

}

for i in myAnimal{
    switch i {
    case _ as Dog:
        print(i)
    default:
        print("The end!")
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2021-01-17
@402d

The variable is an instance of the class. print tries to print your variable.
Wants to take a string representation from this instance.
The class has no such method. By default, prints the name of the class the instance of which the variable is.

W
Wataru, 2021-01-17
@wataru

I'm not a Swift expert, but so far it looks like the language just doesn't know how to write a Dog class. Therefore, it displays some of its internal designation of the class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question