So this is an interesting problem.
In my Lunch Card app, AddView, which I'm already having a problem with - https://developer.apple.com/forums/thread/672848, has an unused variable:
@Environment(\.colorScheme) var colorScheme
The app works fine with it, even if the color scheme doesn't match. I thought a good solution for the color scheme problem would be to get rid of this variable in AddView itself.
Apparently, that's not the right thing to do, and when getting rid of it, I get this message:
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Like I said, the app works fine with it. It's not used in AddView at all yet still gives me an error basically saying - and correct me if I'm wrong - that there's not enough memory to build body, even though the unused variable reverses that.
You can find the latest code for AddView here. - https://developer.apple.com/forums/thread/672848
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Lunch Card - https://apps.apple.com/us/app/lunch-card-id-card-manager/id1546901593 is finally out. But while in App Store Connect, I misclicked while trying to create a macOS version of the app and clicked tvOS. Now, I can't delete it. It gives me the option, but gives me an error. It literally just says:
An error has occurred. Try again later.
After trying to Google this problem, it didn't come to any avail.
Now I'm stuck with a tvOS version of my app that I have no plans to develop (because who needs to scan an ID card on a TV?).
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store Connect
App Store
Developer Tools
So...I lost most of the Lunch Card files to a factory reset. There was an issue with Disk Utility - it's a whole thing. But I've managed to recover most of the files. But there's something that isn't working anymore within the code.
In SettingsView, where the color scheme ("Appearance") picker is located, you choose between light, dark, and system default.
But when calling the sheet for AddView in CardsView (using SheetInfo() from Info.swift), it just defaults to whatever the system is set at. When I previewed it, it was light mode when the app setting was dark.
Thing is, before I lost all my files, it worked perfectly normal, and consumer versions reflected that. I recovered (and rewrote some of) SettingsView and AddView (thank goodness I showed the full code for AddView here). I may have missed something, so here's my code for both, plus ContentView, CardsView, and Info.swift.
SettingsView.swift - https://developer.apple.com/forums/content/attachment/91ff1182-42d3-48b8-9f8d-be765ee32c43AddView - https://developer.apple.com/forums/content/attachment/06f1b340-4770-49f4-b530-6f27c1b50490CardsView - https://developer.apple.com/forums/content/attachment/4291deb9-ce02-4769-8ccf-d02d9d6908b8ContentView - https://developer.apple.com/forums/content/attachment/12cc3378-8769-4cee-8faa-63af72cc7ab3Info.swift - https://developer.apple.com/forums/content/attachment/89c6710c-faed-4b93-8152-a0f9a95806c8
Please read the last thread: Parse XML in SwiftUI - https://developer.apple.com/forums/thread/670984
I've got the code to parse articles from XML courtesy of OOPer...but I need to actually execute it in ArticlesView. How would I call ArticlesParser into ArticlesView and related views and run the parser onto an XML file (THS.xml)?
Here's ArticleInfo.swift and ArticlesView.
ArticleInfo.swift:
//
// ArticleInfo.swift
// Hair Society Go
//
// Created by Joshua Srery on 1/13/21.
// Code provided by OOPer on Apple Developer Forums
//
import Foundation
struct Article {
var title: String = ""
var date: Date?
var author: String?
var img: URL?
/// content in HTML
var content: String = ""
}
class ArticlesParser: XMLParser {
// Public property to hold the result
var articles: [Article] = []
var dateTimeZone = TimeZone(abbreviation: "GMT-6")
lazy var dateFormater: DateFormatter = {
let df = DateFormatter()
//Please set up this DateFormatter for the entry `date`
df.locale = Locale(identifier: "en_US_POSIX")
df.dateFormat = "MMM dd, yyyy"
df.timeZone = dateTimeZone
return df
}()
private var textBuffer: String = ""
private var nextArticle: Article? = nil
override init(data: Data) {
super.init(data: data)
self.delegate = self
}
}
extension ArticlesParser: XMLParserDelegate {
// Called when opening tag (`<elementName>`) is found
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
switch elementName {
case "posts":
nextArticle = Article()
case "title":
textBuffer = ""
case "date":
textBuffer = ""
case "author":
textBuffer = ""
case "img":
textBuffer = ""
case "content":
textBuffer = ""
default:
print("Ignoring \(elementName)")
break
}
}
// Called when closing tag (`</elementName>`) is found
func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
switch elementName {
case "posts":
if let article = nextArticle {
articles.append(article)
}
case "title":
nextArticle?.title = textBuffer
case "date":
print("date: \(textBuffer)")
nextArticle?.date = dateFormater.date(from: textBuffer)
case "author":
nextArticle?.author = textBuffer
case "img":
print("img: \(textBuffer)")
nextArticle?.img = URL(string: textBuffer)
case "content":
nextArticle?.content = textBuffer
default:
print("Ignoring \(elementName)")
break
}
}
// Called when a character sequence is found
// This may be called multiple times in a single element
func parser(_ parser: XMLParser, foundCharacters string: String) {
textBuffer += string
}
// Called when a CDATA block is found
func parser(_ parser: XMLParser, foundCDATA CDATABlock: Data) {
guard let string = String(data: CDATABlock, encoding: .utf8) else {
print("CDATA contains non-textual data, ignored")
return
}
textBuffer += string
}
// For debugging
func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error) {
print(parseError)
print("on:", parser.lineNumber, "at:", parser.columnNumber)
}
}
ArticlesView:
//
// ArticlesView.swift
// Hair Society Go
//
// Created by Joshua Srery on 11/29/20.
//
import SwiftUI
struct ArticlesView: View {
var body: some View {
NavigationView {
List {
ForEach(0 ..< 5) { item in
NavigationLink(destination: ArticleView(title: "Replace with Title var", image: "Replace with Img var", content: "Replace with Content var", author: "Replace with Author var", date: "Replace with Date var")) {
ArticleRow(image: "Replace with Img var", title: "Replace with Title var", author: "Replace with Author var", date: "Replace with Date var")
}
}
}
.navigationTitle("Articles")
.toolbar(content: {
Menu {
Button("Date", action: {})
Button("Title", action: {})
Button("Customize…", action: {})
} label: {
Label("Filter", systemImage: "line.horizontal.3.decrease.circle")
}
})
// Ignore the filter Menu for right now
}
}
}
struct ArticleRow: View {
let image: String
let title: String
let author: String
let date: String
var body: some View {
HStack {
Image(image)
.resizable()
.frame(minWidth: 75, maxWidth: 100, maxHeight: 75)
.cornerRadius(12)
VStack(alignment: .leading, content: {
Text(title)
.font(.headline)
Text("\(author) • \(date)")
.font(.subheadline)
})
}
}
}
Please read the last thread: Call a Class into views - https://developer.apple.com/forums/thread/671482
The right code for the XML parser is almost set in stone, just I need a way to retrieve article data (not just through loadArticles()) like title, author, etc.
I've decided, and was suggested, that I go the same route as my other app, Lunch Card, where there's a function where you use a dataUrl and data to call ArticlesParser(). Thing is, since the code for the XML parser is a bit more complicated, it's harder to pass variables around just like with Lunch Card. There's another class I have to deal with. So I either have to (1) redefine articles the same way with an Array;
@Published var articles: [ArticleInfo] = []
...or (2), find some other way to call articles from the ObservableObject, maybe in a StateObject or ObservedObject.
I want to try and borrow as much code from Lunch Card as possible, but for an XML parser with multiple classes and extensions, it a bit easier said than done. Here's full code for ArticleInfo and ArticlesView.
ArticleInfo.swift - https://developer.apple.com/forums/content/attachment/d16688a9-f420-4dee-b1f4-ed255e325a3eArticlesView - https://developer.apple.com/forums/content/attachment/fbfb99f1-87a7-448b-ad04-54aef6abe61c
Not sure how ArticleInfo is an integer, so I have no idea what's going on or why it's not working as well. Also, I'm trying to experiment with borrowing the JSON decoder/encoder code, so tell me if that's the wrong way to go.
I just noticed something in the Lunch Card app: when adding another card after adding the first, it autofills all the text fields (newCard variable) with the previous info. For a normal customer, I think that would be pretty annoying to have to delete all the field data and replace it every time.
If you need reference, check out previous expansions of this. Here's the most recent code for CardsView and AddView for version 1.2:
CardsView - https://developer.apple.com/forums/content/attachment/dcdbf40d-93ee-46fe-851b-54cf36e4498fNote: Not really important, but instructions now exist.
AddView - https://developer.apple.com/forums/content/attachment/eb2260d0-6848-4cca-b94c-e488963b0139Note: I added colors as a variable as well.
Here's Info.swift. It's not too much different but there are now colors:
Info.swift - https://developer.apple.com/forums/content/attachment/83be0d99-62db-4242-a20b-72f66e78bb02