Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

ios - What is the use of in label of utf16Offset(in: )

I can't understand the in label of utf16Offset(in:) statement

what the use of this label.

And can anyone explain that, Is the following statement is right or wrong?

let location = textString.range(of: hyperText)?.lowerBound.utf16Offset(in: textString)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you code is correct.it means the offset into a string's code units for this index. for example:

  var textString = "niaddjkdskjdsjdsk"
  let location = textString.range(of: "dd")?.lowerBound.utf16Offset(in: textString)

as we know, the bound is (3,_),so the utf16Offset is 3. Before Swift 4.2,we use encodedOffset,now it replace by utf16Offset, they are same behaviorenter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...