I have recently started a Swift programming language course and need some help on my first program. I am using playground to write an anagram program in Xcode v6.3.2. For my logic, I am first sorting the words alphabetically and then comparing them. The error occurs when declaring word1 and word2 as arrays and dictates 'Anagram.type' does not have a member named 'word1'. I believe my logic is correct. I am struggling to understand why this error occurs, and how to solve it. I have looked around online, but am having difficulty applying to what I find to my own code. This is my first time using Stack overflow. All constructive feedback is welcomed.
import UIKit
class Anagram{
let word1 :String
let word2 :String
init(word1: String, word2: String){
self.word1 = word1
self.word2 = word2
}
var characters1 = Array(word1)
var characters2 = Array(word2)
characters1 = characters1.sort()
characters2 = characters2.sort()
var pos = 0
var match = true
while pos < characters2.length && match {
if characters1[pos] == characters2[pos]:
pos = pos + 1
else:
match = false
}
return match
}
let theAnagram = Anagram(word1: "abcd", word2: "dcba")