let ではなく var である配列プロパティを設定しようとしています。setAllShopItems
メソッドに注意してください。
struct ShopDisplay {
private var allShopItemCategories: [ShopItemCategory]
private var currentShopItemCategory: ShopItemCategory
private var shopItemCategoryIcon: MMImageView
private var currentShopItemGender: Gender
private var allShopItems: [ShopItem]
private var allDisplayedShopItems: [ShopItem]
init() {
allShopItemCategories = [ShopItemCategory]()
currentShopItemCategory = ShopItemCategory(rawValue: "TO")!
shopItemCategoryIcon =
MMImageView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
currentShopItemGender = .Female
allShopItems = []
allDisplayedShopItems = []
}
mutating func setShopItemsToDisplay() {
allDisplayedShopItems.removeAll()
for item in self.allShopItems {
let itemCategory = item.object["category"] as! String
if itemCategory == currentShopItemCategory.rawValue {
allDisplayedShopItems.append(item)
}
}
}
mutating func setAllShopItems(shopItems: [ShopItem]) {
self.allShopItems = shopItems
}
setAllShopItems()
このメソッドを次のように呼び出します。
override func prepareForSegue( segue: UIStoryboardSegue,
sender: AnyObject?) {
if (segue.identifier == "dressingRoom") {
let dressingRoomViewController = segue.destinationViewController
as! DressingRoomViewController
dressingRoomViewController.getShopDisplay().setAllShopItems(self.allShopItems)
dressingRoomViewController.getShopDisplay().setAllShopItemCategories(
self.categories)
}
}
getShopDisplay によって返されるプロパティも var です。
class DressingRoomViewController: UIViewController,
UICollectionViewDelegateFlowLayout,
UICollectionViewDataSource
{
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var heightConstraint: NSLayoutConstraint!
private let identifier = "cellIdentifier"
private let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
private let cellSpacing: CGFloat = 5
private let cellsPerRow: CGFloat = 5
private var cellSize: CGFloat = 0.00
private var shopDisplay = ShopDisplay()
@IBOutlet weak var categoryIcon: MMImageView!
func getShopDisplay() -> ShopDisplay {
return self.shopDisplay
}
したがって、設定されているこれらの変数がすべて var であり、mutating
それらがstruct
s である場合に設定するたびにキーワードを使用すると、どのようにこのエラーが発生するのでしょうか?:
/Users/Ben/Documents/Development/MirrorMirror/MirrorMirror/ChooseShopViewController.swift:40:44: タイプ「ShopDisplay」の不変値には、「setAllShopItems」という名前の変更メンバーのみがあります