-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from bmoliveira/35-fix-utf16-string-utils
Solve #35
- Loading branch information
Showing
11 changed files
with
298 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// MarkdownKitViewModel.swift | ||
// Example | ||
// | ||
// Created by Bruno Oliveira on 21/01/2019. | ||
// Copyright © 2019 Ivan Bruel. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MarkdownKit | ||
import Alamofire | ||
|
||
class MarkdownKitViewModel { | ||
|
||
let markdownParser: MarkdownParser | ||
|
||
fileprivate let testingURL: String | ||
|
||
var markdownAttributedStringChanged: ((NSAttributedString?, Error?) -> ())? = nil | ||
|
||
init(markdownParser: MarkdownParser, | ||
testingURL: String = "https://raw.githubusercontent.com/apple/swift-evolution/master/proposals/0240-ordered-collection-diffing.md") { | ||
self.markdownParser = markdownParser | ||
self.testingURL = testingURL | ||
} | ||
} | ||
|
||
extension MarkdownKitViewModel { | ||
func parseString(markdownString: String) { | ||
markdownAttributedStringChanged?(markdownParser.parse(markdownString), nil) | ||
} | ||
|
||
func requestTestPage() { | ||
AF.request(testingURL).responseString { [weak self]response in | ||
if let error = response.error { | ||
self?.markdownAttributedStringChanged?(nil, error) | ||
return | ||
} | ||
|
||
response.result.withValue { [weak self]markdownString in | ||
self?.parseString(markdownString: markdownString) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.