收到错误:“扩展可能不包含存储的属性”

Jay*_*ayo 1 swift

我是 Swift 和 xcode 的新手。我试图在 a 中声明 GoogleMobileAds 变量UISplitViewControllerDelegate,但收到错误:扩展程序可能不包含存储的属性。

这是我的代码:

import GoogleMobileAds

extension MainBiblePagerVC: UISplitViewControllerDelegate{
    // Setup Navigation Items in Bible Page
    var interstitial: GADInterstitial!
Run Code Online (Sandbox Code Playgroud)

谢谢!

Woo*_*oof 5

您不能在扩展内声明存储的属性,只能声明计算的属性

所以你有两种方法:

  1. 在 MainBiblePagerVC 类中声明存储的属性

  2. 使用计算属性:

    extension MainBiblePagerVC: UISplitViewControllerDelegate{
        var interstitial: GADInterstitial! {
            // add object initialization here
            let object = GADInterstitial()
            // set its parameters 
            return object
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)