简体   繁体   English

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

[英]Getting an error: “Extensions may not contain stored properties”

I am new in Swift and xcode. 我是Swift和xcode的新手。 I am trying to declare a GoogleMobileAds variable inside a UISplitViewControllerDelegate , but I am getting an error: Extensions may not contain stored properties. 我想声明内GoogleMobileAds变量UISplitViewControllerDelegate ,但我得到一个错误:扩展名可能不包含存储性能。

Here is my code: 这是我的代码:

import GoogleMobileAds

extension MainBiblePagerVC: UISplitViewControllerDelegate{
    // Setup Navigation Items in Bible Page
    var interstitial: GADInterstitial!

Thanks! 谢谢!

You can't declare stored properties inside extension, only computed ones 您不能在扩展内部声明存储的属性,只能声明计算的属性

So you have two ways: 因此,您有两种方法:

  1. declare stored property inside your class MainBiblePagerVC 在类MainBiblePagerVC中声明存储的属性

  2. use computed property: 使用计算属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 扩展名可能不包含存储的属性 - Extensions May not contain Stored properties Objective C&Swift互操作性导致错误“扩展可能不包含存储的属性” - Objective C & Swift Interoperability causes error “Extensions may not contain stored properties” 扩展 class 中的 Var 显示错误“扩展不得包含存储的属性” - Var in extension class show error “Extensions must not contain stored properties” “扩展可能不包含存储的属性”,除非你是 Apple? 我错过了什么? - "Extensions may not contain stored properties" unless your are Apple? What am I missing? “扩展不能包含存储的属性”阻止我重构代码 - "Extensions must not contain stored properties" preventing me from refactoring code 想要保存核心数据,但“扩展不得包含存储的属性” - Want to save Core Data but “Extensions must not contain stored properties” 扩展名可能不包含存储的属性,并且迅速没有成员问题 - extension may not contain stored properties and no member problems in swift 具有存储属性的扩展 - Extensions with stored properties 有什么解决方法可以快速将存储的属性放入扩展中? - is there any workaround to put stored properties into extensions in swift? 为什么Swift不允许在扩展中存储属性? - Why does Swift not allow stored properties in extensions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM