Wednesday, June 19, 2024
HomeiOS Developmentios - Swift Occasion Variable to finish URL

ios – Swift Occasion Variable to finish URL


As soon as once more… This could simply be a lot simpler than it’s.

I must ship the ID of a picture from one viewcontroller to a different to finish a URL. However I maintain operating into the issue that the occasion variable sort cannot be used inside the operate the place the URL is created:

ImageViewController:

let vc2 = storyBoard.instantiateViewController(withIdentifier: "comview") as! CommentsViewController
        vc2.imgId = imgId

CommentsViewController:

class CommentsViewController: UITableViewController {
   
    var imgId: String = ""

    static func endpointForComments() -> String {
        
        return "https://nutria.web/ap/feedback.php?photo_id=" + imgId // Occasion member 'imgId' can't be used on sort 'CommentsViewController'
    }
    
    static func allMembers(completionHandler: @escaping ([Comment]?, Error?) -> Void) {
        let endpoint = endpointForUsers()
        guard let url = URL(string: endpoint) else {
            print("Error: can't create URL")
            let error = BackendError.urlError(cause: "Couldn't assemble URL")
            completionHandler(nil, error)
            return
        }

  override func viewDidLoad() {
        tremendous.viewDidLoad()
        
        tableView.delegate = self
        tableView.dataSource = self
        
        print("The imgId4 is:", imgId) // works simply wonderful
  }

I’ve gone via about thirty or forty totally different potential options to this drawback… Equivalent to making “endpointForComments” an everyday operate and shifting it into viewDidLoad… however then “allPhotos” can now not attain it. Up to now it has been an countless collection of catch 22s.

Is there some MUCH EASIER approach of getting that quantity to the top of my URL? I imply this strikes me as one thing that ought to’ve simply been potential to do by passing the variable (which is how I did it in Android).



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments