简体   繁体   中英

Declare swift class with 2 dependent generic types

I have a model and it looks like this:

  • Competitions - List of competition
  • Competition - Item of list

And also I'm going to create lots of such lists and display them in separate ViewControllers.

class Competition : ServerConfiguredObject {

    var caption = ""

    override func confirure(_ response: DictionaryWithStringKeys) {
        caption = response["caption"] as! String
    }
}

class Competitions : ServerConfiguredObjectsStorage <Competition> {

}

My aim is to declare viewController like this:

    typealias CompetitionsViewController = ServerConfiguredObjectsViewController <Competition, Competitions>

So I've declared View controller and added collection class and collection item class into template. And I've got an error.

First efford:

class ServerConfiguredObjectsViewController 
     <ServerConfiguredObjectsStorageClass:
         ServerConfiguredObjectsStorage<ServerConfiguredObjectClass:ServerConfiguredObject>> : UIViewController

Compilation Error(String with class declaration was highlighted):

MyClassFullPath.swift:11:141: Expected '>' to complete generic argument list

Second efford:

class ServerConfiguredObjectsViewController 
    <ServerConfiguredObjectClass:ServerConfiguredObject, 
     ServerConfiguredObjectsStorageClass: 
         ServerConfiguredObjectsStorage<ServerConfiguredObjectClass>> : UIViewController

Swift compiler error(String with class declaration wasn't highlighted):

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

How do you think. Is it a swift BUG in the second case? (I think swift must highlight the declaration string at least.)

PS

I'm able to understand why it doesn't work. But my aim is to make it works. I'll be thankful for any recommendations.

Anyway, Thanks for attention.

The first part of your question is easy to answer: the swift compiler should never just crash, no matter what you throw art it. File a bug report with Apple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM