NSOperation thiab NSOperationQueue yog dab tsi hauv iOS?
NSOperation thiab NSOperationQueue yog dab tsi hauv iOS?

Video: NSOperation thiab NSOperationQueue yog dab tsi hauv iOS?

Video: NSOperation thiab NSOperationQueue yog dab tsi hauv iOS?
Video: Multithreading в swift с нуля: урок 15 - Operation & OperationQueue & OperationBlock 2024, Kaum ib hlis
Anonim

NSOperationQueue . NSOperationQueue tswj kev ua tiav ntawm kev ua haujlwm. Nws ua raws li qhov tseem ceeb hauv kab, xws li kev ua haujlwm tau ua tiav nyob rau hauv kwv yees li First-In-First-Out yam, nrog qhov tseem ceeb dua ( NSOoperation . queuePriority) cov uas tau dhia ua ntej ntawm qhov tseem ceeb qis dua.

Hauv qhov no, qhov txawv ntawm GCD thiab NSOperationQueue hauv iOS yog dab tsi?

GCD yog qib qis C-raws li API. NSOoperation thiab NSOperationQueue yog Lub Hom Phiaj-C chav kawm. NSOperationQueue yog Lub hom phiaj C qhwv dua GCD . Yog koj siv NSOoperation , ces koj yog implicitly siv Grand Central Dispatch.

Tsis tas li ntawd, leej twg yog txoj hauv kev ua kom tau txais txiaj ntsig zoo hauv iOS? Muaj peb txoj hauv kev kom ua tiav concurrency hauv iOS:

  • Xov.
  • Dispatch queues.
  • Kev ua haujlwm queues.

Kuj paub, NSOperation hauv Swift yog dab tsi?

NSOoperation yog chav kawm paub daws teeb meem uas tsis tuaj yeem siv ncaj qha yog li koj yuav tsum siv NSOoperation subclass. Hauv iOS SDK, peb tau muab ob qho tib si subclasses ntawm NSOoperation . Cov chav kawm no tuaj yeem siv ncaj qha, tab sis koj tuaj yeem ua tau subclass NSOoperation thiab tsim koj tus kheej chav kawm los ua cov haujlwm.

Dab tsi yog concurrency hauv iOS?

Hloov Kho Hoob Kawm: iOS Concurrency nrog GCD & Kev Ua Haujlwm. Concurrency yog ib txoj hauv kev zoo los hais tias "khiav ntau dua ib txoj haujlwm tib lub sijhawm". Concurrency yog siv ntau zaus rau iOS no pab kiag li lawm yog li koj tuaj yeem khiav dej num hauv keeb kwm yav dhau (xws li rub tawm lossis ua cov ntaub ntawv) thaum koj khaws koj cov neeg siv interface teb.

Pom zoo: