25 questions
0
votes
1
answer
73
views
How can I reason about String.Index after the original string has been modified?
I found that String.Index can become invalid when the original string is modified.
var s = "abc"
let i = s.index(after: s.startIndex)
print(s[i]) // b
s = "字" + s
print(s) // 字abc
...
1
vote
1
answer
198
views
Is it possible to change Swift String Interpolation for the String typealias?
I have a lot of DTOs in my app which log some field. That field should not be logged because the data is kind of sensitive.
The model looks like this:
typealias HiddenFieldType = String
struct DTO1 {
...
0
votes
1
answer
185
views
Swift 5.7 - The compiler cannot type-check complex regex which contains 5 captures
I wrote this code:
let regex = Regex {
let newline = #/\r|\n|\r\n/#
let doubleNewline = Repeat(newline, count: 2)
let dateFormatter = DateFormatter()
"# ...
-1
votes
2
answers
892
views
how to remove character when backspace is pressed swift
i want to remove one last character when user presses the backspace
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> ...
0
votes
2
answers
890
views
How to convert swift-struct object name using swift-string
I have a struct name called Car. Car has two attributes(noOfTyres, ownerName).
struct Car {
var noOfTyres: Int
var ownerName: String
}
The string value is let objStr = "Car/ownerName&...
0
votes
2
answers
281
views
Convert Path String to Object Path in Swift
struct Student{
var rollNum : Int
var name : String
var contact : Contact
}
struct Contact{
var phoneNum : String
var mailId : String
}
let contact = Contact(phoneNum : "1234567890&...
2
votes
2
answers
1k
views
swift string diacriticInsensitive not working correct
I am doing diacritic conversion on string. In Swedish it converts the letters åäö to aao. but iphone keyboard has åäö these letters. I couldn't understand why it converted these 3 letters. Is there an ...
0
votes
1
answer
165
views
find non-alphabet words in any language with swift
I have multiple strings for some languages(english, italian, arabic, french ...etc). I want to see a list of words other than that language's alphabet.
For example for English:
"thisŞĞstring"...
0
votes
0
answers
146
views
Replace character in a long dictionary with swift
I want to replace some characters in a dictionarys keys. There are about a hundred thousand keys in the dictionary. With the code below, this takes about an hour. Can we shorten this time by making ...
2
votes
1
answer
3k
views
String Format Specifiers : rounding rule used for decimal values
I am using String(format:) to convert a Float. I thought the number would be rounded.
Sometimes it is.
String(format: "%.02f", 1.455) //"1.46"
Sometimes not.
String(format: &...
1
vote
1
answer
2k
views
Limit text to a certain number of words in Swift
In a mobile App I use an API that can only handle about 300 words. How can I trimm a string in Swift so that it doesn't contain more words?
The native .trimmingCharacters(in: CharacterSet) does not ...
0
votes
1
answer
122
views
Convert between diacritic variants of a character
I'm passing a string as a parameter to command line tool written in swift.
I have a problem with some characters containing diacritics.
If I pass à á ả ã ạ й ё as a line argument, inside the app I got ...
0
votes
0
answers
21
views
Why is my search string not found in a larger string if compared with Regular Expression? [duplicate]
I am trying to find a substring in another string. I am using Regular expressions. The code is as below:
let occurrence = "Kingfisher:"
let string = "Swiss: SW123123\nKingfisher: ...
2
votes
1
answer
2k
views
Why is using isEmpty preferable over a comparison with an empty string literal is Swift?
The String type is Swift has a property named isEmpty that indicates whether a string has no characters.
I'd like to know if there's any difference between using isEmpty and checking the equality to ...
0
votes
1
answer
906
views
how can i add extra spaces before any special character
how to add extra spaces before any Special character in string ,in Swift, for example if i have string
var str = "#StackOverFlow@is$awesome"
" #StackOverFlow @is $awesome" // i have to achieve ...
6
votes
2
answers
780
views
How could I get Apple emoji name instead of Unicode name?
I see that the Unicode name of an emoji and its Apple name as displayed in Character Viewer are different. How could I get an emoji's Apple name using Swift?
Example:
Emoji: 😄
Unicode Name (got ...
1
vote
4
answers
3k
views
How to force Swift to recognize apostrophe?
I am trying to replace all apostrophe (') characters in a string with another character.
I am running this code:
someString.replacingOccurrences(of: apost, with: "a")
I have tried to let apost equal ...
1
vote
1
answer
631
views
What is String.Encoding.unicode?
Swift offers a series of encodings for strings. As of the time I'm writing this, none of them are documented, which makes this absurdly more confusing than it should be...
I can understand that ....
2
votes
1
answer
318
views
Why is unicode included as an Encoding in Swift's String API?
I read this very important blog regarding string encodings.
After reading it I realized that unicode is a standard of mapping characters to code points which are integers. How these integers are ...
0
votes
0
answers
110
views
How to concat two unicodes in Swift [duplicate]
I have following two unicodes
let countryFlag1 = "0x1F1E6"
let countryFlag2 = "0x1F1E9"
How to concat two unicodes to and assign it to textfield
Tried following it is working but don't know how ...
1
vote
2
answers
756
views
Swift replace occurrence of string with condition
I have string like below
<p><strong>I am a strongPerson</strong></p>
I want to covert this string like this
<p><strong>I am a weakPerson</strong></p>...
0
votes
4
answers
2k
views
Getting "String.Index" while enumerating swift string
Currently we iterate string as below:
let greeting = "Hello"
for (intIndex, char) in greeting.enumerated() {
let currentIndex = greeting.index(greeting.startIndex, offsetBy: intIndex)
let ...
2
votes
1
answer
475
views
swift escaping backslash doesn't work as expected
When I print this:
print("dfi:.*\\{8766370\\}.*:6582.*")
the result on the log looks as expected:
>>>> dfi:.*\{8766370\}.*:6582.*
but when i construct the string dynamically the result ...
0
votes
3
answers
318
views
How to convert Strings in Swift?
I've two cases where I need to convert strings to different formats.
for ex:
case 1:
string inputs: abc, xyz, mno, & llr // All Strings from a dictionary
output: ["abc","xyz", "mno", "llr"...
-1
votes
1
answer
3k
views
Convert array of custom object to String in swift4
I am new to Swift and have an issue converting an array of custom object, to String.
This is my response class Tickets
public struct Tickets: Codable {
public let name: String!
...