dany giguere
02/20/2022, 5:55 PMfun validate(title: String): Json {
val errors: Json
val titleArray: Array<String?>
if(title.length < 20) {
titleArray.add("The title must contain at least 20 characters")
}
if(title.length > 100) {
titleArray.add("The title must contain no more than 100 characters")
}
if(titleArray.length > 0) {
errors.title = titleArray
}
return Json {
"errors": errors
}
}
as it is, I get this error : Variable 'titleArray' must be initialized
Sam
02/20/2022, 6:23 PM=
) before you can access it. In this case I think you'll find it easier to use a list than an array, so try:
val titleArray = mutableListOf<String>()
dany giguere
02/20/2022, 8:10 PM