スウィフトの背景からフォアグラウンドに移動する場合、スウィフトの[nsObject copy]にはどのような方法が適していますか? スウィフトアレイをバックグラウンドからフォアグラウンドにコピー
は、Objective-Cの中に例えば、私たちは実行してバックグラウンドでALAssetsの長い配列(10,000のようなと言う)をループします:[alGroup enumerateAssetsUsingBlock:^(ALAsset *alPhoto, NSUInteger index, BOOL *stop)
{
// Here to make changes for speed up image loading from device library...
// =====================================================
// >>>>>>>>>>>>>>>>>>> IN BACKGROUND <<<<<<<<<<<<<<<<<<<
// =====================================================
if(alPhoto == nil)
{
c(@"number of assets to display: %d", (int)bgAssetMedia.count);
// c(@"All device library photos uploaded into memory...%@", bgAssetMedia);
dispatch_async(dispatch_get_main_queue(), ^(void)
{
// =====================================================
// >>>>>>>>>>>>>>>>>>> IN FOREGROUND <<<<<<<<<<<<<<<<<<<
// =====================================================
[ui hideSpinner];
if (_bReverse)
// Here we copying all the photos from device library into array (_assetPhotos)...
_assetPhotos = [[NSMutableArray alloc] initWithArray:[[[bgAssetMedia copy] reverseObjectEnumerator] allObjects]];
else
_assetPhotos = [[NSMutableArray alloc] initWithArray:[bgAssetMedia copy]];
// NSLog(@"%lu",(unsigned long)_assetPhotos.count);
if (_assetPhotos.count > 0)
{
result(_assetPhotos);
}
});
} else {
// if we have a Custom album, lets remove all shared videos from the Camera Roll
if (![self isPhotoInCustomAlbum:alPhoto])
{
// for some reason, shared glancy videos still show with 00:00 minutes and seconds, so remove them now
BOOL isVideo = [[alPhoto valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypeVideo];
int duration = 0;
int minutes = 0;
int seconds = 0;
// NSString *bgVideoLabel = nil;
if (isVideo)
{
NSString *strduration = [alPhoto valueForProperty:ALAssetPropertyDuration];
duration = [strduration intValue];
minutes = duration/60;
seconds = duration % 60;
// bgVideoLabel = [NSString stringWithFormat:@"%d:%02d", minutes, seconds];
if (minutes > 0 || seconds > 0)
{
[bgAssetMedia addObject:alPhoto];
}
} else {
[bgAssetMedia addObject:alPhoto];
}
}
}
// NSLog(@"%lu",(unsigned long)bgAssetMedia.count);
}];
をその後、我々は更新するフォアグラウンドに切り替えますこれらの行は、上記のスニペットであるのUIViewController、:
_assetPhotos = [[NSMutableArray alloc] initWithArray:[bgAssetMedia copy]];
「コピー」機能は、私たちはすぐに再び配列をループすることなく、バックグラウンドからフォアグラウンドにメモリをマーシャリングすることができ、黒魔術でした。 Swiftにも同様の方法がありますか?おそらく、このような何か:
_assetPhotos = NSMutableArray(array: bgAssetMedia.copy())
は背景から前景にメモリポインタを渡すために今スウィフトスレッド安全ですか?新しいプロトコルは何ですか?ありがとう -