title: Declaring NSDictionary and put it key value pair in Swift?
body: <p>I have been trying to declare an NSDictionary with class type key and value like this :</p>
  
  <pre><code>var catAndSubCatDict: NSDictionary&lt;Category, Array&lt;SubCategory&gt;&gt; = NSDictionary&lt;Category, Array&lt;SubCategory&gt;&gt;()
  </code></pre>
  
  <p>Here, "Category" and "SubCategory" are the global classes. I know that I can not use a class type for key field. However, I should achieve this anyway. Is there any way to do this ? How can I declare specialized NSDictionary or similar things to do this ?</p>
  
  <p>In addition, I use this dictionary like this :</p>
  
  <pre><code>for(var i=0; i&lt;resultJson.count; i++)
  {
     let subCategoryItemList = resultJson.objectAtIndex(i) as NSDictionary
     let categoryItem = subCategoryItemList.valueForKey(WSConstants.CATEGORY_OBJ) as NSDictionary
  
     var category: Category = Category()
     category.categoryId    = categoryItem.valueForKey(WSConstants.CATEGORY_ID) as Int
     category.categoryName  = categoryItem.valueForKey(WSConstants.NAME) as String
  
     var subCategoryList: Array&lt;SubCategory&gt; = []
     let jsonSubCategoryList = subCategoryItemList.allKeysForObject(WSConstants.SUBCATEGORY_LIST_OBJ) as NSArray
  
     for(var i=0; i&lt;jsonSubCategoryList.count; i++)
     {
        let subCategoryObj = jsonSubCategoryList.objectAtIndex(i) as NSDictionary
  
        var subCategory: SubCategory = SubCategory()
        subCategory.subCategoryId    = subCategoryObj.valueForKey(WSConstants.SUBCATEGORY_ID) as Int
        subCategory.subCategoryName  = subCategoryObj.valueForKey(WSConstants.NAME) as String
        subCategory.subCategoryType  = subCategoryObj.valueForKey(WSConstants.SUBCATEGORY_TYPE) as Int
  
        subCategoryList.append(subCategory)
     }
     self.catAndSubCatDict.setValue(category, forkey: subCategoryList) // Also, I have to achieve this
  }
  </code></pre>
  
  <p>Thank you for your answers,</p>
  
  <p>Best regards</p>