我用来在外部 API 上Alamofire调用.put方法。JSON在 Postman 中,我可以成功地以以下格式传递原始数据,其中每个项目都包含一个 ID 和一个数量。:
[{
"id":"176",
"quantity":"2"
}, {
"id":"178",
"quantity":"1"
}]
Run Code Online (Sandbox Code Playgroud)
卷曲示例:
PUT /cart HTTP/1.1
Host: someapi.biz
x-api-key: somekey
x-auth-token: sometoken
Content-Type: application/json
cache-control: no-cache
Postman-Token: sometoken
[{
"id":"176",
"quantity":"2"
}, {
"id":"178",
"quantity":"1"
}]------WebKitFormBoundary7MA4YWxkTrZu0gW--
Run Code Online (Sandbox Code Playgroud)
我很快就无法弄清楚如何将这些信息正确格式化为 Alamofire 的一组参数。
for item in OrderedItems {
let rowItem: JSON = ["id" : item.ID, "quantity" : item.Quantity]
??
}
Run Code Online (Sandbox Code Playgroud) 我有一个函数可以动画 UIImageView 从一组坐标到屏幕另一侧的另一组坐标的移动。在动画期间,我想记录我点击图像时的位置。当我拨打这样的电话时,我得到的不是当前位置:
var rippleImage = UIImageView()
//example animation block
UIView.animate(withDuration: 6, delay: 0.0, options: [.curveLinear, .allowUserInteraction], animations: {
self.rippleImage.frame = CGRect(x: (xaxis - 500) , y: (yaxis - 500) , width: (self.rippleImage.frame.width + 1000), height: (self.rippleImage.frame.height + 1000))
self.rippleImage.alpha = 0.1
}, completion: nil )
//sample button click function to capture location
@objc func pianoKeyButtonTapped(sender: UIImageView) -> [String] {
// get and animate current ripple
let currentRippleLocation = self.rippleImage.frame
print(currentRippleLocation)
}
Run Code Online (Sandbox Code Playgroud)
在每种情况下,我都会得到相同的目的地位置,如下所示:
(-342.5, 67.0, 1060.0, 1060.0)
Run Code Online (Sandbox Code Playgroud)