-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

Alexander
  • 59,041
  • 12
  • 98
  • 151
  • 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)? – Sweeper Feb 15 '21 at 13:27
  • not helpful, but this link was absolute help https://stackoverflow.com/questions/29636633/static-vs-class-functions-variables-in-swift-classes – Nima Salehi Feb 15 '21 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. – Alexander Feb 15 '21 at 13:55
  • import UIKit var str = "Hello, playground" print(str) /** * */ class foo { static func hi() { print("hi") } } – Nima Salehi Feb 15 '21 at 14:10
  • https://stackoverflow.com/questions/29206465/static-vs-class-as-class-variable-method-swift/29206635#29206635 – Nima Salehi Feb 15 '21 at 14:10
  • class foo { static func hi() { println("hi") } } – Nima Salehi Feb 15 '21 at 14:47
  • i replace it with static, thnx Alexander( https://stackoverflow.com/users/3141234/alexander ) – Nima Salehi Feb 15 '21 at 14:56

1 Answers1

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).