-1

Java:

public Static int myFunction(int n){
    ...
}

Swift:

import UIKit

var str = "Hello, playground"
print(str)

Static func (n: Int) -> Intdo {
    
}

xcode issues these: Use of unresolved identifier 'Static' Top-level statement cannot begin with a closure expression Expected identifier in function declaration Consecutive statements on a line must be separated by ';' Did you mean to use a 'do' statement? Closure expression is unused

7
  • You seemed to have answered your own question. Given all these errors, do you really think you can do Static func (n:Int)->Intdo { (whatever that is)? Commented Feb 15, 2021 at 13:27
  • not helpful, but this link was absolute help stackoverflow.com/questions/29636633/… Commented Feb 15, 2021 at 13:46
  • None of the keywords in Swift or Java start with a capital. It's static, not Static. Your Java code isn't valid, either. Also, your swift function lacks a name, which is invalid. Commented Feb 15, 2021 at 13:55
  • import UIKit var str = "Hello, playground" print(str) /** * */ class foo { static func hi() { print("hi") } } Commented Feb 15, 2021 at 14:10
  • stackoverflow.com/questions/29206465/… Commented Feb 15, 2021 at 14:10

1 Answer 1

0

static vs class as class variable/method (Swift)

for adding Static before func name add a class to encapsulate the function defined as

class foo {
  static func hi() {
    println("hi")
  }
}

is a type method (i.e. a method that is called on the type itself) which also is final (i.e. cannot be overridden in a subclass).

Sign up to request clarification or add additional context in comments.

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.