Here is my class
class aClassName():
def __init__(self):
#do something...
iface.setActiveLayer(QgsProject.instance().mapLayersByName('someName')[0])
#do something
...
The class calls a number of methods from iface such as setActiveLayer, .mapCanvas().zoomToSelected() etc in different functions. It runs properly when it is called in the same file.
But when I tried to use the class by importing it into another file:
from theClassFile import aClassName
The error message showed up and said :
NameError: name 'iface' is not defined
even if adding from qgis.utils import iface to theClassFile with reference from here.
I just began to use PyQGIS last month.

from qgis.utils import ifaceto the import section of the file which containsclass aClassName– Kadir Şahbaz Dec 30 '19 at 10:47