Post

Replies

Boosts

Views

Activity

Reply to Locally Built Apple-LLVM Toolchain Can't Built Bitcode Supported Static Framework
I expect the local build of the apple-llvm toolchain to behave the same as the pre-built toolchain that’s included in Xcode. As far as I know, Apple has never stated the open source version and the bundled version are the same. Have you ever found any article that the two are the same? I guess Apple would not reveal what are the differences between the two versions to check if apps built for App Store are really built with the genuine tool.
Jan ’21
Reply to Create a blinking label
I tired this in the viewDidLoad() function, It would be better if you could show more context. There's one very simple principle in iOS programming: NEVER call sleep. (Never call blocking functions in the main thread.) All the UI updates begins when the current task in the main thread is finished. UI updates starts after viewDidLoad() is finished, meaning all the intermediate results are not shown and only the last result done in viewDidLoad() will be shown with very long delay. As you wrote yourself, using Timer is one of the right ways: 				caption.backgroundColor = .black 				var backgroundColorIsRed = false 				var blinkCount = 0 				Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) {timer in 						backgroundColorIsRed.toggle() 						self.caption.backgroundColor = backgroundColorIsRed ? .systemRed : .black 						blinkCount += 1 						if blinkCount >= 4 { 								timer.invalidate() 						} 				}
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to libc++abi.dylib: terminating with uncaught exception of type NSException
The most important part of the error message is here: '+[FYBInterstitial stopRequesting:]: unrecognized selector sent to class 0x10451c600' That is stating there is a class FYBInterstitial, and some part of your code is trying to call the class method stopRequesting:, but the class actually does not implement the method. Does your code have any parts calling stopRequesting:? (It may be described in the storyboard.)
Jan ’21
Reply to Why is a Class faster in SwiftUI than a Struct? (with example)
The Metal View works perfectly, when the bindings are class-based, and isn't even in this example so it's purely the difference between struct / observed / class based bindings that matters here. Sometimes it's less noticeable though, but always too slow for my use case. It was better if the shown code could reproduce the issue. Will update here when I got news from them. Thanks. I'm very curious and will watch on this thread.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Parse XML in SwiftUI
how can I use XMLParser to parse that specific data (title, image, author, date, content, etc.) and map it to the specific variables?  OK, let's concentrate on this issue. If you want to work with XMLParser, you need to implement a class conforming to XMLParserDelegate. Creating a subclass of XMLParser and making itself conform to XMLParserDelegate is an often found pattern, though it is not necessary. import Foundation struct Article { &#9;&#9;var title: String = "" &#9;&#9;var date: Date? &#9;&#9;var author: String? &#9;&#9;var img: URL? &#9;&#9;/// content in HTML &#9;&#9;var content: String = "" } class ArticlesParser: XMLParser { &#9;&#9;// Public property to hold the result &#9;&#9;var articles: [Article] = [] &#9;&#9; &#9;&#9;var dateTimeZone = TimeZone(abbreviation: "GMT-6") &#9;&#9;lazy var dateFormater: DateFormatter = { &#9;&#9;&#9;&#9;let df = DateFormatter() &#9;&#9;&#9;&#9;//Please set up this DateFormatter for the entry `date` &#9;&#9;&#9;&#9;df.locale = Locale(identifier: "en_US_POSIX") &#9;&#9;&#9;&#9;df.dateFormat = "MMM dd, yyyy" &#9;&#9;&#9;&#9;df.timeZone = dateTimeZone &#9;&#9;&#9;&#9;return df &#9;&#9;}() &#9;&#9; &#9;&#9;private var textBuffer: String = "" &#9;&#9;private var nextArticle: Article? = nil &#9;&#9;override init(data: Data) { &#9;&#9;&#9;&#9;super.init(data: data) &#9;&#9;&#9;&#9;self.delegate = self &#9;&#9;} } extension ArticlesParser: XMLParserDelegate { &#9;&#9; &#9;&#9;// Called when opening tag (`<elementName>`) is found &#9;&#9;func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) { &#9;&#9;&#9;&#9;switch elementName { &#9;&#9;&#9;&#9;case "posts": &#9;&#9;&#9;&#9;&#9;&#9;nextArticle = Article() &#9;&#9;&#9;&#9;case "title": &#9;&#9;&#9;&#9;&#9;&#9;textBuffer = "" &#9;&#9;&#9;&#9;case "date": &#9;&#9;&#9;&#9;&#9;&#9;textBuffer = "" &#9;&#9;&#9;&#9;case "author": &#9;&#9;&#9;&#9;&#9;&#9;textBuffer = "" &#9;&#9;&#9;&#9;case "img": &#9;&#9;&#9;&#9;&#9;&#9;textBuffer = "" &#9;&#9;&#9;&#9;case "content": &#9;&#9;&#9;&#9;&#9;&#9;textBuffer = "" &#9;&#9;&#9;&#9;default: &#9;&#9;&#9;&#9;&#9;&#9;print("Ignoring \(elementName)") &#9;&#9;&#9;&#9;&#9;&#9;break &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;// Called when closing tag (`</elementName>`) is found &#9;&#9;func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) { &#9;&#9;&#9;&#9;switch elementName { &#9;&#9;&#9;&#9;case "posts": &#9;&#9;&#9;&#9;&#9;&#9;if let article = nextArticle { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;articles.append(article) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;case "title": &#9;&#9;&#9;&#9;&#9;&#9;nextArticle?.title = textBuffer &#9;&#9;&#9;&#9;case "date": &#9;&#9;&#9;&#9;&#9;&#9;print("date: \(textBuffer)") &#9;&#9;&#9;&#9;&#9;&#9;nextArticle?.date = dateFormater.date(from: textBuffer) &#9;&#9;&#9;&#9;case "author": &#9;&#9;&#9;&#9;&#9;&#9;nextArticle?.author = textBuffer &#9;&#9;&#9;&#9;case "img": &#9;&#9;&#9;&#9;&#9;&#9;print("img: \(textBuffer)") &#9;&#9;&#9;&#9;&#9;&#9;nextArticle?.img = URL(string: textBuffer) &#9;&#9;&#9;&#9;case "content": &#9;&#9;&#9;&#9;&#9;&#9;nextArticle?.content = textBuffer &#9;&#9;&#9;&#9;default: &#9;&#9;&#9;&#9;&#9;&#9;print("Ignoring \(elementName)") &#9;&#9;&#9;&#9;&#9;&#9;break &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;// Called when a character sequence is found &#9;&#9;// This may be called multiple times in a single element &#9;&#9;func parser(_ parser: XMLParser, foundCharacters string: String) { &#9;&#9;&#9;&#9;textBuffer += string &#9;&#9;} &#9;&#9; &#9;&#9;// Called when a CDATA block is found &#9;&#9;func parser(_ parser: XMLParser, foundCDATA CDATABlock: Data) { &#9;&#9;&#9;&#9;guard let string = String(data: CDATABlock, encoding: .utf8) else { &#9;&#9;&#9;&#9;&#9;&#9;print("CDATA contains non-textual data, ignored") &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;textBuffer += string &#9;&#9;} &#9;&#9; &#9;&#9;// For debugging &#9;&#9;func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error) { &#9;&#9;&#9;&#9;print(parseError) &#9;&#9;&#9;&#9;print("on:", parser.lineNumber, "at:", parser.columnNumber) &#9;&#9;} } You have no need to implement all the methods defined in XMLParserDelegate, depending on the content of the xml. If the actual xml is more complex than the example, you need to re-write many parts of this code. You can use it like this: (Assuming data is containing the xml as Data.) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let parser = ArticlesParser(data: data) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if parser.parse() { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(parser.articles) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if let error = parser.parserError { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(error) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("Failed with unknown reason") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} One more, the xml header should be something like this: <?xml version="1.0" encoding="UTF-8"?> I guess it is broken when you post the example. But if the API actually returns such a header, you may need to fix the API.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21