I am working on a project that sends some HTTP commands with an IP address that the user defines in a text field. The IP address is essentially piped into many different functions for my app. As I have done this I keep running into the "Instance member cannot be used on type" error. At the fundamentals of variable declaration, what would be the correct way to do the following? I will have about 40-50 different requests.
@IBOutlet weak var myIPaddress: UITextField!
var baserequest = "http://\(myIPaddress):8088/api/?function="
var requestA = "\(baserequest)myFunctionA&value=abc"
var requestB = "\(baserequest)myFunctionB&value=xyz"
var requestC = "\(baserequest)myFunctionC&value=123"
...
...
I am not sure if this matters but because we are using HTTP commands one of the declarations looks like this
var program1 = NSMutableURLRequest(URL: NSURL(string: "\(baseRequest)activeinput&input=1" )!)
* UPDATE *
I am not sure what my issue is. Here is the code I have and it's still throwing that error. On
var request1 = NSMutableURLRequest(URL: NSURL(string: "\(baserequest)activeinput&input=1" )!)
So this is my entire code
import UIKit
import Foundation
func httpGet(request: NSURLRequest!, callback: (String?, NSError?) -> Void) {
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
guard error == nil && data != nil else {
callback("", error)
return
}
callback(String(data: data!, encoding: NSUTF8StringEncoding), nil)
}
task.resume()
}
class FirstViewController: UIViewController, UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet weak var vmixip: UITextField!
var baserequest: String = ""
func textFieldDidEndEditing(textField: UITextField) {
updateBaseRequest(textField.text!)
}
func updateBaseRequest(vmixip: String) {
baserequest = "http://\(vmixip):8088/api/?function="
}
var request1 = NSMutableURLRequest(URL: NSURL(string: "\(baserequest)activeinput&input=1" )!)
@IBAction func Program1(sender: UIButton) {
if let image = UIImage(named:"g1") {
sender.setImage(image, forState: .Normal)
}
httpGet(request1) { string, error in
guard error == nil && string != nil else {
print(error?.localizedDescription)
return
}
print(string!) //
}
}
}