正如文档所说" 您确定可选项确实包含值,您可以通过添加感叹号(!)来访问其基础值 "
那么为什么UIViewController使用init方法呢
init(nibName nibName: String!,bundle nibBundle: NSBundle!)
并告诉我" 如果指定nil,则nibName属性设置为nil. "
为什么init(nibName nibName: String?,bundle nibBundle: NSBundle?)不用呢?
我对此很困惑.
我想使用__block变量来获取块中的值.但是当阻塞时,__block变量似乎是零.为什么会这样?
NSString *fileName = [Tools MD5Encode:url];
__block NSString *filePath = nil;
[fileList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *aFileName = obj;
if ([aFileName isEqualToString:fileName]) {
NSString *path = [VERSIONS_INFO_DATA_DIRECTORY stringByAppendingPathComponent:aFileName];
filePath = path;
NSLog(@"filePath1 %@", filePath);
*stop = YES;
}
}];
//NSLog(@"filePath2 %@", filePath);
//filePath seems to be nil
return filePath;
Run Code Online (Sandbox Code Playgroud)
当我将代码更改为[路径复制]时,它可以工作.但我不知道这是不是一个好主意.任何决定?
NSString *fileName = [Tools MD5Encode:url];
__block NSString *filePath = nil;
[fileList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *aFileName = obj;
if ([aFileName isEqualToString:fileName]) { …Run Code Online (Sandbox Code Playgroud) 我想使用AFNetwork下载多个文件,但我不知道如何实现这个?如您所见,我创建了一个操作数组并在其中添加了3个任务
NSMutableArray *operations = [NSMutableArray array];
NSArray *requestArray = @[ @"...task1.zip", @"task2.zip", @"task3.zip" ];
for (int i = 0; i < 3; i++) {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[requestArray objectAtIndex:i]]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[[requestArray objectAtIndex:i] lastPathComponent]];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation setDownloadProgressBlock:^(NSUInteger …Run Code Online (Sandbox Code Playgroud)