iOS 工作中遇到的问题 (三)

异步获取数据

dispatch_async(dispatch_get_global_queue(0, 0), ^{ 
// 处理耗时操作的代码块... 

//通知主线程刷新 
dispatch_async(dispatch_get_main_queue(), ^{ 
//回调或者说是通知主线程刷新, 
}); 

});

SDWebImage手动清除缓存的方法

1.找到SDImageCache类2.添加如下方法:
- (float)checkTmpSize { float totalSize = 0; NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath]; for (NSString *fileName in fileEnumerator) { NSString *filePath = [diskCachePath stringByAppendingPathComponent:fileName]; NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; unsigned long long length = [attrs fileSize]; totalSize += length / 1024.0 / 1024.0; } // NSLog(@"tmp size is %.2f",totalSize);  return totalSize; }

新版的SDImageCache类,已增加此方法
[[SDImageCache sharedImageCache] getSize];

3.在设置里这样使用
#pragma 清理缓存图片 - (void)clearTmpPics { [[SDImageCache sharedImageCache] clearDisk]; // [[SDImageCache sharedImageCache] clearMemory];//可有可无  DLog(@"clear disk"); float tmpSize = [[SDImageCache sharedImageCache] checkTmpSize]; NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize] : [NSString stringWithFormat:@"清理缓存(%.2fK)",tmpSize * 1024]; [configDataArray replaceObjectAtIndex:2 withObject:clearCacheName]; [configTableView reloadData]; }


使用SDWebimage下载图片

#import "UIImageView+WebCache.h"
[self.icon sd_setImageWithURL:[NSURL URLWithString:reportTextModel.imageName]];

在mac下MP3转caf

afconvert /System/Library/Sounds/Submarine.aiff     ~/Desktop/sub.caf -d ima4 -f caff -v

给后台传json字符串

    NSMutableArray *array = [NSMutableArray array];
    NSDictionary *dict = @{@"productId": @"P0000002",@"count":@1,@"price":@50};
    [array addObject:dict];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"areward"] = jsonString;

找出数组的相同字符串

// 下面数组中包含了两个"你好",两个"我好",两个"好的"
    // array1 是需要处理的目标数组
    NSMutableArray *array1 = [NSMutableArray arrayWithObjects:@"你好",@"我好",@"他好",@"你好",@"我好",@"不好",@"好的",@"好的", nil];
    // array2 是去掉相同元素后的数组
    NSMutableArray *array2 = [NSMutableArray array];
    
    for (NSString *str in array1) {//////遍历数组1
        if (![array2 containsObject:str]) {//判断数组2中有没有该元素,如果没有就添加到数组2中,该步骤就是去掉数组中的重复元素
            [array2 addObject:str];
        }
    }
    NSLog(@"array1Count = %ld",array1.count);
    NSLog(@"array2Count = %ld",array2.count);

金钱符号

你可能感兴趣的:(iOS 工作中遇到的问题 (三))