2015-09-02 40 views
1

我是swift的新手。我想在静态函数中使用无静态成员的Swift类以下是我的代码。我无法在静态函数中访问静态类的成员。有没有办法在swift函数中访问非静态成员?在swift类的静态函数中访问非静态常量

public class Test{ 
private let testString:String 

init(test:String){ 
    testString = test 
} 

static func Get(url:String){ 
//Here testString is not accessable.. 
} 
} 

回答

4

不,没有办法访问静态函数中的非静态变量。不过,您可以创建该类的静态实例(一种单例生成方式)并访问它的testString变量。