Swift Error: Variable used within its own initial value

后端 未结 4 1404
灰色年华
灰色年华 2020-12-24 01:37

When I\'m initializing an instance of an entity I\'m getting the error Variable used within its own initial value.

Here is the code throwing the error:<

相关标签:
4条回答
  • 2020-12-24 02:06

    I have faced same error when missing out if while unwrapping the text .

    By adding if resolved above issue.

    0 讨论(0)
  • 2020-12-24 02:10

    You have a function parameter called word in scope and you're trying to create a constant with the same name. Name your constant something other than word.

    0 讨论(0)
  • 2020-12-24 02:16

    You are redefining a constant word which has the same name as a parameter within your function

    class func buildWordDefinition (word:String, language:Language, root:TBXMLElement) -> WordDefinition
    {
        // same name as the parameter here
        let word = WordDefinition(word: word, language: language)
    }
    
    0 讨论(0)
  • 2020-12-24 02:22

    You are declaring a constant named word, and trying to use the argument with the same name to initialize it. The compiler tries to use the just declared constant to assign its own initial value, instead of using the argument.

    0 讨论(0)
提交回复
热议问题