SlideShare a Scribd company logo
1 of 62
Download to read offline
NSMutableCharacterSet
Natalie
2018/07/18
NSMutableCharacterSet
NSMutableCharacterSet
宣告⼀一個接⼝口以 管理理可修改的Unicode字符集
可以在NSRange的數值範圍或者 strings 的字符中添加或刪除 mutable
character set 中的字符
NSMutableCharacterSet沒有定義primitive methods
它的⼦子類類必須實現此類類和NSCharacterSet的所有⽅方法,還必須實現mutableCopy(with:)
與Core Foundation的CFMutableCharacterSet是 “toll-free bridged”
NSCopying Protocol的method
並不是所有的對應類類型間都可⾃自動轉換
NSRunloop與CFRunLoop,
NSBundle與CFBundle,
NSDateFormatter與CFDateFormatter之間都不⽀支持的
Toll-Free Bridging
Toll-Free Bridging是指在某些
Core Foundation框架和
Foundation框架相配對的Data
Type間,可⾃自動轉換使⽤用的機制
Cocoa框架中的⼤大部分NS開頭的類類在CF
中都有對應的類類型存在
->NS是對CF在更更⾼高層⾯面的⼀一個封裝
Toll-Free Bridging
必須使⽤用顯式轉換
// Remark: Swift strings/collections 是 value types ⽽而 Foundation types 是 reference types
Method
取得 Standard Character Sets
•alphanumeric

•capitalizedLetter

•control 

•decimalDigit

•decomposable 

•illegal 

•letter 

•lowercaseLetter 

•newline

•nonBase 

•punctuation 

•symbol 

•uppercaseLetter 

•whitespaceAndNewline

•whitespace
alphanumeric - 回傳包含 L *,M *和N *字符的字符集

capitalizedLetter -回傳包含Lt字符的字符集

control -回傳包含 Cc和Cf字符的字符集

decimalDigit - 回傳包含⼗十進制數類類字符的字符集

decomposable - 以Unicode編碼標準3.2版中“標準分解”的定義,

回傳包含單個Unicode字符的字符集,也可以為字符sequences

(例例如帶有重⾳音的字⺟母)

illegal - 回傳包含非字符或未在Unicode 3.2版中定義的字符集

letter - 回傳包含 L *&M *中的字符的字符集

lowercaseLetter -回傳包含 Ll中字符的字符集

newline -回傳包含換⾏行行符的字符集

(U + 000A~U + 000D,U + 0085,U + 2028和U + 2029)

nonBase - 回傳包含 M *中字符的字符集

punctuation - 回傳包含 P *中字符的字符集

symbol -回傳包含S *中字符的字符集。

uppercaseLetter -回傳包含Lu和Lt中字符的字符集。

whitespaceAndNewline- 回傳包含 Z *,U + 000A~U + 000D和U + 0085中字符的字符集

whitespace - 回傳包含Zs和CHARACTER TABULATION(U + 0009)中字符的字符集
The Unicode Standard. Unicode Consortium. July 2018
REF:Unicode character property
取得 Standard Character Sets
•alphanumeric:普通字符 + 數字 + 可分解字符

•capitalizedLetter:⾸首字⼤大寫

•control :控制符

•decimalDigit:數字(包括全型數字)

•decomposable :可分解(通過組合多個字符形成的字符)

•illegal :非字符+非法字符

•letter :普通字符(字⺟母,假名,漢字等)

•lowercaseLetter:⼩小寫 

•newline:換⾏行行

•nonBase :非基礎( M *中的字符)
•punctuation :標點

•symbol :符號(Unicode Private Use Area中的字符除外)

•uppercaseLetter :⼤大寫

•whitespaceAndNewline:空格+換⾏行行

•whitespace :空格
創建⾃自定義字符集
回傳包含指定字串串中的字符集
回傳包含指定Unicode值範圍內的字符集
回傳包含由bitmap representation決定的字符集
回傳從存儲在指定路路徑⽂文件中的bitmap
representation中讀取的字符集
😺
添加和刪除字符
加入在指定Unicode值範圍內的字符
刪除在指定Unicode值範圍內的字符
加入指定字串串中的字符
刪除指定字串串中的字符
合併字符集
反轉字符集
回傳指定字符以外的字符集
反轉字符集
NSCharacterSetNSCharacterSet
要⽤用CharacterSet
NSMutableCharacterSet 不能⽤用
消失的NSMutableCharacterSet
在這之前...
Unicode 中每⼀一個字元都可以被解釋為⼀一個或多個 unicode scalars。 字元
的 unicode scalars是⼀一個唯⼀一的 21 位元數字 (和名稱),例例如U+0061表示
⼩小寫的拉丁字⺟母 A ("a"),U+1F425表示⼩小雞表情 (“🐥”)。

Unicode Scalar相當於UTF-32的編碼⽅方式。
當 Unicode 字串串被寫進程式本⽂文檔或其他儲存結構當中,這些 unicode
scalars也可以按照 Unicode 定義的格式之⼀一進⾏行行編碼。其包括UTF-8(以
8 位元代碼單元進⾏行行編碼) 和UTF-16(以 16 位元代碼單元進⾏行行編碼)。

Unicode Scalar
在 Swift 中,字串串和字串串串串都是基於 Unicode Scalar建立的,採⽤用21位⼆二進
制進⾏行行編碼,共17個平⾯面(除了了基本多⽂文種平⾯面中的 UTF-16 代理理對碼位
外,即U+D800⾄至U+DFFF的編碼空間),也就是說編碼範圍是U+0000-
U+D7FFF 或者 U+E000-U+10FFFF
獲取Unicode Scalar
NSCharacterSet部分Method
創建字串串集
NSCharacterSet
創建字串串集
實際應⽤用
⽤用contains(_:)檢查字串串是否包括某些字符集?
⽤用insert(_:)在字串串中插入某些字符集?
⽤用remove(_:)刪除字串串中的某些字符集?
NSCharacterSet
NSCharacterSet What is the best way to test if a CharacterSet contains a Character in Swift 4?
刪除字串串中的某些
字符集
@NSString
刪除前後空格
檢查character set是否
包括在某⼦子集內
刪除前後指定的字符
如何刪除及提取指定的字符?
刪除及提取指定的字符
SwiftのCharacterSetで⽂文字列列操作 - Qiita
可是...
先刪除空字符
檢查字串串是否包括某些字符集
在字串串中插入字符集
ULR處理理
ULR處理理
CharacterSet.urlHostAllowed等類類型包含了了所有不需要被encode的字符
CharacterSet.urlHostAllowed不包含: "#%/<>?@^`{|}
CharacterSet.urlPathAllowed不包含: "#%;<>?[]^`{|}
CharacterSet.urlUserAllowed不包含: #%/<>?@^`{|}
CharacterSet.urlQueryAllowed不包含: "#%<>[]^`{|}
CharacterSet.urlPasswordAllowed不包含: "#%/:<>?@[]^`{|}
補充:分割單詞
分割單詞-> Tokenization
中⽂文分词-iOS⾃自带分词器CFStringTokenizer
NSMutableCharacterSet
Protocols
CVarArg
實例例可以以
Cの參參數進⾏行行編
碼和適當傳送
Equatable
可以比較
值是否相等
Hashable
為判等結果為相同的
對象提供相同的hash
value,以保證在被⽤用
作字典的key時的確定
性和性能
NSCopying
提供複製功能
NSMutableCopying
只有定義“不可
變與可變”區別
的類類才應採⽤用
NSSecureCoding
只要⼀一個類類對⾃自⾝身的實例例進
⾏行行編碼/解碼,就應該使⽤用
它,以防⽌止替換攻擊
NSCoding是基礎類庫中將對象歸檔到⽂件
系統上,或複製到另⼀個地址空間的⼀種⽅式
如果⽤decodeObjectForKey(解碼成實際的對象)
並不能保證創建的對象是預期的結果
REF: NSSecureCoding When to use NSSecureCoding
Reference
• The Unicode Standard

• Unicode Punctuation Characters

• Unicode Emoji Characters

• Unicode Character Categories

• Using character sets in Swift

• Finding Character in CharacterSet - Using Swift - Swift Forums

• 理理解了了Unicode你才能理理解的String與Character

• The Absolute Minimum Every Software Developer Absolutely, Positively Must Know
About Unicode and Character Sets

• 字符串串的 Unicode 表示法

• NSCharacterSet

• SwiftのCharacterSetで⽂文字列列操作 - Qiita 

• Three Ways to Enumerate the Words In a String Using Swift

• Natural Language Processing and your Apps
拉霸時間

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Swift meeting-0718