Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessing datasource using simple array #13

Open
ekapradityagk opened this issue May 9, 2018 · 1 comment
Open

accessing datasource using simple array #13

ekapradityagk opened this issue May 9, 2018 · 1 comment

Comments

@ekapradityagk
Copy link

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
Copy link
Author

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)
}
}()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant