๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“Œ Language/Swift

[Swift] toggle์„ ์ด์šฉํ•˜์—ฌ Bool๊ฐ’ ์‰ฝ๊ฒŒ ๋ฐ”๊พธ๊ธฐ

by Fomagran ๐Ÿ’ป 2020. 11. 13.
728x90
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š” Foma ์ž…๋‹ˆ๋‹ค!!

 

์˜ค๋Š˜ ์•Œ์•„๋ณผ ๊ฑด toggle()์ด๋ผ๋Š” ๋ฉ”์†Œ๋“œ์ž…๋‹ˆ๋‹ค.

 

 

ํ‰์†Œ์— Boolean๊ฐ’์„ ์‚ฌ์šฉํ•˜๋ฉด true์ผ๋•Œ false์ผ๋•Œ๋ฅผ ์•Œ์•„๋‚ด์–ด ์‚ฌ์šฉํ•˜๊ณค ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

ํ•˜์ง€๋งŒ toggle() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ˜„์žฌ Boolean๊ฐ’์„ ๋ฐ˜๋Œ€๋กœ ๋ฐ”๊พธ์–ด์ค๋‹ˆ๋‹ค.

 

๊ณ ๋กœ ํ˜„์žฌ์˜ Boolean๊ฐ’์„ ๋ชฐ๋ผ๋„ ๋ฐ˜๋Œ€๋กœ ๋ฐ”๊ฟ”์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์•„์ฃผ ์œ ์šฉํ•œ ๊ฒƒ์ด์ฃ !!

 

์˜ˆ์‹œ์™€ ํ•จ๊ป˜ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

ํ‰์†Œ ์•„๋ž˜์™€ ๊ฐ™์ด boolean๊ฐ’์„ ์•Œ์•„๋‚ผ ๋• if๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ˜๋Œ€๋กœ ๋ฐ”๊พธ๊ณค ํ–ˆ๋Š”๋ฐ์š”

 

์•„๋ž˜์™€ ๊ฐ™์ด toggle()์„ ์‚ฌ์šฉํ•˜๋ฉด boolean๊ฐ’์ด ์•Œ์•„์„œ ๋ฐ˜๋Œ€๋กœ ๋ฐ”๋€Œ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค!!!

]

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€