Post

Replies

Boosts

Views

Activity

Reply to The right way for implementation of a view hierarchy in UIViewController
I haven't found a discussion. Neither have I. I guess, the most preferred way by Apple would be using Interface Builder: class SomeVC: UIViewController { @IBOutlet private weak var someLabel: UILabel! @IBOutlet private weak var someSwitch: UISwitch! override func viewDidLoad() { super.viewDidLoad() } } If you do not prefer Apple's way, unless you have some reason to be forced to use 1️⃣ or 3️⃣, I would use 2️⃣. For only one reason that it can represent someLabel and someSwitch may not be replaced. But, as already noted, I have never found this sort of discussion in the dev forums, so not sure my opinion would be sort of leading or not.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to How does my iOS app get file write permission?
I already tried posting an issue there, without any answers.... :-(  You have one option, give up using such an unreliable framework. Of course you may need to fully re-write your code... You can wait here, very rare but there may be some people who would write some solution about non-Apple frameworks. You can continue waiting for replies in this site until the moderator of this site closes this thread. Good luck.
Mar ’21
Reply to How to read property list (binary format) if the iOS fails to load it via NSPropertyListSerialization
I could have reproduced the issue using @eskimo's code with changing 60 to 600. (Just my curiosity, why do you need this deeply nested data?) Some other methods, such as NSDictionary.init(contentsOf:) or CFPropertyListCreateWithData, seem to be using the common code with PropertyListSerialization and causes the same issue. is there another way to read the propertylist file? I'm afraid you may need to parse the binary file using the info shown in @Claude31's reply.
Topic: App & System Services SubTopic: General Tags:
Mar ’21
Reply to Not sure how to add Prev/Next buttons in my SwiftUI List's Detail view.
One way would be passing manager as well as model: class ModelManager: ObservableObject { static let shared = ModelManager() @Published var modelList = Model.testData func previous(for model: Model) - Model? { if let index = modelList.firstIndex(where: {$0.modelValue == model.modelValue}) { if index 0 { return modelList[index - 1] } } return nil } func next(for model: Model) - Model? { if let index = modelList.firstIndex(where: {$0.modelValue == model.modelValue}) { if index modelList.count - 1 { return modelList[index + 1] } } return nil } } struct ContentView: View { @StateObject var manager: ModelManager = ModelManager.shared var body: some View { NavigationView { List(manager.modelList) { object in NavigationLink( destination: DetailView(manager: manager, model: object), label: { Text("fred \(object.modelValue)") }) } } } } struct DetailView: View { @ObservedObject var manager: ModelManager @State var model: Model var body: some View { VStack { HStack { if let previous = manager.previous(for: model) { Button("Previous") { model = previous } } Spacer() if let next = manager.next(for: model) { Button("Next") { model = next } } } Text("value: \(model.modelValue)") Spacer() } } }
Topic: UI Frameworks SubTopic: SwiftUI 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
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 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 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 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 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 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 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