Post

Replies

Boosts

Views

Activity

Reply to (Expansion) Retrieve articles from an XML parser
ArticlesParser now holds articles as a published variable.  ArticlesParser is not an ObservableObject, so making it @Published does not make sense. But ArticlesInfo - where the loadArticles() function is held - now cannot call articles because that property does not exist in ArticlesInfo. Why did you remove articles? I completely do not understand why. On the topic of using the Lunch Card method, would using JSON be easier to use than XML? If you easily remove some declarations without thinking why it is there, both JSON and XML cannot be easy for you.
Topic: App & System Services SubTopic: General Tags:
Mar ’21
Reply to onDelete change label
I can share you the project  Thanks for sharing. I tried your code and found the swipe action label was shown as Delete even if I set the simulators Language settings to German. Then I checked your project. In Localizations, German was actually added, but it shows 0 Files Localized. Seems your project does not have any resources localizable. (And, unfortunately, this is the default project setting, when you choose SwiftUI App for Life Cycle.) Add a new file named Localizable.strings to your project. (It may be empty till you really make your project localizable.) And localize it including Germany. (You can find a button Localize... in the File Inspector.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Set an array of arrays inside of UICollectionView that's inside a UITableView and return the correct number of items?
how can i use this part Please put the exact line into the place I have show, inside viewWillAppear of SelectedShowVC. i'm sorry how can update with the following code my cellForRowAt for the UITable and the cellForItemAt for the UICollection i didn't quite understand And, sorry, I have missed to post some parts (core parts) of code needed: SelectedShowVC (extension) func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) - Int { if collectionView === UI.castCollectionView { //#- Use `===` instead of `==` return arrayCast.count } else { //#↓ use `tag` as `season` let season = collectionView.tag guard (1...10) ~= season else {return 0} return arrayOfArraySeasonsEpisodes[season-1].count } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) - UICollectionViewCell { if collectionView === UI.castCollectionView { //#- Use `===` let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifierCast", for: indexPath) as! CastCell cell.backgroundColor = .clear cell.model = arrayCast[indexPath.item] return cell } else { //#↓ Use `tag` as `season` let season = collectionView.tag guard (1...10) ~= season else {return UICollectionViewCell()} let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifierSeasons", for: indexPath) as! SeasonCell cell.backgroundColor = .clear //global variable assign to the model for uicollectionview individual cell let arreglo = arrayOfArraySeasonsEpisodes[season-1][indexPath.item] //#- cell.model = arreglo return cell } } func getSeasons(url: String) { //... for category in toneCategories { //#↓ You can simplify many `if`s using Array if (1...10) ~= season { let show = Episodess(dictionary: category, seasonInt: season) arrayOfArraySeasonsEpisodes[season-1].append(show) } } //... } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell { guard let cell = tableView.dequeueReusableCell(withIdentifier: "seasonsRegister", for: indexPath) as? NumberOfSeasonsCell else { return UITableViewCell() } cell.selectionStyle = .none cell.backgroundColor = .clear //note for each cell i manually asign an different array - #Better not do it let season = indexPath.row + 1 guard (1...10) ~= season else {return UITableViewCell()} cell.setCollectionViewTag(season) //#- Use `tag` as `season` //#↓ I do not understand why you need this //Generally, you should never modify data in `tableView(_:cellForRowAt:)` let arreglo = arrayOfArraySeasonsEpisodes[season-1] let arregloDeArregloss = ArregloBidimencional(arreglo: arreglo, tag: 0) arregloDeArreglos.append([arregloDeArregloss]) return cell }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Unable to get the title from PKAddPassButton
What could be wrong in this? PKAddPassButton is actually a subclass of UIButton, but it does not mean all the properties or methods work the same as UIButton. As far as I checked, PKAddPassButton has some private UILabels and the actually shown text is held in one of them. (You may find that title would appear overlapping the existing title of PKAddPassButton, if you call setTitle:.) You could explore the subviews of the button and get or set the text of the label. But this sort of view hierarchy would change at any time in the future, at any time without notifications. Considering why Apple made such UILabels private, modifying the contents of such labels might be taken as using private APIs.
Mar ’21
Reply to Populating UICollectionView with Images from Camera Roll
If I remove line 14 as you suggested I get this error message: 2021-03-16 13:53:51.771564+0100 Flowshot[6490:1274036] [Storyboard] Unknown class GalleryImageCell in Interface Builder file. Thanks for trying. Seems you have not set Custom Class of the cell correctly. Can you see the grayed module name of your project in the Module field? If not (then, you may see grayed None), check Inherit Module From Target. (In some cases, you need to uncheck and re-check.) Of course, you may need to reconfirm the content in the Class field, no extra whitespace before or after the class name? Please try until you do not see Unknown class GalleryImageCell in Interface Builder file. There may be other things to fix, but resolving this Unknown class would be the first thing to do.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Populating UICollectionView with Images from Camera Roll
Can you tell what happens if you remove this line (line 14)? self.collectionView!.register(GalleryImageCell.self, forCellWithReuseIdentifier: reuseIdentifier) If you designed your GalleryImageCell as the custom cell on the storyboard, you should not call register({class}, forCellWithReuseIdentifier:). All the settings made on the storyboard will not be used when you call register in this style. (Please do not forget to set the reuse Identifier dataCell to the Identifier of the cell in the Attribute Inspector.) Your code may cause some other problems, but that is another issue.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to MeasurementFormatter workaround for missing .unitStyle = .none?
How do I retrieve the user's preferred unit from locale? As far as I checked the documentations of Apple, I could not find any APIs to get preferred weight unit. there sure are other weight / mass units out there There are only three countries where the metric system is not used: the US, Liberia and Myanmar. Testing with macOS 11.1 and iOS 14.4 Simulator, only one region "US" uses pounds. extension Locale { var measurementSystem: String { (self as NSLocale).object(forKey: NSLocale.Key.measurementSystem) as! String } } func formatWeight(for locale: Locale, weightInKgs: Double) - String { let mformatter = MeasurementFormatter() mformatter.locale = locale mformatter.unitOptions = .naturalScale mformatter.unitStyle = .medium let weight = Measurement(value: weightInKgs, unit: UnitMass.kilograms) return mformatter.string(from: weight) } let localeIds = ["en_US", "es_US", "en_GB", "en_LR", "my_MM", "ja_JP"] for localId in localeIds { let locale = Locale(identifier: localId) print(locale, locale.measurementSystem) print(locale.regionCode ?? "*region unknown*") print("Uses Metric System: \(locale.usesMetricSystem)") print(formatWeight(for: locale, weightInKgs: 100.1)) } Output: en_US (fixed) U.S. US Uses Metric System: false lb es_US (fixed) U.S. US Uses Metric System: false lb en_GB (fixed) U.K. GB Uses Metric System: true kg en_LR (fixed) U.S. LR Uses Metric System: false kg my_MM (fixed) U.S. MM Uses Metric System: false ၁၀၀.၁ kg ja_JP (fixed) Metric JP Uses Metric System: true kg (I'm not sure if kg is really preferred in daily life in the UK, but macOS/iOS uses kg for weight/mass when Locale set to en_GB.) Seems using UnitMass.pounds is universal enough, practically.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Index Out of Range
I changed it to this, but when I press Add, the simulator freezes Using isValidIndex does not solve your issue. You declare voti2 with initializing it to an emtpy Array. But there are no lines in your code which appends an element to voti2, thus voti2 stays empty and any index cannot be valid. What sort of result do you expect in voti2 after calling tutto()?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Synchronization inside concurrent NSOperationQueue of NSURLSession.
Will dictionary usage get synchronized automatically ? With your description, I assume you are using NSMutableDictionary. Under this assumption the answer is NO. You should better read this article: Thread Safety Summary - https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html Simply saying, all the mutable objects are thread-unsafe (unless thread-safety is clearly documented). You may need to implement synchronizing access to the dictionary explicitly by yourself.
Topic: App & System Services SubTopic: Core OS Tags:
Mar ’21
Reply to StateObject reinitialised when Form scrolls
sample to reproduce the issue. Sorry, but your code is not appropriate for a sample to reproduce the issue. Structs cannot be an @StateObject and your code does not compile. You should better send a feedback to Apple attaching an appropriately made small sample. Until Apple will fix the issue (I'm not sure if Apple would take this as a bug to be fixed), you may need to find some workaround.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21