Type Does Not Have a Member

Type does not have a member

You cannot initialize an instance class property referencing another instance property of the same class, because it's not guaranteed in which order they will be initialized - and swift prohibits that, hence the (misleading) compiler error.

You have to move the initialization in a constructor as follows:

let components: NSDateComponents

init() {
self.components = myCalendar.components(.CalendarUnitYear | .CalendarUnitMonth, fromDate: now)
}

ViewController.Type does not have a member named

The initial value of a property (in your case: timer) cannot depend on another property of the class (in your case: interval).

Therefore you have to move the assigment timer = NSTimer(interval, ...) into a method of the
class, e.g. into viewDidLoad. As a consequence, timer has to be defined as an
optional or implicitly unwrapped optional.

Note also that Selector(...) takes a literal string as argument, not the method itself.

So this should work:

class ViewController: UIViewController {

var interval : NSTimeInterval = 1.0
var timer : NSTimer!

func timerRedraw() {

}

override func viewDidLoad() {
super.viewDidLoad()
timer = NSTimer(timeInterval: interval, target: self, selector: Selector("timerRedraw"), userInfo: nil, repeats: true)

// ...
}

// Other methods ...
}

'Class.Type' does not have a member named 'variable' error just a lack of class variable support?

The two errors messages you're getting are actually a result of two different, but related, reasons.

error: Use of unresolved identifier 'self'

self refers to an instance of a type and does not exist until that type is considered fully initialized, and therefore cannot be used for default property values.

error: 'Simple.Type' does not have a member named 'someConstant'

Class variables and static variables are considered "type variables" of classes and structs, respectively. What this means is that they're defined as variables on the type itself, as opposed to an instance of that type. By this definition and the fact that you can't use self for default property values, it's clear that this error message is a result of Swift looking for a class variable named someConstant. Class variables are still not supported as of Beta 4.

The analogous code for structs, with type variables taken into account, compiles just fine:

struct Simple {
static let someConstant = 0.50
static var someVariable = 1

let referringConstant = someConstant
var referringVar = someVariable

let explicitTypeProperty = Simple.someConstant
}

Reference: my recollection of the "Properties" and "Initializers" chapters of The Swift Programming Language.

A member of the type, 'Method', does not have a corresponding column in the data reader with the same name

The problem may be because you are retrieving all fields of all tables in your stored procedure and it doesn't retrieve a field that matches with a member of the TestSearch_Result object, in this case it would be 'Method'.

Swift 'String.Type' does not have a member named 'stringWithContentsOfFile'

Try something like this:

var error:NSError?
let string = String(contentsOfFile: "/usr/temp.txt", encoding:NSUTF8StringEncoding, error: &error)
if let theError = error {
print("\(theError.localizedDescription)")
}

Swift 2.2:

if let string = try? String(contentsOfFile: "/usr/temp.txt") {
// Do something with string
}

Swift: 'ViewController.Type' does not have a member named 'URL'

None of your code is in a method, wrap it up in a method and call the method when appropriate.

Swift: 'Class.type' does not have member named 'variable'

First- as smozgur said in the comments, you need to use a function to check whether or not it is an anagram. Secondly, from what I can tell, Array(String) no longer works as of Swift 2.0. To fix this, I referred to Convert a String to an array of characters swift 2.0. So, in summary, I placed your logic into a function and fixed the creation of your characters(1,2) array. This is how I got this to work:

class Anagram{
let word1 : String
let word2 : String

init(word1: String, word2: String){
self.word1 = word1
self.word2 = word2
}

func checkAnagram () -> Bool {
var characters1 = Array(word1.characters).sort()
var characters2 = Array(word2.characters).sort()
var pos = 0
var match:Bool = true
while pos < characters2.count && match {

if characters1[pos] == characters2[pos] {

pos++
}

else {
match = false
}
}
return match
}
}

let trueAnagram = Anagram(word1: "abcd", word2: "dcba")

trueAnagram.checkAnagram()
//returns true

let falseAnagram = Anagram(word1: "false", word2: "falze")

falseAnagram.checkAnagram()
//returns false.

Sidenote: Instead of using pos = pos + 1, just use pos++.

If this works for you, please check my answer. If not, comment and I will try again to help you.

Error with Swift Code: String.Type does not have a member named 'stringWithContentOfURL'

Factory methods have pretty much all been replaced by Swift initializers (this happened quite a while ago, if I remember correctly). The ones you want are:

let searchResultString:String! = String(contentsOfURL: NSURL(string: searchURL)!, encoding: NSUTF8StringEncoding, error: &error)

Note that NSURL(string:) returns an optional NSURL - handle it however you think best.



Related Topics



Leave a reply



Submit