So I just started working on Challenge 10 and ran into a bunch of different error messages. I am getting the error messages expected expression, and expected pattern, and also Cannot convert value of type ‘[String : Person]’ to expected argument type ‘String’. Any advice?
class Person{
var name:String!
init(_ fullName:String){
name = fullName
}
}
class Book{
var title:String!
var author:String!
init(_ bookTitle:String, _ bookAuthor:String){
title = bookTitle
author = bookAuthor
}
}
class Library{
var catalogue = ["ORW":Book("1984", "George Orwell"), "RAY":Book("Fahrenheit 451", "Ray Bradbury")]
var checkedOutBooks = [String:Person]()
//let searchResult = lib.searchByTitle("1984")
func searchByTitle(_ title:String) -> String{
var bookFound = false
var bookMessage = ""
for 0..<catalogue.count{ in index
if(catalogue[index].title == title){
bookFound = true
break
}
}
if(bookFound){
if(checkedOutBooks == title){
bookMessage = "Checked out by name"
}
else{
bookMessage = "Available"
}
}
else{
bookMessage = "Not in Catalog!"
}
//Available
//Checkout
//Not in catalog
return bookMessage
}
func checkOut(_ bookId:String, _ person:Person) -> String{
var bookFound = false
var bookMessage = ""
for 0..<catalogue.count{ in index
if(catalogue[index].title == title){
bookFound = true
break
}
}
if(book)
//Returns error if out already
//Returns success and adds
//Returns book doesn't exist
return bookMessage
}
func checkIn(_ bookId:String) -> String{
//Returns doesn't exist
//Returns error if book is not already out
//Returns successful check in.
return ""
}
}
let lib = Library()
let borrower1 = Person("Curious George")
let borrower2 = Person("Mark Twain")
let searchResult = lib.searchByTitle("1984")
print(searchResult)
let borrowResult = lib.checkOut("ORW", borrower1)
print(borrowResult)
let searchResult2 = lib.searchByTitle("1984")
print(searchResult2)
let borrowResult2 = lib.checkOut("ORW", borrower2)
print(borrowResult2)
let checkInResult = lib.checkIn("RAY")
print(checkInResult)