Skip to content

Commit

Permalink
Small tweaks to IOSFeedParser
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Oct 23, 2023
1 parent 5c9181f commit c3e93cb
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
}
Expand Down

0 comments on commit c3e93cb

Please sign in to comment.