I'm new to coding for Swift and I don't have much experience of Objective C so am trying to download a file from the web (csv) and dump it into the root program directory.
Unfortunately I can't find any how-to tutorial in Swift although I am working through the tutorial at http://www.appcoda.com/background-transfer-service-ios7/ which is in ObjectiveC.
This may be really basic (and apologies) but I'm trying to create a class in Swift replacing the implementation of the FileDownloadInfo class in ObjectiveC. (If anyone has a Swift example of the tutorial, that would be REALLY helpful.
The implementation in ObjectiveC is:
@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
A FileDownloadArray is then populated via
-(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"]];
}
I've created the following in a Swift class, but of course there's no function - how do I amend this to enable me to populate an array in the same way as above?
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
}
}