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 Set an array of arrays inside of UICollectionView that's inside a UITableView and return the correct number of items?
I moved to FireFox. Seems FireFox works well with this site and I can write a reply. I struggled with your code for hours, and I think the following code would be able to make your collection views work: (I renamed all the struct names to follow the coding convection of Swift, if you have some specific reason you cannot follow it, please re-interpret them appropriately.) globals var imagenArraaay: [String] = [] var arrayPoster_path: [String] = [] var arrayOverview: [String] = [] var arrayCreatorName: [String] = [] var season_number: String = "" var season_number2: Int = 0 var air_date: String = "" var still_path: String = "" var arrayName: [String] = [] var arrayFirst_air_date: [String] = [] var arrayBackdrop_path: [String] = [] var arrayVote_average: [NSNumber] = [] var arrayid: [NSNumber] = [] var arrayShows: [Tvshows] = [] var arrayCast: [Castt] = [] var arrayCreator: [Created] = [] var arrayAiringSeason: [Episode] = [] //#↓ Remove these many Arrays //var arraySeasonsEpisodes: [Episodess] = [] //var arraySeasonsEpisodes2: [Episodess] = [] //var arraySeasonsEpisodes3: [Episodess] = [] //var arraySeasonsEpisodes4: [Episodess] = [] //var arraySeasonsEpisodes5: [Episodess] = [] //var arraySeasonsEpisodes6: [Episodess] = [] //var arraySeasonsEpisodes7: [Episodess] = [] //var arraySeasonsEpisodes8: [Episodess] = [] //var arraySeasonsEpisodes9: [Episodess] = [] //var arraySeasonsEpisodes10: [Episodess] = [] //#↓ And use one Array of Array instead var arrayOfArraySeasonsEpisodes: [[Episodess]] = .init(repeating: [], count: 10) var arregloDeArreglos: [[ArregloBidimencional]] = [] var arregloDeArreglosTri: [ArregloTridimencional] = [] var arrayOfSeasonsInt: [Int] = [] SelectedShowVC override func viewWillAppear(_ animated: Bool) { arrayCast.removeAll() arrayCreator.removeAll() arrayAiringSeason.removeAll() arrayOfSeasonsInt.removeAll() arrayCreatorName.removeAll() // arraySeasonsEpisodes.removeAll() //duplicate arregloDeArreglos.removeAll() //#↓ Remove these // arraySeasonsEpisodes.removeAll() // arraySeasonsEpisodes2.removeAll() // arraySeasonsEpisodes3.removeAll() // arraySeasonsEpisodes4.removeAll() // arraySeasonsEpisodes5.removeAll() // arraySeasonsEpisodes6.removeAll() // arraySeasonsEpisodes7.removeAll() // arraySeasonsEpisodes8.removeAll() // arraySeasonsEpisodes9.removeAll() // arraySeasonsEpisodes10.removeAll() arrayOfArraySeasonsEpisodes = .init(repeating: [], count: 10) //#- Use Array (of Array) //... UI.tvTitleLabel.text = UI.SelectedNamee UI.descriptionTV.text = UI.SelectedOverVieww UI.scoreLabel.text = UI.SelectedVotee } (As modest as possible, your code is sort of a showcase of bad practices. Especially, getCastInfo and getCreators (with included getSeasons) are critically bad and you should better re-write them as soon as possible if your code is not just an exercise. But this is another issue.) NumberOfSeasonsCell //#↓ Extension to use `tag` of collection view as `season` extension NumberOfSeasonsCell { func setCollectionViewTag(_ tag: Int) { self.seasonsCollectionView.tag = tag } }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to ForEach and HStack
What do you mean with combined entity and how do I do it? Define only one Entity CombinedContent with two Attributes in your xcdatamodel: value of type String date of type Date You just need only one DataModel class: class DataModel: ObservableObject{ @Published var data: [CombinedContent] = [] var txt = "" var dataAttuale = Date() let context = persistentContainer.viewContext init() { readData() } func readData(){ let request: NSFetchRequestCombinedContent = CombinedContent.fetchRequest() do { let results = try context.fetch(request) self.data = results } catch { print(error.localizedDescription) } } func writeData(){ let entity = NSEntityDescription.insertNewObject(forEntityName: "CombinedContent", into: context) as! CombinedContent entity.value = txt entity.date = dataAttuale do { try context.save() self.data.append(entity) } catch { print(error.localizedDescription) } } func deleteData(indexSet: IndexSet){ for index in indexSet{ do { let obj = data[index] context.delete(obj) try context.save() let index = data.firstIndex(of: obj) data.remove(at: index!) } catch { print(error.localizedDescription) } } } func updateData(){ } } You can use it as: ForEach(combinedModel.data, id: \.objectID){ obj in HStack { Text(obj.value) Text("\(obj.date, formatter: dateFormatter)") } }.onDelete(perform: combinedModel.deleteData)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Cannot use instance member 'restaurantOptions' within property initializer; property initializers run before 'self' is available
Cannot use instance member 'restaurantOptions' within property initializer; property initializers run before 'self' is available In your code, restaurantOptions is an instance property, OK? And restaurantString also is an instance property. And you are trying to use restaurantOptions.joined(separator: "\n") as an initial value of the property restaurantString, in other words, you are trying to use restaurantOptions.joined(separator: "\n") within property initializer. In Swift, you cannot use any instance methods nor any instance properties in an initial value of other (usual) instance properties. The error message is re-stating the fact with very simplified reason. One way to workaround this restriction of Swift, you can set the value of restaurantString in onAppear: struct RestaurantPickerView: View { //... @State var restaurantOptions:Array = UserDefaults.standard.stringArray(forKey: "restaurantOptions") ?? [] @State var restaurantString: String = "" //Initialize with a dummy value //... var body: some View { ZStack { //... } .onAppear { //Set the actual value in `onAppear` restaurantString = restaurantOptions.joined(separator: "\n") } } } If you could show how restaurantString was used, I would have proposed some other way.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Swift C++ interoperability
NO, not yet as for now. There were some discussions about Swift-C++ interoperability in forums.swift.org . For example: Interoperability between Swift and C++ - https://forums.swift.org/t/manifesto-interoperability-between-swift-and-c/33874 In my opinion, the process is in the early stage and you may need to wait years for the released version of Swift including this feature. Or you can contribute developing this feature, please read the article linked above.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to (Expansion) Call a Class into views
You have no need to (and should not, in this case) make ArticlesParser a local class nested in a function. class ArticlesParser: XMLParser { //... } extension ArticlesParser: XMLParserDelegate { //... } class ArticlesInfo: ObservableObject {     @Published var articles: [Article] = []     func loadArticles() { let articlesParser = ArticlesParser() //... } }
Topic: App & System Services SubTopic: General Tags:
Mar ’21
Reply to Declarations
I don't understand what it means? It's an interface declaration of the class in Objective-C. You cannot use Objective-C in SwiftUI and just ignore the Objective-C versions of documentation. Visit the Swift version of documentation: https://developer.apple.com/documentation/avfoundation/avplayer Or you want to learn a classical way of developing apps, in addition to learning SwiftUI? It may be a long way. Learning Objective-C would benefit some parts of your developing apps, but it may not be the first place to go.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Core Data Make Decodable
Searching with "Core Data Make Decodable", I could have find this article: Using Codable with Core Data and NSManagedObject (Seems the dev forums does not like this URL and I cannot include the link to it. Please search with the title.) The core part of the article is to put the line calling init(context:) into the initializer init(from:): enum DecoderConfigurationError: Error { case missingManagedObjectContext } extension CodingUserInfoKey { static let managedObjectContext = CodingUserInfoKey(rawValue: "managedObjectContext")! } @objc(CurrentPlayers) public class CurrentPlayers: NSManagedObject, Decodable { enum CodingKeys: String, CodingKey { case photoUrl = "PhotoUrl" case firstName = "FirstName" case lastName = "LastName" case position = "Position" case team = "Team" case yahooName = "YahooName" case status = "Status" case jerseyNumber = "JerseyNumber" } public static var managedObjectContext: NSManagedObjectContext? required public convenience init(from decoder: Decoder) throws { guard let context = decoder.userInfo[.managedObjectContext] as? NSManagedObjectContext else { throw DecoderConfigurationError.missingManagedObjectContext } self.init(context: context) //... } } You just need to pass the right managed object context when decoding: let decoder = JSONDecoder() decoder.userInfo[.managedObjectContext] = ... decoder.decode(...)
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Did Xcode 12.4 get rid of "storyboards" by default?
did Xcode 12.4 get rid of "storyboards" by default? Xcode shows SwiftUI as default in Interface, but you can choose Storyboard there. where do I go to relearn how to start? If you want to learn how to code in SwiftUI, better visit Apple's tutorial first: Introducing SwiftUI - https://developer.apple.com/tutorials/swiftui/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to (Expansion) Retrieve articles from an XML parser
Here's code for ArticleInfo  Seems you have gone back to the first place. Have you ever learnt programming? If this is just a school homework and you have no intention to learn programming, you should better find a good friend, rather than asking here. Your latest ArticlesParser lacks the property articles to integrate the extension into the actual ObservableObject: What do you mean by integrate?
Topic: App & System Services SubTopic: General Tags:
Mar ’21