Skip to content

Instantly share code, notes, and snippets.

View regularberry's full-sized avatar

Sean Berry regularberry

View GitHub Profile
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)
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)
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()
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()
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()
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())
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!")
"""
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
-----------
//
let poet = PoetFile(list: [], generatorInfo: nil)
print(poet.fileContents)
// OUTPUT
---------
//
//
// Generated by SwiftPoet on 6/29/18
//
func testMutableClass() {
let group = DispatchGroup()
let obj = MutableClass()
for _ in 0...1000 {
group.enter()
DispatchQueue.global().async {
let sleepVal = arc4random() % 1000
usleep(sleepVal)