1

I am following The Complete iOS App Development Bootcamp by Angela, and I am in lesson 353. My question is how to solve the error "Cannot call value of non-function type 'URL'". My code so far is simply of three lines

import Cocoa
import CreateML

let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/user/Documents/CurrentProjects/Work/Mini/Twittermenti-iOS13-master/twitter-sanders-apple3.csv"))

The instructor is not facing the problem on Xcode 10 Beta while I am on Xcode 11.3.1 but I face the problem while following the exact same code. Anyone knows how to solve it?

  • 1
    Do you have any variable or class/struct named URL that you have created yourself? What happens if you replace URL with Foundation.URL? – Joakim Danielson Dec 19 '20 at 18:22
  • @JoakimDanielson I dont have any variable or class/struct named URL that I have created myself and when I add Foundation I receive error "Module 'Foundation' has no member named '<#T##URL#>'"Which I am not sure what even means –  Dec 19 '20 at 18:28
  • @JoakimDanielson based on usage of `MLDataTable` the OP is using MacOS, hence `import Cocoa` and not `Foundation` is correct. – timbre timbre Dec 19 '20 at 19:19
  • @KirilS. Of course you can import only Foundation for macOS, I do it all the time – Joakim Danielson Dec 19 '20 at 21:01
  • @Impostor_Syndrom_Incarnated could you perhaps include some more code related to the error, like the surrounding code lines? – Joakim Danielson Dec 19 '20 at 21:06
  • Also, the following works fine for me `let url = Foundation.URL(fileURLWithPath: "/Users/...")` so in your case `let data = try MLDataTable(contentsOf: Foundation.URL(fileURLWithPath: "/Users/..."))` should work fine. – Joakim Danielson Dec 19 '20 at 21:10
  • @KirilS. But you did bring up an interesting point, MLDataTable is MacOS only but OP is taking an iOS programming course so something is fishy here. – Joakim Danielson Dec 19 '20 at 21:16
  • @Impostor_Syndrom_Incarnated Is this an iOS or a macOS project you are working on? – Joakim Danielson Dec 19 '20 at 21:20

1 Answers1

0

Most likely somewhere you defined a variable like this:

enter image description here

hence you are overwriting a URL class (an instance of which you are trying to create), with your local variable.

Change your local variable to lower-case (which is Swift standard anyways), and it will work:

import Cocoa
import CreateML

var url: URL

let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/user/Documents/CurrentProjects/Work/Mini/Twittermenti-iOS13-master/twitter-sanders-apple3.csv"))
timbre timbre
  • 12,648
  • 10
  • 46
  • 77