Simple Swift file download with URL

前端 未结 2 1267
暗喜
暗喜 2021-02-10 01:25

So I have the URL as string (in this case a JPG but would like a general procedure for any file type if possible) and I have the file path as string where I want to save the fil

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-10 01:53

    With Swift 4, the code will be:

    if let url = URL(string: myURLstring) {
        let imageDataFromURL = try Data(contentsOf: url)
    }
    

提交回复
热议问题