【发布时间】:2014-08-29 21:46:41
【问题描述】:
我是 Swift 编码的新手,我对 Objective C 没有太多经验,所以我尝试从网络 (csv) 下载文件并将其转储到根程序目录中。
很遗憾,尽管我正在学习 ObjectiveC 中 http://www.appcoda.com/background-transfer-service-ios7/ 的教程,但我在 Swift 中找不到任何操作教程。
这可能是非常基本的(并且很抱歉),但我正在尝试在 Swift 中创建一个类来替换 ObjectiveC 中 FileDownloadInfo 类的实现。 (如果有人有本教程的 Swift 示例,那将非常有帮助。
ObjectiveC 中的实现是:
@implementation FileDownloadInfo
-(id)initWithFileTitle:(NSString *)title andDownloadSource:(NSString *)source{
if (self == [super init]) {
self.fileTitle = title;
self.downloadSource = source;
self.downloadProgress = 0.0;
self.isDownloading = NO;
self.downloadComplete = NO;
self.taskIdentifier = -1;
}
return self;
}
@end
然后通过
填充 FileDownloadArray-(void)initializeFileDownloadDataArray{
self.arrFileDownloadData = [[NSMutableArray alloc] init];
[self.arrFileDownloadData addObject:[[FileDownloadInfo alloc] initWithFileTitle:@"iOS Programming Guide" andDownloadSource:@"https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/iphoneappprogrammingguide.pdf"]];
}
我在 Swift 类中创建了以下内容,但当然没有功能 - 我如何修改它以使我能够以与上述相同的方式填充数组?
import UIKit
class FileDownloadInfo: NSObject {
var fileTitle: NSString
var downloadSource: NSString
var downloadTask: NSURLSessionDownloadTask?
var taskResumeData: NSData?
var downloadProgress: Double
var isDownloading: Bool
var downloadComplete: Bool
var taskIdentifier: Int
init(initWithFileTitle title: NSString, andDownloadSource source: NSString) {
self.fileTitle = title
self.downloadSource = source
self.downloadProgress = 0.0
self.isDownloading = false
self.downloadComplete = false
self.taskIdentifier = -1
}
}
【问题讨论】:
标签: ios swift nsurlsession