Reputation: 5936
I have a simple function in OBJ C to create a random number
+(NSString*)certRef
{
NSInteger rNumber = arc4random() % 100000000 + 1;
NSString *randomCertRef = [NSString stringWithFormat: @"%ld", (long)rNumber];
return randomCertRef;
}
Now im trying to convert it Swift:
Class ToolsCustomFunctions
func randomNumber(theNumber: String){
let rNumber = arc4random() % 100000000 + 1;
let rNumberString = "\(rNumber)"
println("THE RANDOM NUMBER IS: \(rNumberString)")
return (theNumber)
}
The above gives Error "string not convertible to ()
Then im trying access it in class B
let rNumberFuction = ToolsCustomFunctions()
//read randomised number string here//
Various attempts including println "the random number is \(rNumberFuction.randomNumber(theNumber: String))"
result in not accessing/setting the randomised number from my function either through compiler error or a nil value
Upvotes: 0
Views: 46
Reputation: 540005
func randomNumber(theNumber: String) { ... }
is a function
Void
or ()
.What you want is a function
which is declared as
func randomNumber() -> String { ... }
And the return value should be rNumberString
, not theNumber
.
Upvotes: 3