Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


luke jones
luke jones
8,915 Points

adding an array to an array

I asked this question yesterday but don't think I asked the question too well. I'm going to try and ask it a little better this time... import UIKit

class House: NSObject {

var housePerson = []
var houseNumber = ""
var houseAddress = ""
var housePhoneNumber = ""

} class HouseModel{

func getHouse() -> [House] {

    var house = [House()]

    let house1 = House()
    house1.housePerson = ["Steve", "Matthew", "Paul", "Jason"]
    house1.houseNumber = "123"
    house1.houseAddress = "Bob Drive"
    house1.housePhoneNumber = "123456789"

    return house


class Person { var personName = "" var personAge = "" var personHeight = "" var personWeight = "" var personSex = "" } class PersonModel{

func getPerson() -> [Person] {

    var person = [Person]()

    let person1 = Person()
    person1.personName = "Steve"
    person1.personAge = "23"
    person1.personHeight = "180cm"
    person1.personWeight = "200lbs"
    person1.personSex = "M"

    let person2 = Person()
    person2.personName = "Matthew"
    person2.personAge = "27"
    person2.personHeight = "165cm"
    person2.personWeight = "170lbs"
    person2.personSex = "M"

    return person

} }

I want to add person1 to the House array rather than them being two separate arrays. Hopefully that makes sense.