获取错误:“扩展可能不包含存储的属性”
问题描述:
我是Swift和xcode中的新成员。我试图在UISplitViewControllerDelegate
中声明一个GoogleMobileAds变量,但是出现错误:扩展名可能不包含存储的属性。获取错误:“扩展可能不包含存储的属性”
这里是我的代码:
import GoogleMobileAds
extension MainBiblePagerVC: UISplitViewControllerDelegate{
// Setup Navigation Items in Bible Page
var interstitial: GADInterstitial!
谢谢!
答
不能声明里面存储的扩展属性,只有那些计算
所以,你有两种方式:
类MainBiblePagerVC使用计算物业内
-
申报存储的属性:
extension MainBiblePagerVC: UISplitViewControllerDelegate{ var interstitial: GADInterstitial! { // add object initialization here let object = GADInterstitial() // set its parameters return object } }
您是否在错误中检查了[这些搜索结果](https://stackoverflow.com/search?q=Extensions+may+not+contain+stored+properties)? – rmaddy
你应该阅读[Extensions](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Extensions.html#//apple_ref/doc/uid/TP40014097-CH24-ID151) Swift书的一章。 – rmaddy
尝试了解错误消息。这一点很明显:'interstitial'是一个存储的属性,* Extensions可能不包含存储的属性*。 – vadian