0

how to add object in array.

I have :- var datasourceModel:QM_ChartDataSourceModel

in datasourceModel i have output as:-

<QM.QM_OfferModel: 0x7aecea50>
<QM.QM_OfferModel: 0x7aecfb30>
<QM.QM_OfferModel: 0x7aed0e40>
<QM.QM_OfferModel: 0x7aed0ec0>
<QM.QM_OfferModel: 0x7aed0f70>

in here:-

var insertedArray:QM_CartModel?

in this my output as :<QM.QM_CartModel: 0x7ae4a020>

So i need to add insertedArray in the datasourceModel

How to add?

my cartmodel:-

  //models.........
    var offerdetailModel:QM_OfferModel?

    init(withoffermodel  newofferdetailtModel:QM_OfferModel){
        offerdetailModel = newofferdetailtModel
        print(offerdetailModel?.name)
        offerdetailAddName = offerdetailModel?.name
        offerdetailid = offerdetailModel?.id

    }

the values are there in offerdetailModel

so i need to insert the offerdetailmodel?.name from the

.how to insert this value

  • `insertedArray.append(your_element)` <-- Have you tried this? – dahiya_boy May 10 '18 at 10:04
  • Possible duplicate of [Add an element to an array in Swift](https://stackoverflow.com/questions/24002733/add-an-element-to-an-array-in-swift) – mag_zbc May 10 '18 at 10:10
  • @dahiya_boy i have updated my code.So how to add according,please check – nahlaabdulnawal May 10 '18 at 10:15
  • try this let obj : DictModel = QM_OfferModel Model() obj.TotalComments = 0 obj.engagement_comment_id = 0 obj.comment = (commentTextField.text?.trimmingCharacters(in: .whitespaces))! obj.comment_user_name = userDefaultObj.userName!.capitalized obj.comment_user_id = 0 obj.comment_user_image = "" self.feedCommentDictArray.append(obj) – Satheeshkumar Naidu May 10 '18 at 11:30

0 Answers0