M
M
Maxim Trofimov2018-07-04 21:35:55
Swift
Maxim Trofimov, 2018-07-04 21:35:55

How to call a function from another class that has no type?

I can't figure out what the problem is. How to call a function that has no type at all to print text? "Instance member 'mustprint' cannot be used on type 'Printer'; "

ViewController.swift
class ViewController: UIViewController {

    @IBAction func action (sender: UIButton) {
        Printer.mustprint() //не билдит
    }
}



Printer.swift
class Printer: ViewController {

  func mustprint() {
        print ("was printed")
    }

}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
doublench21, 2018-07-04
@doublench21

Are you sure you know the Swift language? Judging by the code and the question - no.
You need to understand what a type method is and what an instance method is.
The type method is defined like this. The static keyword can be replaced with class (but that doesn't matter)

class Printer {
  static func mustprint() {
    print ("was printed")
  }
}

And it is called like this
----------
And what you wrote is an instance method
class Printer {
   func mustprint() {
    print ("was printed")
  }
}

And it is called first by creating an instance of this class, and then calling the function.
----------
What they tell you here: "Instance member 'mustprint' cannot be used on type 'Printer'; "

P
Petya Petrov, 2014-10-31
@petya_petrally

in main.css on line 4834 change the width to 100% and remove the margins

.right-col {
    float: none;
    margin: 0 auto;
    margin-right: 40px;
    width: 400px;
}

O
oavoavoav, 2016-11-19
@oavoavoav

Help:
* max-width: 100% ;
this is not entirely correct (although it is debatable if it is meant as a global element property policy), but if it is difficult to find the right element, whose content goes beyond 100% (either text, or padding, or whatever)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question