Tag: swift

Swift TRON内容类型HeaderBuilder语法

我正在使用TRON来访问基于ruby on rails的api,我觉得我的问题是因为标题没有正确的信息。 我一直在使用TRON的HeaderBuilder语法,但却无法真正看到语法需要的内容。 我的rails错误是在尝试从特定控制器操作获取数据时 [active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.25ms) Filter chain halted as :ensure_valid_accept_media_type rendered or redirected Completed 406 Not Acceptable in 61ms (Views: 30.0ms | ActiveRecord: 2.7ms | Solr: 0.0ms) 在xcode中,我使用rest类型控制器来获取json public class DataController { static let tron = TRON(baseURL: GlobalVariables().baseURL) class Fetched: JSONDecodable { let response: JSON required init(json: JSON) throws […]

Swift相当于Ruby的“each_cons”

ruby Ruby有each_cons可以像这样使用 class Pair def initialize(left, right) @left = left @right = right end end votes = [“a”, “b”, “c”, “d”] pairs = votes.each_cons(2).map { |vote| Pair.new(*vote) } p pairs # [#, #, #] 迅速 swift中的代码相同,但没有each_cons函数 struct Pair { let left: String let right: String } let votes = [“a”, “b”, “c”, “d”] var pairs […]