-1

new approach to ask my question. I thought it was clear but apparently not. :-D 2nd chance.

I use SWXMLhash to get information from websites. For each website i need a different struct, because the datastructure of each website is different.

I have a good working function (using 1 website as source) which i would like to transform to a general function depending on the chosen website.

The best solution i have got so far (see code below) got me a compile error on:

 TorrentProviderItem = try xmlTorrent["rss"]["channel"]["item"].value()

compile error = Ambiguous reference to member 'subscript'

code of function:

 private func setResultsToEqualData(result: String, Torrentprovider: TorrentProviders) {
    var TorrentProviderItem: [XMLIndexerDeserializable]
    var xmlTorrent: XMLIndexer!
    xmlTorrent = SWXMLHash.parse(result)

    switch Torrentprovider {
    case .ExtraTorrent:
        TorrentProviderItem = [ExtraTorrentItem]()
    default:
        TorrentProviderItem = [Torrentz2Item]()
    }

    do {
        TorrentProviderItem = try xmlTorrent["rss"]["channel"]["item"].value()
    } catch {
        print("FOUT in torrent!!")
        return
    }

    selectBestResult()
}

I have no clue how to fix this. Anyone else?

ps in the original function for 1 website i use:

var TorrentProviderItem: [ExtraTorrentItem]

and without the switch, that works fine.

  • "Can someone help me?" Not likely until you edit your Q and add a much more thorough description of what you want to achieve, the actual code of what you tried, and the exact compiler error(s) (and on which line(s)) you received. It's impossible to answer your question without this information. Like "what's 2 plus some other number?" - best we can say is "it's twice whatever some other number is". – Joshua Nozzi May 24 '17 at 13:29
  • @ Joshua Nozzi Good point, i changed my question completely and i hope it is more clear like this. I played around with the code to find an answer, without any luck. I didn't save all "test" code, so i can't show all the things i have tried. The presented code is the closed i have got. – Ronald Baks May 24 '17 at 13:58
  • Type `XMLIndexer` doesn't seem to have a function called `value()` according to its source code. – JeremyP May 24 '17 at 14:22
  • @ JeremyP, valid point. But without the switch en a direct declaration of the var TorrentProviderItem like "var TorrentProviderItem: [ExtraTorrentItem]" this works fine. The also use value() in the example on the GitHub site of SWXMLhash. – Ronald Baks May 24 '17 at 14:30
  • @RonaldBaks Good work - the question is now answerable by those familiar with the library or willing to take the time to research it. My downvote and vote to close as unclear have both been retracted. – Joshua Nozzi May 24 '17 at 16:15
  • @JoshuaNozzi thank you. – Ronald Baks May 24 '17 at 16:32

1 Answers1

0

Some showed me the options of a function within a struct. So i used this to build a workaround. I wrote a function in each struct for each website, the returning value of each function is of the same datatype.

For me it is a workaround and not the solution. I still have to add every website to the function (see below).

private func setResultsToEqualData(result: String, Torrentprovider: TorrentProviders) -> torrentProviderItem? {
    var TorrentProviderItem = [torrentProviderItem]()
    var xmlTorrent: XMLIndexer!
    xmlTorrent = SWXMLHash.parse(result)

    switch Torrentprovider {
    case .ExtraTorrent:
        var tempExtraTorrentItem: [ExtraTorrentItem]
        do {
            tempExtraTorrentItem = try xmlTorrent["rss"]["channel"]["item"].value()
            for item in tempExtraTorrentItem {
                TorrentProviderItem.append(item.result())
            }
        } catch {
            print("FOUT in torrent!!")
            return nil
        }

    case .Torrentz2:
        var tempTorrentz2Item: [Torrentz2Item]
        do {
            tempTorrentz2Item = try xmlTorrent["rss"]["channel"]["item"].value()
            for item in tempTorrentz2Item {
                TorrentProviderItem.append(item.result())
            }
        } catch {
            print("FOUT in torrent!!")
            return nil
        }
    }
    return (selectBestResult(results: TorrentProviderItem))
}

I think the solution to create a general function lay's within the Strucs. To use one struct for all websites in stead of a struct for each website. I just don't know how to do this. Jet.