两种结构相互引用

时间:2016-12-07 19:07:26

标签: swift

鉴于以下情况:

struct Book {
    let title: String
    let description: String
    let authors: [Author]
}

struct Author {
    let name: String
    let books: [Book]
}

现在我们有一个奇怪的情况:

var books = [Books]()
var authors = [Authors]()

let author1 = Author(name: "some author", books: [book1]) // ????
let book1 = Book(title: "Some title", authors: [author1]) // ????

books.append(book1)
authors.append(author1)

我们如何解决这个问题?

0 个答案:

没有答案