Not sure why Swift is giving me a "Cannot find 'xFile' in scope" error

I have the following structure :

struct XFile : Codable {
   ...variables here   
    
    init(fileUrl: URL, key: String) {
    ...
}

Then in another class I am trying the following:

class UploadTask {
	var xfile: XFile
	var inProgress = false
	
	init(file: URL) {
		xFile = XFile(fileUrl: file, key: "filename")
	}
}

If typed as above Xcode gives me the following error:

Cannot find 'xFile' in scope

If I remove the xFile= part,

Xcode give me the following warning and error:

Result of 'XFile' initializer is unused
Return from initializer without initializing all stored properties

Obviously I am breaking some rule, just not sure what it is.

  • Oh ****! The ‘f’! I kept looking at the ‘x’! Thank you. I seriously think I have a reading disorder sometimes.

Add a Comment

Accepted Reply

The rule you are breaking is that capitalization matters when you spell a name. You're saying

xFile = ...

So the Swift compiler looks for the term xFile declared as a variable name in scope, to which something can be assigned. But the word xFile doesn't appear as a variable name in scope — just as the compiler is telling you.

What does appear as a variable name in scope is xfile, which as far as Swift is concerned is a totally different name.

  • Wow! The ‘f’! I kept looking at the ‘x’! Thank you. I seriously think I have a reading disorder sometimes.— SergioDCQ less than a minute ago

Add a Comment

Replies

The rule you are breaking is that capitalization matters when you spell a name. You're saying

xFile = ...

So the Swift compiler looks for the term xFile declared as a variable name in scope, to which something can be assigned. But the word xFile doesn't appear as a variable name in scope — just as the compiler is telling you.

What does appear as a variable name in scope is xfile, which as far as Swift is concerned is a totally different name.

  • Wow! The ‘f’! I kept looking at the ‘x’! Thank you. I seriously think I have a reading disorder sometimes.— SergioDCQ less than a minute ago

Add a Comment