swift
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| swift [2023/11/19 22:13] – admin | swift [2023/11/19 22:16] (current) – admin | ||
|---|---|---|---|
| Line 77: | Line 77: | ||
| [[https:// | [[https:// | ||
| - | ### Relationship | + | ### Relationship: Connect entities |
| ref: https:// | ref: https:// | ||
| - | Step by Step: | ||
| 1. Create Entities in CoreData | 1. Create Entities in CoreData | ||
| Line 87: | Line 86: | ||
| 5. In `...CoreDataProperties` file, you should be able to see code like below for adding transactions to this certain piggy object. | 5. In `...CoreDataProperties` file, you should be able to see code like below for adding transactions to this certain piggy object. | ||
| - | ```swift | + | ``` |
| extension Piggy { | extension Piggy { | ||
| Line 121: | Line 120: | ||
| 2. In ` ...CoreDataProperties` file, `transactions` is an `NSSet`, perform the following steps to convert it from an `NSSet` to a `Set< | 2. In ` ...CoreDataProperties` file, `transactions` is an `NSSet`, perform the following steps to convert it from an `NSSet` to a `Set< | ||
| - | ```swift | + | ``` |
| | | ||
| let set = transactions as? Set< | let set = transactions as? Set< | ||
| Line 133: | Line 132: | ||
| 1. Use them in your View: To read purchased items connected to a certain piggy in a View. Use the following code: | 1. Use them in your View: To read purchased items connected to a certain piggy in a View. Use the following code: | ||
| - | ```swift | + | ``` |
| | | ||
| | | ||
| Line 165: | Line 164: | ||
| Or use the following code. However with this method the HistoryView won't update if you add new purchasedItem (transaction) because it is only monitoring the object `piggy`. To trigger view update when purchasedItem is added, you need to use the method above to fetch `PurchasedItem` directly. | Or use the following code. However with this method the HistoryView won't update if you add new purchasedItem (transaction) because it is only monitoring the object `piggy`. To trigger view update when purchasedItem is added, you need to use the method above to fetch `PurchasedItem` directly. | ||
| - | ```swift | + | ``` |
| struct HistoryView: | struct HistoryView: | ||
| | | ||
swift.1700403186.txt.gz · Last modified: (external edit)
