본문 바로가기 메뉴 바로가기

Peppo

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

Peppo

검색하기 폼
  • 분류 전체보기 (221)
    • Story (13)
    • iOS (143)
      • Error (11)
    • 알고리즘 (43)
    • ETC (7)
    • React-Native (0)
    • CS (Computer science) (3)
  • 방명록

Swift compactMap flatMap 차이 (1)
[Swift] compactMap, flatMap

오늘은 고차함수 compactMap과 flatMap에 대해 공부해 보려고 합니다. 먼저 예시로 바로 들어볼게요. 아래와 같은 배열이 있습니다. let arr = [nil, 1, 2, nil, nil, 5] 여기서 nil을 없애고 배열을 반환하고 싶으면 ? 이때 compactMap, flatMap 을 사용하면 돼요! let arr = [nil, 1, 2, nil, nil, 5] let compactMap1 = arr.compactMap { $0 } let flatMap1 = arr.flatMap { $0 } print("compact:\(compactMap1)") // compact:[1, 2, 5] print("flatMap:\(flatMap1)") // flatMap:[1, 2, 5] 이렇게 맛보기만 ..

iOS 2022. 9. 1. 00:12
이전 1 다음
이전 다음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
  • Peppo's Github
TAG
  • iOS error
  • Swift ModernRIBs
  • Swift joined
  • RIBs tutorial
  • removeLast()
  • Swift init
  • Swift 프로퍼티
  • Swift 알고리즘
  • Swift 프로그래머스
  • Swift RIBs
  • Swift
  • Class
  • Swift Leetcode
  • Swift Error Handling
  • swift (programmers)
  • swift programmers
  • Swift inout
  • swift 고차함수
  • swift reduce
  • swift protocol
  • Combine: Asynchronous Programming with Swift
  • Swift final
  • 2023년 회고
  • 원티드 프리온보딩
  • Swift joined()
  • RTCCameraVideoCapturer
  • ios
  • CS 네트워크
  • swift property
  • Swift 내림차순
more
«   2025/05   »
일 월 화 수 목 금 토
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바