weijentu / automatic-height-tagcells

This is a sample project to implement features with dynamic height of UITableViewCell based on autolayout, tags aligned automatically and clickable tags.
http://www.xcodeproj.com
MIT License
225 stars 36 forks source link

accessing datasource using simple array #13

Open ekapradityagk opened 6 years ago

ekapradityagk commented 6 years ago

hi, so sorry for my previous opened issue,

at the moment im using your code and try to bypass your data source from json file and do this

` private func configureCell(_ object: AnyObject, atIndexPath indexPath: IndexPath) { if object.isKind(of: AHTagTableViewCell.classForCoder()) == false { abort() } let cell = object as! AHTagTableViewCell

    var dataFundArr = NSMutableArray()
    var dataDictionary = [
        "url":"0.25",
        "color":"0xFF8F8F",
        "enabled":"true",
        "category":"data category",
        "title":"aadsa"
    ]

    print("data dict")
    for (myKey,myValue) in dataDictionary {
        print("\(myKey) \t \(myValue)")
    }
    dataFundArr.add(dataDictionary)

    let tags = dataFundArr

    cell.label.setTags(tags as! [AHTag])
}

`

but the compiler is reject it saying

Could not cast value of type 'Swift._SwiftDeferredNSDictionary<Swift.String, Swift.String>' (0x10102b518) to 'AutomaticHeightTagTableViewCell.AHTag' (0x100938468). 2018-05-09 13:55:03.900266+0700 AutomaticHeightTagTableViewCell[15205:3410518] Could not cast value of type 'Swift._SwiftDeferredNSDictionary<Swift.String, Swift.String>' (0x10102b518) to 'AutomaticHeightTagTableViewCell.AHTag' (0x100938468).

the issue is still the same, i want to use my own set of array to generate data instead of json file

ekapradityagk commented 6 years ago

so after i check, on the dataSource function you change each of dictionary from this

["ENABLED": 1, "URL": http://pinterest.com, "COLOR": 0xFF8F8F, "TITLE": All Pins, "CATEGORY": Pinterest]

into this

AHTag(category: "Pinterest", title: "All Pins", color: UIExtendedSRGBColorSpace 1 0.560784 0.560784 1, url: Optional(http://pinterest.com), enabled: true)

so i assuming i had to take out something in this function to mine, or change this piece of function to accept my array

private let dataSource = { () -> [Array] in let URL = Bundle.main.url(forResource: "TagGroups", withExtension: "json")! // print("url " + URL) do { let data = try Data(contentsOf: URL) // print("data " + Data(data)) let object = try JSONSerialization.jsonObject(with: data, options: .allowFragments) // print("object " + String(object)) guard let groups = object as? [[[String : Any]]] else { fatalError("Not in an expected form of [[[String : Any]]]") } print("data source") for element in groups { print(element) } return groups.map({ return $0.map({ AHTag(dictionary: $0) }) }) } catch let error as NSError { fatalError(error.localizedDescription) } }()