中定義的內部類的變量名我有這兩個類:要知道在外部類
class User:Obj
{
var firstBook:Book?
var secondBook:Book?
}
class Book:Obj
{
func getMyName() -> String
{
// Something need to do here
// return name
}
}
let user = User()
let book_1 = Book()
user.firstBook = book_1
let book_2 = Book()
user.secondBook = book_2
print(book_2.getMyName()) //Expected: secondBook
print(book_1.getMyName()) //Expected: firstBook
正如你明白,我需要得到父類的變量名。 將是巨大的,如果將有可能同時得到父母class.Type
爲什麼你需要這樣做呢? – Hamish
假設firstBook和secondBook是本地數據庫中的單獨表格,我需要從Book對象 –