# Challenge 2 Of Chapter 13 Problem

**URL:** <https://forums.kodeco.com/t/challenge-2-of-chapter-13-problem/171887>\
**Category:** Swift Apprentice\
**Created:** [May 25, 2022, 8:41pm UTC](https://forums.kodeco.com/t/challenge-2-of-chapter-13-problem/171887 "2022-05-25T20:41:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinkazama](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jinkazama/32/105896_2.png) [@jinkazama](https://forums.kodeco.com/u/jinkazama)\
**Post date:** [May 25, 2022, 8:41pm UTC](https://forums.kodeco.com/t/challenge-2-of-chapter-13-problem/171887/1 "2022-05-25T20:41:47Z")

</div>

I am not sure if it is just a mishap from the editorial team, but by no mean can we initialize an object from any of the struct or class below. Anyway the challenge question is this

> Your challenge here is to build a set of objects to support a t-shirt store. Decide if each object should be a class or a struct, and why.
> 
> TShirt - Represents a shirt style you can buy. Each TShirt has a size, color, price, and an optional image on the front.
> 
> User - A registered user of the t-shirt store app. A user has a name, email, and a ShoppingCart (below).
> 
> Address - Represents a shipping address, containing the name, street, city, and zip code.
> 
> ShoppingCart - Holds a current order, which is composed of an array of TShirt that the User wants to buy, as well as a method to calculate the total cost. Additionally, there is an Address that represents where the order will be shipped.

These are the code

```auto

 struct Tshirt {

 let size: String

 let color: String

 let price: Double

 var image: String?

}

 class Customer {

 let name: String

 var emailAddress: String

 let shoppingCart: ShoppingCart

 init (name: String, emailAddress: String, shoppingCart: ShoppingCart) {

 self.name = name

self.emailAddress = emailAddress

self.shoppingCart = shoppingCart

}

}

struct Address {

 let name: Customer

var street: String

var city: String

var zipCode: String

}

class ShoppingCart {

var orders: [Tshirt] = []

 let address: Address

init (address: Address) {

self.address = address

}

```

as you can see the customer object requires the shoppingCart object for initialization, and the shoppingCart object requires the address struct for initialization and then the address struct requires the customer object for its initialization as well. It becomes like a cycle which depends on others to be initialized in order to get themselves created.

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [May 26, 2022, 3:12pm UTC](https://forums.kodeco.com/t/challenge-2-of-chapter-13-problem/171887/2 "2022-05-26T15:12:37Z")

</div>

@mattjgalloway any suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [November 8, 2022, 12:42pm UTC](https://forums.kodeco.com/t/challenge-2-of-chapter-13-problem/171887/4 "2022-11-08T12:42:34Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
