Post

Replies

Boosts

Views

Activity

Reply to Swift framework localization
Have a look here : https://stackoverflow.com/questions/56917337/cannot-localize-my-swift-5-framework-localization-import-does-nothing Try to call the extended NSLocalizedString API. func NSLocalizedString(_ key: String, tableName: String? = nil, bundle: Bundle= Bundle.main, value: String = "", comment: String) -> String
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21
Reply to Xcode 13 beta 3 - should it create Localizable.strings file for the base languge?
I usually have both the base language and a file for any language (including base: hence it will show twice). For adding manually a new language, I usually do it directly in Finder before dragging into the project (with some care depending on what type of file it is). I've written a document (in french) for my own use that I could share if you post an email address where to send.
Jul ’21
Reply to Editor placeholder in source file
When you post code, don't post in comments. It is totally messed up. Here it is formatted: class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var benchPressPB: UITextField! @IBOutlet weak var squatPB: UITextField! @IBOutlet weak var deadliftPB: UITextField! @IBOutlet weak var ohpPB: UITextField! @IBOutlet weak var rackPullPB: UITextField! @IBOutlet weak var legPressPB: UITextField! @IBOutlet weak var pullUpsPB: UITextField! var textFields = var textFieldKeys = [ "benchPressPB", "squatPB", "deadliftPB", "ohpPB", "rackPullPB", "legPressPB", "pullUpsPB" ] var textFieldStrings = override func viewDidLoad() { super.viewDidLoad() self.benchPressPB.delegate = self self.squatPB.delegate = self self.deadliftPB.delegate = self self.ohpPB.delegate = self self.rackPullPB.delegate = self self.legPressPB.delegate = self self.pullUpsPB.delegate = self textFields = [benchPressPB, squatPB, deadliftPB, ohpPB, rackPullPB, legPressPB, pullUpsPB] for (index, key) in textFieldKeys.enumerated() { let aValue = UserDefaults.standard.string(forKey: key) textFields[index].text = aValue textFieldStrings.append(aValue ?? "") } } func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() let newText = textField.text if let index = textFields.firstIndex(of: textField) { textFieldStrings[index] = newText UserDefaults.standard.set(newText, forKey: textFieldKeys[index]) } return true } } // My full code for my app, to provide a new default value, do I first need to declare it as a variable? or am I completely missing the point. Apologies if this is a completely dumb question. I am literally brand new to this and was advised the best way to learn was to just build something instead of a boring udemy course. I had to delete some of the code to post... UITextFields() & UIString() Really appreciate all your help! There is something that doesn't mean anything:  var textFields =   var textFieldKeys = [    "benchPressPB",    "squatPB",    "deadliftPB",    "ohpPB",    "rackPullPB",    "legPressPB",    "pullUpsPB"   ]    var textFieldStrings = The error here: if let index = textFields.firstIndex(of: textField) { textFieldStrings[index] = newText UserDefaults.standard.set(newText, forKey: textFieldKeys[index]) } textField is UITextField ; textFields is an array of String (I assume) So you should search for newText. But it is an optional, you need to unwrap first if let newText = textField.text, let index = textFields.firstIndex(of: newText) {
Topic: UI Frameworks SubTopic: UIKit Tags:
Jul ’21
Reply to Need Help Transfer Data From Button
It's risky to have dataSource as a Set, because order will change. Don't you mind ? Anyway, just replace selectedNameInCell = dataSource[indexPath.row].yahooName with override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { if let cell = cellForRow(at: IndexPath) { selectedNameInCell = cell.yahooName // I assume you have such a property in the cell ; or maybe it is just cell.textLabel!.text if the name is the textLabel } }
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21
Reply to Need Help Transfer Data From Button
I wanted to avoid duplicates with an array. Yes, that's logical, but you should handle it when you populate the array. Or remove any duplicate in the array: var myArray = [/* Some items*/] var noReplicateArray = [] // with same types of items for item in myArray { if !noReplicateArray.contains(item) { noReplicateArray.append(item) } } You can also use reduce: noReplicateArray = myArray.reduce([]) {array, item in if array.contains(item) { return array } else { return array+[item] } } But the first appears to be much faster.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21