From c3e93cbdea8235053551bafa75886d76e71d50e2 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Mon, 23 Oct 2023 07:42:21 +0530 Subject: [PATCH] Small tweaks to `IOSFeedParser` --- .../sasikanth/rss/reader/network/IOSFeedParser.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/network/IOSFeedParser.kt b/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/network/IOSFeedParser.kt index 3a11a21b0..4d11281cd 100644 --- a/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/network/IOSFeedParser.kt +++ b/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/network/IOSFeedParser.kt @@ -56,7 +56,6 @@ import platform.darwin.NSObject @Inject @Suppress("CAST_NEVER_SUCCEEDS") class IOSFeedParser(private val dispatchersProvider: DispatchersProvider) : FeedParser { - private var feedPayload: FeedPayload? = null override suspend fun parse( xmlContent: String, @@ -65,18 +64,19 @@ class IOSFeedParser(private val dispatchersProvider: DispatchersProvider) : Feed ): FeedPayload { return withContext(dispatchersProvider.io) { suspendCoroutine { continuation -> + var feedPayload: FeedPayload? = null val data = (xmlContent as NSString).dataUsingEncoding(NSUTF8StringEncoding)!! val xmlFeedParser = - IOSXmlFeedParser(feedUrl, fetchPosts) { feedPayload -> - this@IOSFeedParser.feedPayload = feedPayload + IOSXmlFeedParser(feedUrl, fetchPosts) { parsedFeedPayload -> + feedPayload = parsedFeedPayload } val parser = NSXMLParser(data).apply { delegate = xmlFeedParser } val parserResult = parser.parse() - val feedPayload = feedPayload - if (parserResult && feedPayload != null) { - continuation.resume(feedPayload) + val nullableFeedPayload = feedPayload + if (parserResult && nullableFeedPayload != null) { + continuation.resume(nullableFeedPayload) } else if (!parserResult && parser.parserError() != null) { continuation.resumeWithException(XmlParsingError(parser.parserError()?.description)) }