如何从Swift中的JSON返回collectionview numberOfItemsInSection中最多10个项目

如何从Swift中的JSON返回collectionview numberOfItemsInSection中最多10个项目,json,swift,uicollectionview,Json,Swift,Uicollectionview,我得到的Json响应如下所示 detailsDB = ProductDetailsData(dictionary: NSDictionary()) func serviceCall(){ let param = ["jsonrpc": "2.0", "params": ["product_id" : productID ]] as [String :

我得到的Json响应如下所示

   detailsDB = ProductDetailsData(dictionary: NSDictionary())

   func serviceCall(){
let param = ["jsonrpc": "2.0",
             "params": ["product_id" : productID
             ]] as [String : Any]

APIReqeustManager.sharedInstance.serviceCall(param: param, vc: self, url: getUrl(of: .product_details), header: header) {(responseData) in
  
        self.detailsDB = ProductDetailsData(dictionary: responseData.dict as NSDictionary? ?? NSDictionary())
}
像这样,我得到的所有JSON产品都显示在collectionview中。。在这里我需要显示最多10个从JSON到collectionview的产品

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return detailsDB?.result?.seller_products?.count ?? 0
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VerticalSliderCollectionCell", for: indexPath) as! VerticalSliderCollectionCell
   
    let indexData = detailsDB?.result?.seller_products?[indexPath.item]
    cell.imgProduct.getImage(strUrl: "\(productImagePath)\(indexData?.default_image?.image ?? "")")
    cell.lblTitle.text = indexData?.product_by_language?.title
    cell.lbRealPrice.text = indexData?.discount_price != "0.000" ? "\(indexData?.price ?? "") KWD" : ""
    cell.lblDiscountedPrice.text = indexData?.discount_price != "0.000" ? "\(indexData?.discount_price ?? "") KWD" : "\(indexData?.price ?? "") KWD"
   
    return cell
}

请帮助我解决此错误。再次使用:min(detailsDB?.result?.seller\u products?.count?0,10)只需将此逻辑写入
numberOfItemsInSection
,类似于:
return min(10,detailsDB?.result?.seller\u products?.count?.0)
,不要在Swift中使用
NS…
收集类型。你扔掉了类型信息。使用本机类型
Array
Dictionary
从解析的数据中获取前缀10项source@RajaKishan,好的,那么如何在
cellForItemAt