gpt4 book ai didi

IOS 按日期时间排序键值

转载 作者:行者123 更新时间:2023-11-29 02:59:05 27 4
gpt4 key购买 nike

我是 IOS 开发的新手。我想按 NSDate 对 NSMutable 字典进行排序,但无法成功。以下是我的代码:

- (void)handleSelectedAssets:(NSMutableDictionary *)selectedAssets {

NSMutableArray *UUIDs = [NSMutableArray array];
assetCount = 0;
NSMutableDictionary *yourMutableDictionary = [[NSMutableDictionary alloc] init];
for (NSString *key in selectedAssets) {
NSURL *assetURL = [selectedAssets objectForKey:key];

ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
NSString *UUID = [self getUUID];
UploadAsset *ua = [[[UploadAsset alloc] initWithAssetURL:assetURL] autorelease];

ua.delegate = self;
ua.UUID = UUID;
ua.uploadURL = self.uploadURL;
ua.chunkSize = chunkSize;
ua.qualityPercent = qualityPercent;

[self.uploads addObject:ua];

//[self.uploadAssets setObject:assetURL forKey:UUID];

[UUIDs addObject:UUID];

NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate];

[yourMutableDictionary setObject:UUID forKey:myDate]; // want to sort this dictionary by key.


assetCount++;
if ([selectedAssets count] == assetCount) {
// After sorting, I want to assign all value to below sendSelectedUUIDs.

// NSLog(@"Sort %@",sValues);
[self sendSelectedUUIDs:UUIDs];
//[self startUploaderQueue];
[self handleUploads:ALAssetTypePhoto];
[self handleUploads:ALAssetTypeVideo];
}
} failureBlock:^(NSError *error) {
NSLog(@"ALAssetsLibrary Error");
}];
}


}

最佳答案

试试这个....

-(NSMutableArray *)sortByDate:(NSMutableArray *)array objectforKey:(NSString *)key ascending:(BOOL)asc{

NSSortDescriptor *sortDescriptor;
sortDescriptor=[[NSSortDescriptor alloc]initWithKey:key ascending:asc];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [array sortedArrayUsingDescriptors:sortDescriptors];
return [[NSMutableArray alloc]initWithArray:sortedArray];
}

关于IOS 按日期时间排序键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23512780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com