所以我是 swift 的新手,我无法让我的愿望清单按钮将项目从阵列运动鞋移动到阵列运动鞋 1
class Sneakers {
var sneakers = [
BagProducts(image: UIImage(named: "Image")! , category: "Men" , name: "Adidas Gazelle", price: 100.00, size: "40" , color: "Blue"),
BagProducts(image: UIImage(named: "Image")! , category: "Men" , name: "Adidas Gazelle", price: 100.00, size: "40" , color: "Blue"),
]
var sneakers1 = [
WishProducts(image: UIImage(named: "AdidasGalaxy")! , category: "Women" , name: "Adidas Galaxy 6", price: 55.00, size: "", color: ""),
WishProducts(image: UIImage(named: "NewBalance")! , category: "Men" , name: "New Balance BB550", price: 150.00, size: "", color: ""),
]
}
这是我的数组
@objc func wishButtonTapped(_ sender: UIButton) {
viewModel.sneakers1.append(contentsOf: viewModel.sneakers)
print("Moved to wishlist")
}
这是我用来让它移动的函数,但是当我运行它时出现这个错误“在调用实例方法'append'时没有完全匹配
protocol BagProduct {
var image: UIImage { get }
var category: String { get }
var name: String { get }
var price: Double { get }
var size: String { get }
var color: String { get }
}
protocol WishProduct {
var image: UIImage { get }
var category: String { get }
var name: String { get }
var price: Double { get }
var size: String { get }
var color: String { get }
}
struct WishProducts: WishProduct {
let image: UIImage
let category: String
let name: String
let price: Double
let size: String
let color: String
init(image: UIImage, category: String, name: String, price: Double, size: String, color: String) {
self.image = image
self.category = category
self.name = name
self.price = price
self.size = size
self.color = color
}
}
struct BagProducts: BagProduct {
let image: UIImage
let category: String
let name: String
let price: Double
let size: String
let color: String
init(image: UIImage, category: String, name: String, price: Double, size: String, color: String) {
self.image = image
self.category = category
self.name = name
self.price = price
self.size = size
self.color = color
}
}
这是我用于我的产品的结构