Cov kev xaiv nrawm yog dab tsi?
Cov kev xaiv nrawm yog dab tsi?

Video: Cov kev xaiv nrawm yog dab tsi?

Video: Cov kev xaiv nrawm yog dab tsi?
Video: yog hmoov dab tsi tub huas xyooj 2024, Kaum ib hlis
Anonim

Ib xaiv tau hauv Swift yog ib hom uas tuaj yeem tuav tus nqi lossis tsis muaj nqi. Xaiv tau yog sau los ntawm append ib? rau txhua hom: Ua ntej koj qhib nws (lossis "unwrap" hauv hom lus ntawm xaiv tau ) koj yuav tsis paub tias nws muaj qee yam lossis tsis muaj dab tsi.

Ntawm no, vim li cas peb thiaj siv cov kev xaiv hauv Swift?

Koj siv cov kev xaiv : Rau cov khoom uas tsis muaj tus nqi pib (thiab tsis muaj nqi pib hauv tus tsim), xws li cov khoom siv hluav taws xob. Koj kuj tuaj yeem tsim cov cuab yeej uas tsis tseem ceeb rau kev ua haujlwm ntawm qee qhov piv txwv, piv txwv li. xaiv tau . Thaum ib txoj kev uas yuav tsum tau xa rov qab tus nqi poob.

Ib tug kuj yuav nug, dab tsi yog nil hauv Swift? tsis muaj tau piav qhia hauv Apple docs li: txhais tau tias "tsis muaj khoom siv tau." Yog tias koj tshiab rau programming tsis muaj tsuas yog txhais tau hais tias qhov sib txawv (qee zaum hu ua khoom) yog khoob thiab tsis muaj nqi. Yog tias koj muaj keeb kwm yav dhau los hauv programming tsis muaj tuaj yeem xav txog qhov zoo tshaj plaws raws li kev hloov pauv zoo li rau null.

Hauv qhov no, kuv yuav ua li cas tshem tawm cov kev xaiv hauv Swift?

Koj ua tau unwrap xaiv nyob rau hauv peb-thiab-ib-ib-txoj kev: Nrog quab yuam unwrapping , siv yog tias [ xaiv tau ] != nil thiab [ xaiv tau ]! Nrog xaiv tau kev khi, siv yog cia [tsis yog- xaiv tau ] = [ xaiv tau ] {

Dab tsi yog tuple hauv Swift?

Tuples hauv Swift Nyob hauv qhov chaw ntawm phau ntawv txhais lus thiab cov qauv: lawv tuav cov ntaub ntawv tshwj xeeb (xws li cov qauv) tab sis tuaj yeem tsim los ntawm ya (xws li phau ntawv txhais lus). Lawv feem ntau yog siv los rov qab ntau yam txiaj ntsig los ntawm kev hu ua haujlwm.

Pom zoo: