小编t0r*_*199的帖子

如何在Swift中转换Int数组中的String(数字)

我想知道如何在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)

谢谢大家的帮助!

arrays string int swift

12
推荐指数
2
解决办法
2万
查看次数

如何在Swift中的另一个类中设置变量值

如何在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)

variables class uiviewcontroller ios swift

1
推荐指数
1
解决办法
8441
查看次数

标签 统计

swift ×2

arrays ×1

class ×1

int ×1

ios ×1

string ×1

uiviewcontroller ×1

variables ×1