-1

I have an Array of [Hashtag]. The Hashtag NSObject simply holds a variable for the hashtagName which is a String?. One array is a categoriesArray and the other is a fashionArray. What I would like is when I tap a certain indexPath in my didSelectItemAtIndexPath method, I want to insert the fashionArray into the categoriesArray at the selected Index. The issue I have is that it wants an array of Strings and not an array of Hashtag. How do I achieve this? Thanks guys. Code is below:

import UIKit

class Hashtag: NSObject {

    var hashtagName: String?
}

private let reuseIdentifier = "Cell"

class HashtagView: UICollectionViewController, UICollectionViewDelegateFlowLayout {

    var categoriesArray = [Hashtag]()

    var fashionArray = [Hashtag]()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationController?.navigationBar.tintColor = .white
        navigationItem.title = "Hashtag"

        self.collectionView?.backgroundColor = .white
        self.collectionView?.register(HashtagCell.self, forCellWithReuseIdentifier: reuseIdentifier)
        self.collectionView?.contentInset = UIEdgeInsetsMake(10, 0, 0, 0)

        handleFetchCategories()
        handleFetchFashionHashtags()
    }

    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        if indexPath.item == 1 {
            // insert here
            self.categoriesArray.insert(fashionArray[indexPath.item].hashtagName, at: 1)
            print(categoriesArray)
        }

    } 
Jimmy
  • 285
  • 3
  • 11
  • Isn't this a repost of [your previous question](http://stackoverflow.com/questions/43172959/swift-cant-insert-nsobject-into-array-as-it-wants-a-string-instead)? Why another question? Why not edit your other one? – rmaddy Apr 02 '17 at 21:54
  • @rmaddy I'm clearly a newbie after an answer to help with my programming... Why be such a jobs worth? – Jimmy Apr 02 '17 at 22:19
  • 1
    Being a newbie or not is irrelevant. This site works a certain way. Reposting questions just to get more attention is not acceptable on this site. The proper thing for you to do is to edit, as needed, your earlier question to make it clearer. – rmaddy Apr 02 '17 at 22:21

1 Answers1

-2

To insert that Better is use dictionary>, where key is your indexpath.row and value is collection of all objects of Hashtag.

hament
  • 1