Answer the question
In order to leave comments, you need to log in
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:
I don’t understand where this value comes from. I would be grateful for a hint.
The code:
//: [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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question