Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangyongji
/
MRFramework
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c50a53e0
authored
Dec 04, 2019
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加一个与字符串做比较的协议
parent
ee3d36b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
MRFramework/MRFramework/Extensions/Foundation/String+util.swift
+37
-0
No files found.
MRFramework/MRFramework/Extensions/Foundation/String+util.swift
View file @
c50a53e0
...
...
@@ -128,6 +128,7 @@ extension String {
}
}
// MARK: - Calculate text size
extension
String
{
public
func
size
(
with
attributes
:
MRStringAttribute
...
,
fixedWidth
:
CGFloat
)
->
CGSize
{
guard
count
>
0
&&
fixedWidth
>
0
else
{
...
...
@@ -157,3 +158,39 @@ extension String {
return
DataURLParser
<
UIImage
>.
parserDataURL
(
self
)
}
}
// MARK: - Compare with MRCompareToString
extension
String
{
public
static
func
==
<
T
:
MRCompareToString
>
(
lhs
:
Self
,
rhs
:
T
)
->
Bool
{
return
rhs
.
compare
(
with
:
lhs
)
==
.
orderedSame
}
public
static
func
<
<
T
:
MRCompareToString
>
(
lhs
:
Self
,
rhs
:
T
)
->
Bool
{
return
rhs
.
compare
(
with
:
lhs
)
==
.
orderedDescending
}
public
static
func
<=
<
T
:
MRCompareToString
>
(
lhs
:
Self
,
rhs
:
T
)
->
Bool
{
let
rs
=
rhs
.
compare
(
with
:
lhs
)
return
rs
==
.
orderedSame
||
rs
==
.
orderedDescending
}
public
static
func
>
<
T
:
MRCompareToString
>
(
lhs
:
Self
,
rhs
:
T
)
->
Bool
{
return
rhs
.
compare
(
with
:
lhs
)
==
.
orderedAscending
}
public
static
func
>=
<
T
:
MRCompareToString
>
(
lhs
:
Self
,
rhs
:
T
)
->
Bool
{
let
rs
=
rhs
.
compare
(
with
:
lhs
)
return
rs
==
.
orderedSame
||
rs
==
.
orderedAscending
}
}
/// 比较字符串的协议。任意类遵守该协议来实现跟字符串比较
public
protocol
MRCompareToString
:
Comparable
{
static
func
<
(
lhs
:
Self
,
rhs
:
String
)
->
Bool
static
func
<=
(
lhs
:
Self
,
rhs
:
String
)
->
Bool
static
func
>
(
lhs
:
Self
,
rhs
:
String
)
->
Bool
static
func
>=
(
lhs
:
Self
,
rhs
:
String
)
->
Bool
static
func
==
(
lhs
:
Self
,
rhs
:
String
)
->
Bool
func
compare
(
with
string
:
String
)
->
ComparisonResult
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment