[Swift] URL Encoding을 위한 CharacterSet 살펴보기

urlQueryAllowed 외에도 가능한 URL 인코딩 옵션을 알아봅시다

TL; DR;

url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
https://github.com/sujinnaljin?tab=repositoriesurlQueryAllowed
https://github.com/sujinnaljin?tab=repositories
urlFragmentAllowed
https://github.com/sujinnaljin?tab=repositories
urlHostAllowed
https%3A%2F%2Fgithub.com%2Fsujinnaljin%3Ftab=repositories
urlPathAllowed
https%3A//github.com/sujinnaljin%3Ftab=repositories
urlPasswordAllowed
https%3A%2F%2Fgithub.com%2Fsujinnaljin%3Ftab=repositories
urlUserAllowed
https%3A%2F%2Fgithub.com%2Fsujinnaljin%3Ftab=repositories%

들어가기 전에

https%3A%2F%2Fgithub.com%2Fsujinnaljin%3Ftab=repositories
url.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

addingPercentEncoding(withAllowedCharacters:)

URLEncoding CharacterSet

urlUserAllowed (15개)

! $ & \ ( ) * + , - . ; = _ ~

urlPasswordAllowed (15개)

! $ & \ ( ) * +  - . ; = _ ~

urlPathAllowed (17개)

! $ & \ ( ) * +  - . / : = @ _ ~

urlHostAllowed (18개)

! $ & \ ( ) * +  - . : ; = [ ] _ ~

urlFragmentAllowed (19개)

! $ & \ ( ) * +  - . / : ; = ? @ _ ~

urlQueryAllowed (19개)

! $ & \ ( ) * +  - . / : ; = ? @ _ ~

보오너스

urlQueryAllowed

urlFragmentAllowed

urlHostAllowed

urlPathAllowed

urlUserAllowed

urlPasswordAllowed

참고

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store