我很擔心如何在swift中設置網址。我想在swift上使用SDWebImage下載並顯示圖像。我已將url設置爲如下,但無法返回圖片。我找不到如何自動獲取樣式和基本名稱。如何通過回形針在rails上更新swift中的圖片數據?
http://localhost:3000/assets/photos/:id/:style/:basename.:extension
我一直在寫服務器端的RoR,並通過回形針上傳圖片。
謝謝你的幫助。
Rails的
class User < ActiveRecord::Base
has_many :questions
has_many :answers
has_attached_file :photo,
:styles => { medium: "300x300>", thumb: "100x100>" },
:url => "/assets/photos/:id/:style/:basename.:extension",
:path => "#{Rails.root}/public/assets/photos/:id/:style/:basename.:extension"
validates_attachment :photo, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] }
end
斯威夫特
let cell = tableView.dequeueReusableCellWithIdentifier("iconIdentifier", forIndexPath: indexPath) as! IconTableViewCell
let imageURL = NSURL(string: "http://localhost:3000/assets/photos/:id/:style/:basename.:extension")
cell.iconView.sd_setImageWithURL(imageURL!)
return cell