2

I am a beginner and I'd like to print an array on a label by pressing a button.

I already know how to put a String in the label like this:

@IBAction func Start(sender: UIButton) {
    label.text = "Insert Array"

But instead of "Insert Array" I want to insert my function, which creates an Array at the end. If I insert the Array, it says:

use of unresolved identifier 'array'

My code works perfectly in the playground.

1
  • Please show your my function, which creates an Array at the end Commented Oct 16, 2015 at 15:45

3 Answers 3

3

try with this.

you test() function has NSArray return type

func test()-> NSArray{
 //bla bla bla
 let myArray:NSArray = ["data1","data2","data3"]

 print(myArray)
 return myArray;
}

then you can get your result

label.text = test().componentsJoinedByString(",")
Sign up to request clarification or add additional context in comments.

2 Comments

But I don't want to create a new Array. I got a separate file with a function func test() { bla bla bla print(myArray) } I can't use "myArray" because it is in that scope, right? sorry, i'd rather not upload my function :/ Ps: I am still trying to figure out how to format comments :P
Thank you very much, I knew it's that simple. :) I forgot to return the array and I didn't declare the type of the function.
0

whenever you want to print a non-String variable as a String use \()

label.text = "\(ArrayFunc())"

if this is for troubleshooting purposes use

println(ArrayFunc())
//or
println("Array: \(ArrayFunc())")

1 Comment

Yes I tried that. But it returns only "()" as a result
-1

try below code for(NSString *str in resultArray){

    [resultLabel.text= [str stringByAppendingString:@","];

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.