我想知道如何在Swift中转换Int数组中的String.在Java中,我总是这样做:
String myString = "123456789";
int[] myArray = new int[myString.lenght()];
for(int i=0;i<myArray.lenght;i++){
myArray[i] = Integer.parseInt(myString.charAt(i));
}
Run Code Online (Sandbox Code Playgroud)
谢谢大家的帮助!
如何在swift中的myClass2另一个类myClass中为类中的变量添加值?
我已经尝试了类似的东西myClass2().myvariable = "value",但这没有用; 我的变量值仍然是nil.这是代码:
myViewController2:
import UIKit
class MyViewController2: UIViewController {
var myVariable : String?;
@IBOutlet weak var display: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func showPressed(sender: AnyObject) {
display.text = myVariable;
}
}
Run Code Online (Sandbox Code Playgroud)
视图控制器:
import UIKit
class ViewController: UIViewController {
let myClassInstance = myViewController2(); …Run Code Online (Sandbox Code Playgroud)