Cannot find 'self' in scope

Hi! I'm trying to display a pdf inside my iOS app and I'm using the code displayed below, but for every self inside it I'm getting this error: Cannot find 'self' in scope

//
//  gimnaziumStundenplan.swift
//  stundenplan
//
//  Created by Alex on 04/09/2021.
//

import UIKit
import PDFKit

private func createPdfView(withFrame frame: CGRect) -> PDFView {
    let pdfView = PDFView(frame: frame)
    pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    pdfView.autoScales = true

    return pdfView
}

private func createPdfDocument(forFileName fileName: String) -> PDFDocument? {
    if let resourceUrl = self.resourceUrl(forFileName: fileName) {
        return PDFDocument(url: resourceUrl)
    }
    

    if let resourceUrl = URL(string: "https://web.stanford.edu/class/archive/cs/cs161/cs161.1168/lecture4.pdf") {
            return PDFDocument(url: resourceUrl)
        }

        return nil

}



private func displayPdf() {
    let pdfView = self.createPdfView(withFrame: self.view.bounds)
    if let pdfDocument = self.createPdfDocument(forFileName: "heaps") {
        self.view.addSubview(pdfView)
        pdfView.document = pdfDocument
    }
}
}


Answered by robnotyou in 686903022

"self" refers to the object that the func is contained in.
But your code shows no such object.
Perhaps you have you omitted the crucial code?
...but if these funcs are global, then there is indeed no "self".

Accepted Answer

"self" refers to the object that the func is contained in.
But your code shows no such object.
Perhaps you have you omitted the crucial code?
...but if these funcs are global, then there is indeed no "self".

Cannot find 'self' in scope
 
 
Q