Created
June 18, 2020 12:13
-
-
Save joniden/5f438e18df6a78f7c7fe6f0d9d129692 to your computer and use it in GitHub Desktop.
Help swiftui gethttpsdata
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 SwiftUI | |
class ContentViewData: ObservableObject { | |
@Published var myTextFieldText: String = "" | |
func getdata() { | |
Network.getHttpsData() | |
} | |
} | |
struct ContentView: View { | |
@ObservedObject var contentViewData = ContentViewData() | |
var body: some View { | |
VStack { | |
VStack(alignment: | |
.leading) { | |
Text("Testar!").font(.title).padding() | |
Button(action: { | |
contentViewData.getData() | |
}) { | |
Text("Get DATA") | |
.frame(minWidth: 0, maxWidth: .infinity) | |
.font(.system(size: 18)) | |
.padding() | |
.foregroundColor(.black) | |
.overlay( | |
RoundedRectangle(cornerRadius: 25) | |
.stroke(Color.black, lineWidth: 2) | |
) | |
} | |
} | |
TextField("ReturnData", text: $myTextFieldTitle) | |
.frame(height: 55) | |
.textFieldStyle(PlainTextFieldStyle()) | |
.padding([.leading, .trailing], 4) | |
.cornerRadius(16) | |
.overlay(RoundedRectangle(cornerRadius:16).stroke(Color.gray).padding(.bottom, -150).padding(.top, 50)) | |
.padding([.leading, .trailing], 24) | |
Text(contentViewData.myTextFieldText) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
class Network { | |
func getHttpsData() { | |
let url:String = "https://www.example.se/aaa?op=1" | |
_ = HttpsGetData.httpsGet(url) | |
{ (data, response, error) in | |
if let error = error { | |
print("Error: \(error)") | |
} else if let data = data { | |
print("---------------------------------------") | |
print("Data: \(data.count)") | |
let newStr = String(data: data, encoding: .utf8) | |
print("---------------------------------------") | |
print("newStr: \(newStr ?? "n/a")") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment