What is lldb_expr in Swift Playground?
I am not 100% about this but to me this seems sane and logical.
Your Animal
class is empty so the compiler needs a way to express / print the class / it's values. So what it does is print __lldb_expr_380.Animal
because the compiler doesn't know what else to make of it. If you add a property, for example legs
, the result becomes this: {{legs 2} feet 4}
.
So, in my understanding whenever you have this empty superclass the compiler will get 'confused' and the error that happens is that it will just print out __llb_expr_:some_number:.ClassName
instead of something like {}
.
Reference: http://discuss.codewithchris.com/t/episode-7-classes-error---lldb-expr-/150
What is this [__lldb_expr_19.Book] I'm getting in the console?
That's the way Swift describes classes.
For a more meaningful way add this extension to adopt CustomStringConvertible
. In the computed property return whatever you want
extension Book : CustomStringConvertible {
var description : String { return "Book \(name) / \(author)" }
}
Do you really need a class? With a struct you get rid of the initializer, adopting Equatable
doesn't require any additional code and you get a better description for free.
This can replace your entire class
struct Book : Equatable {
let title, author, genre: String
}
Empty Class in Swift Playground Gives __lldb_expr_ Error
This is not an error.
It's an information that the variable foo
now holds an object of class FooBar
whose internal name is __lldb_expr_12.FooBar
. __lldb_expr_12
is the Swift module's name in the Playground in this case.
Error lldb_expr when printing a variable
It´s not an error, it´s the Low Level Debugger and how the Playground prints out your enum. If you break it down you´ll see:
[
__lldb_expr_98.Movie.MovieGenere.comedy
,
__lldb_expr_98.Movie.MovieGenere.adventure
,
__lldb_expr_98.Movie.MovieGenere.animation
]
Create random number of class instances - Swift
There are probably a lot of different (valid) approaches to this. One of which could be something like this:
let exerciseArray = ["squats", "pushups", "lunges", "jumping jacks"]
struct Exercise {
let name: String
let reps: Int
}
func randomInt(upperBound: UInt32) -> Int {
return Int(arc4random_uniform(upperBound))
}
let numberOfExercisesInWorkout = randomInt(upperBound: 10)
let exercises: [Exercise] = (1...numberOfExercisesInWorkout).map { _ in
let randomKey = randomInt(upperBound: UInt32(exerciseArray.count))
return Exercise(name: exerciseArray[randomKey], reps: randomInt(upperBound: 10))
}
print(exercises)
Which ouputs something like this:
[Exercise(name: "lunges", reps: 8), Exercise(name: "jumping
jacks", reps: 6), Exercise(name: "lunges", reps: 4),
Exercise(name: "squats", reps: 9), Exercise(name: "jumping
jacks", reps: 5), Exercise(name: "squats", reps: 9)]
Note: You could also modify the (randomInt
) helper function to take into account a lowerBound I guess
Related Topics
How to Reference Instance Function When Calling Sequencetype.Foreach
Maximum Height of iOS 8 Today Extension
How to Customize the Navigation Back Symbol and Navigation Back Text
Xcode6: Run Two Instances of the Simulator
When Do I Need to Call Setneedsdisplay in iOS
Checking a Null Value in Objective-C That Has Been Returned from a JSON String
The Maximum Number of Apps for Free Development Profiles Has Been Reached. Xcode 11.5
What Does Main.Sync in Global().Async Mean
Xcode 5 Crashes -- Xcode Quit Unexpectedly
What's the Equivalent of the Uisplitviewcontroller in Swiftui
Disabling Nslog for Production in Swift Project
How to Get Navigation Based Template Functionality in Swift Programming
iOS Autolayout: Two Buttons of Equal Width, Side by Side
What #Defines Are Set Up by Xcode When Compiling for Iphone
Storing Authentication Tokens on iOS - Nsuserdefaults VS Keychain
Wait for Asynchronous Operation to Complete in Swift
"Your Binary Is Not Optimized for iPhone 5" (Itms-90096) When Submitting