Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[220712] TIL #36

Closed
Taehyeon-Kim opened this issue Jul 11, 2022 · 0 comments
Closed

[220712] TIL #36

Taehyeon-Kim opened this issue Jul 11, 2022 · 0 comments
Assignees

Comments

@Taehyeon-Kim
Copy link
Owner

Taehyeon-Kim commented Jul 11, 2022

๐Ÿชด Summary

  1. AutoLayout Priority
  2. ViewController ์ข…๋ฅ˜ (UIAlertController - Alert, Action Sheet - ์ค‘์‹ฌ์œผ๋กœ ๋ณธ)
  3. Literal
  4. Playground
  5. ํ•จ์ˆ˜, ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜๊ฐ’

๐Ÿ—‚ Memo

TIL์— ๋„ˆ๋ฌด ๋งŽ์€ ๋ฆฌ์†Œ์Šค๋ฅผ ๋“ค์ด์ง€ ๋ง™์‹œ๋‹ค.

AutoLayout Priority

  • hugging priority
  • resistance priority

์šฐ์„ ์ˆœ์œ„๋Š” ์ดํ›„์— ๋‹ค๋ฅธ ์•„ํ‹ฐํด์—์„œ ๋” ์ž์„ธํžˆ ์ •๋ฆฌํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค.

View ๋˜๋Š” Button์— Tag ๊ฐ’ ๋ถ€์—ฌ

UIView์—๋Š” tag๋ผ๋Š” ํ”„๋กœํผํ‹ฐ๊ฐ€ ์กด์žฌํ•œ๋‹ค. ํ•ด๋‹น ํ”„๋กœํผํ‹ฐ๋กœ ๊ฐ๊ฐ์˜ ์š”์†Œ๋ฅผ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋™์ผํ•œ ์š”์†Œ๋ฅผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์•ก์…˜์„ ์ฒ˜๋ฆฌํ•  ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-07-13 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 1 51 05

๋นจ๊ฐ„์ƒ‰ ๋ฐ•์Šค ๋ถ€๋ถ„์ด UIButton ํƒ€์ž…์ด๋ผ๊ณ  ํ•œ๋‹ค๋ฉด ๊ฐ๊ฐ์„ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด ๊ผฌ๋ฆฌํ‘œ๋ฅผ ๋ถ™์ธ๋‹ค๊ณ  ์ดํ•ดํ•˜๋ฉด ํŽธํ•  ๊ฒƒ ๊ฐ™๋‹ค. ์ง€๊ธˆ์€ tag ๊ฐ’์„ 1๋ถ€ํ„ฐ ์ˆœ์ฐจ์ ์œผ๋กœ ๋ถ™์˜€์ง€๋งŒ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค๋ฉด ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค์— ์ ‘๊ทผํ•˜๊ฑฐ๋‚˜ ๊ฐ’์„ ๊บผ๋‚ด์„œ ์‚ฌ์šฉํ•  ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด์„œ ๊ฐ๊ฐ์˜ Button์— ์•„๋ž˜์™€ ๊ฐ™์ด emotionButtonDidTapped์ด๋ผ๋Š” ๋™์ผํ•œ IBAction์„ ์—ฐ๊ฒฐํ•ด์ฃผ์—ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž. ๊ทธ๋Ÿผ ์–ด๋–ป๊ฒŒ ๊ตฌ๋ถ„์„ ํ•ด์•ผ ํ• ๊นŒ? ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ๊ฒ ์ง€๋งŒ tag๋ฅผ ์ด์š”ํ•˜๋ฉด ํŽธํ•˜๋‹ค. sender๋ผ๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜์— ์‹ ํ˜ธ๊ฐ€ ์ „๋‹ฌ๋˜์–ด ๋„˜์–ด์˜ฌํ…๋ฐ sender.tag๋กœ ์ ‘๊ทผํ•ด๋ณด๋ฉด ์–ด๋Š ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ๋Š”์ง€ tag ๋ฒˆํ˜ธ๋กœ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋‹ค. ์œ„์˜ ๊ทธ๋ฆผ์œผ๋กœ ์ƒ๊ฐํ•ด๋ณด๋ฉด ์ฒซ ๋ฒˆ์งธ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด sender.tag์— 1์ด ๋‹ด๊ฒจ ์žˆ์„ ๊ฒƒ์ด๋‹ค. ํ•ด๋‹น ์ •๋ณด๋กœ ์‹ ํ˜ธ๋ฅผ ๋ณด๋‚ธ ๊ฐ์ฒด๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ณ  ์›ํ•˜๋Š” ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ๋ฉด ๋  ๊ฒƒ์ด๋‹ค.

@IBAction func emotionButtonDidTapped(_ sender: UIButton) {
    let index = sender.tag
    self.emotions[index].increaseEmotionCount()
    emotionTitleLabels[index].text = self.configureEmotionTitleLabel(for: index)
}

ViewController ์ข…๋ฅ˜

UIAlertController (Alert, Action Sheet)

Human Interface Guidelines์™€ ์ž˜ ์—ฎ์–ด์„œ ๋ณด์ž.

  • ์‹œ์Šคํ…œ ์•Œ๋ฆผ
  • ๋ฐ”ํ…€ ์‹œํŠธ

Alert Action Style

  • Default
  • Destructive (๋นจ๊ฐ„์ƒ‰ ์ฒ˜๋ฆฌ)
  • Cancel (bold ์ฒ˜๋ฆฌ, ๋ถ„๋ฆฌ๋˜๋Š” ์˜์—ญ)

Alert Action๊ฐ€ ๋ฉ”๋‰ด ํ•˜๋‚˜ํ•˜๋‚˜๋ฅผ ์˜๋ฏธํ•œ๋‹ค๊ณ  ๋ด๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๋‹ค. cancel ์Šคํƒ€์ผ์˜ ๊ฒฝ์šฐ ์ž๊ธฐ ์ž๋ฆฌ์— ์•Œ์•„์„œ ๋ถ™๋Š”๋‹ค. 2๊ฐœ์˜ ๊ฒฝ์šฐ ์™ผ์ชฝ์— ๋ถ™๊ณ , 2๊ฐœ ์ด์ƒ์˜ ๊ฒฝ์šฐ ๊ฐ€์žฅ ์•„๋ž˜์— ๋ถ™๋Š”๋‹ค. cancel ์Šคํƒ€์ผ์€ 2๊ฐœ ์ด์ƒ ์„ค์ •ํ•  ์ˆ˜ ์—†๋‹ค.

Thread 1: "UIAlertController can only have one action with a style of UIAlertActionStyleCancel"

UIImagePickerController

  • ์‚ฌ์ง„์„ ์ฐ๊ณ , ๋™์˜์ƒ์„ ๋…นํ™”ํ•˜๊ณ , ์‚ฌ์šฉ์ž์˜ ๋ฏธ๋””์–ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ํ•ญ๋ชฉ์„ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•œ ์‹œ์Šคํ…œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ด€๋ฆฌ

UIActivityViewController

  • ๊ณต์œ  ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ
  • ๋ณต์‚ฌ, ์†Œ์…œ ๋ฏธ๋””์–ด ์‚ฌ์ดํŠธ์— ์ฝ˜ํ…์ธ  ๊ฒŒ์‹œ, ์ด๋ฉ”์ผ ๋˜๋Š” SMS๋ฅผ ํ†ตํ•œ ํ•ญ๋ชฉ ๋ณด๋‚ด๊ธฐ ๋“ฑ๊ณผ ๊ฐ™์€ ์—ฌ๋Ÿฌ ํ‘œ์ค€ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณต

UIMenuController

  • ์ž˜๋ผ๋‚ด๊ธฐ, ๋ณต์‚ฌ, ๋ถ™์—ฌ๋„ฃ๊ธฐ, ์„ ํƒ, ๋ชจ๋‘ ์„ ํƒ ๋ฐ ์‚ญ์ œ ๋ช…๋ น์— ๋Œ€ํ•œ ๋ฉ”๋‰ด ์ธํ„ฐํŽ˜์ด์Šค
  • iOS 16.0+ ๋ถ€ํ„ฐ๋Š” Deprecated ๋˜์–ด์„œ, ๋Œ€์‹  UIEditMenuInteraction์„ ์‚ฌ์šฉํ•˜๋ผ๊ณ  ํ•œ๋‹ค.

UIDocumentPickerViewController

  • ํŒŒ์ผ ์•ฑ๊ณผ ๊ด€๋ จ
  • ์•ฑ์˜ ์ƒŒ๋“œ๋ฐ•์Šค ์™ธ๋ถ€์— ์žˆ๋Š” ๋ฌธ์„œ ๋˜๋Š” ๋Œ€์ƒ์— ๋Œ€ํ•œ ์•ก์„ธ์Šค๋ฅผ ์ œ๊ณต

UIFontPickerViewController

  • ์ด๊ฒƒ์€ ์ฒ˜์Œ ๋ดค๋‹ค.
  • iOS13.0+
  • ์‹œ์Šคํ…œ์—์„œ ์ œ๊ณตํ•˜๊ฑฐ๋‚˜ ์‚ฌ์šฉ์ž๊ฐ€ ์„ค์น˜ํ•˜๋Š” ๊ธ€๊ผด์„ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค ๊ด€๋ฆฌ

UIColorPickerViewController

  • iOS14.0+
  • ์ƒ‰์ƒ ์„ ํƒ ๊ธฐ๋Šฅ

Literal

๋ฆฌํ„ฐ๋Ÿด์˜ ์ •ํ™•ํ•œ ์ •์˜๋ฅผ ๊ณต์‹ ๋ฌธ์„œ์—์„œ ์ฐพ์•„๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ ๋Š๋‚Œ์ด๋ผ๊ณ  ๋ณด๋ฉด ๋  ๊ฒƒ ๊ฐ™๋‹ค.

๋ฆฌํ„ฐ๋Ÿด์€ ์ˆซ์ž ๋˜๋Š” ๋ฌธ์ž์—ด๊ณผ ๊ฐ™์€ ์œ ํ˜• ๊ฐ’์˜ ์†Œ์Šค ์ฝ”๋“œ ํ‘œํ˜„์ž…๋‹ˆ๋‹ค. ๋ฆฌํ„ฐ๋Ÿด์€ ์ž์ฒด์ ์œผ๋กœ ์œ ํ˜•์ด ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ์— Swift๋Š” Literal์˜ ํƒ€์ž…์„ ์œ ์ถ”ํ•˜๋ ค๊ณ  ์‹œ๋„ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

42                  // Integer literal
3.14159          // Floating-point literal
"Hello, world!"  // String literal
/Hello, .*/      // Regular expression literal
true             // Boolean literal

์ด๋ฏธ์ง€ ๋ฆฌํ„ฐ๋Ÿด๊ณผ ์ƒ‰์ƒ ๋ฆฌํ„ฐ๋Ÿด๋„ ๊ฐ™์€ ๋Š๋‚Œ์ด์ง€ ์•Š์„๊นŒ ์ƒ๊ฐํ•œ๋‹ค.

  • #imageLiteral
  • #colorLiteral

Playground

์‹ค์ œ ๋งŒ๋“ค๊ณ  ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ ์ฝ”๋“œ ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด ์ƒ๊ฐ๋ณด๋‹ค ์‰ฝ์ง€ ์•Š์€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ฝ”๋“œ์˜ ํ…Œ์ŠคํŠธ ์šฉ๋„๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค.

ํ•จ์ˆ˜, ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜๊ฐ’

๋ฐ˜ํ™˜๊ฐ’์ด ์žˆ๊ณ  ์—†์Œ์— ๋”ฐ๋ผ ์ฝ”๋“œ๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค. ํ•จ์ˆ˜ ์ž˜ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ ์ง„์งœ ์ค‘์š”ํ•˜๋‹ค.

var numberSet: Set = [2,4,6,8,10]
var numberSet2: Set = [1,2,3,4,5]

numberSet.subtract(numberSet2)      // ๋ฐ˜ํ™˜๊ฐ’ X
numberSet.subtracting(numberSet2)   // ๋ฐ˜ํ™˜๊ฐ’ O

var numberArray = [1,2,3,4,5,6,7,8,9,10]
numberArray.shuffle()  // ๋ฐ˜ํ™˜๊ฐ’ X
numberArray.shuffled() // ๋ฐ˜ํ™˜๊ฐ’ O
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant