This file contains hidden or 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
| class ViewController: UIViewController, URLSessionTaskDelegate { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let url = URL(string: "http://0.0.0.0")! | |
| let data = "Secret Message".data(using: .utf8)! | |
| let tempDir = FileManager.default.temporaryDirectory | |
| let localURL = tempDir.appendingPathComponent("throwaway") | |
| try? data.write(to: localURL) |
This file contains hidden or 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
| class ViewController: UIViewController, URLSessionTaskDelegate { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let url = URL(string: "http://0.0.0.0")! | |
| let data = "Secret Message".data(using: .utf8)! | |
| let request = URLRequest(url: url) | |
| let config = URLSessionConfiguration.background(withIdentifier: "uniqueId") | |
| let session = URLSession(configuration: config, delegate: self, delegateQueue: nil) | |
| let task = session.uploadTask(with: request, from: data) |
This file contains hidden or 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
| let url = URL(string: "http://0.0.0.0")! | |
| let data = "Secret Message".data(using: .utf8) | |
| let request = URLRequest(url: url) | |
| let config = URLSessionConfiguration.background(withIdentifier: "uniqueId") | |
| let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil) | |
| let task = session.uploadTask(with: request, from: data) { responseData, response, error in | |
| print("We're done here") | |
| } | |
| task.resume() |
This file contains hidden or 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
| let url = URL(string: "http://0.0.0.0")! | |
| let data = "Secret Message".data(using: .utf8) | |
| let request = URLRequest(url: url) | |
| let task = URLSession.shared.uploadTask(with: request, from: data) { responseData, response, error in | |
| print("We're done here") | |
| } | |
| task.resume() |
This file contains hidden or 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
| let url = URL(string: "http://0.0.0.0")! | |
| let data = "Secret message".data(using: .utf8) | |
| var request = URLRequest(url: url) | |
| request.httpBody = data | |
| let task = URLSession.shared.dataTask(with: request) { data, response, error in | |
| print("We're all done here") | |
| } | |
| task.resume() |
This file contains hidden or 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
| let methodBuilder = MethodSpec.builder(for: "doTheThing") | |
| methodBuilder.add(modifier: .Public) | |
| let code = """ | |
| for _ in 0..<howManyTimes { | |
| print("I'm doing the thing!") | |
| } | |
| """ | |
| methodBuilder.add(codeBlock: code.toCodeBlock()) |
This file contains hidden or 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
| let structBuilder = StructSpec.builder(for: "TestStruct") | |
| let fieldBuilder = FieldSpec.builder(for: "myField", type: .StringType, construct: nil) | |
| structBuilder.add(field: fieldBuilder.build()) | |
| let methodBuilder = MethodSpec.builder(for: "doTheThing") | |
| methodBuilder.add(modifier: .Public) | |
| let code = """ | |
| print("I'm doing the thing!") | |
| """ |
This file contains hidden or 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
| let structBuilder = StructSpec.builder(for: "TestStruct") | |
| let fieldBuilder = FieldSpec.builder(for: "myField", type: .StringType, construct: nil) | |
| structBuilder.add(field: fieldBuilder.build()) | |
| let poet = PoetFile(list: [structBuilder.build()], generatorInfo: nil) | |
| print(poet.fileContents) | |
| /// OUTPUT | |
| ----------- | |
| // |
This file contains hidden or 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
| let poet = PoetFile(list: [], generatorInfo: nil) | |
| print(poet.fileContents) | |
| // OUTPUT | |
| --------- | |
| // | |
| // | |
| // Generated by SwiftPoet on 6/29/18 | |
| // |
This file contains hidden or 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
| func testMutableClass() { | |
| let group = DispatchGroup() | |
| let obj = MutableClass() | |
| for _ in 0...1000 { | |
| group.enter() | |
| DispatchQueue.global().async { | |
| let sleepVal = arc4random() % 1000 | |
| usleep(sleepVal) |