2016-11-10 43 views
0

的我用于返回我使用“MapPoints”(从DB)的阵列下面更改语法

extension Sequence where Iterator.Element == MapPoints { 
    func makeJSON() -> JSON { 
     return .array(self.map { $0.makeJSON() }) 
    } 

    func makeResponse(request: Request) throws -> Response { 
     return try makeJSON().makeResponse() 
    } 
} 

现在这给出了一个错误“实例构件‘数组’不能在类型‘JSON’用“

有谁能告诉我应该怎么做?

回答

1

通过初始化程序JSON(array: [T])

extension Sequence where Iterator.Element == Post { 
    func makeJSON() throws -> JSON { 
    return try JSON(map { try $0.makeJSON() }) 
    } 

    func makeResponse(request: Request) throws -> Response { 
    return try makeJSON().makeResponse() 
    } 
}