简体   繁体   English

声明带有2个相关泛型类型的swift类

[英]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. 而且我还将创建很多这样的列表,并将它们显示在单独的ViewController中。

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: 我的目标是这样声明viewController:

    typealias CompetitionsViewController = ServerConfiguredObjectsViewController <Competition, Competitions>

So I've declared View controller and added collection class and collection item class into template. 因此,我声明了View controller并将集合类集合项类添加到模板中。 And I've got an error. 而且我有一个错误。

First efford: 第一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 MyClassFullPath.swift:11:141:期望使用'>'来完成通用参数列表

Second efford: 二等奖:

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

Swift compiler error(String with class declaration wasn't highlighted): Swift编译器错误(带有类声明的字符串未突出显示):

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1 命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc失败,退出代码为1

How do you think. 你怎么想。 Is it a swift BUG in the second case? 在第二种情况下,它是不是很快的错误? (I think swift must highlight the declaration string at least.) (我认为swift必须至少突出显示声明字符串。)

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. 向Apple提交错误报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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