-
-
Save swishy/22c2c178ea8a42bc9ddc29a1950f226c to your computer and use it in GitHub Desktop.
swift OutputStream delegate issue
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
| import Foundation | |
| class TestClass: NSObject, StreamDelegate { | |
| func stream(_ aStream: Stream, handle eventCode: Stream.Event) { | |
| print("FOO") | |
| } | |
| func main() { | |
| let profile = "<amin:command name='mkdir' xmlns:amin='http://projectamin.org/ns/'>\n\t<amin:flag name='m'>0755</amin:flag>\n\t<amin:param name=\"target\">/tmp/test_ashell</amin:param>\n</amin:command>" | |
| // Testing delegate | |
| let testStream = OutputStream.toMemory() | |
| testStream.schedule(in: RunLoop.current, forMode: RunLoop.Mode.default) | |
| testStream.delegate = self | |
| testStream.open() | |
| let xmlByteArray = [UInt8](profile.utf8) | |
| testStream.write(xmlByteArray, maxLength: xmlByteArray.count) | |
| testStream.close() | |
| let outputData = testStream.property(forKey: Stream.PropertyKey.dataWrittenToMemoryStreamKey) as! Data | |
| let outputBytes = [UInt8](outputData) | |
| let outputXml = String(decoding: outputBytes, as: UTF8.self) | |
| print(outputXml) | |
| } | |
| } | |
| print("Launching stream test app") | |
| let foo = TestClass() | |
| foo.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment