【发布时间】:2021-05-22 07:53:29
【问题描述】:
for postdata in postdata {
if index < tableViewItems.count {
tableViewItems.insert(postdata, at: index)
index += adInterval
} else {
break
}
}
我需要在同一个 AnyObject Var 上添加 PostData 广告和 Native Ads 才能使其正常工作,但我找不到添加 Post Data 的方法,因为它显示出现错误提示“参数类型'PostData' 应为类或类约束类型的实例。”非常感谢您的帮助,谢谢。
编辑 1
class Ad {
var postimage: String!
var publisher: String!
var timestring: String!
var timestamp = Date().timeIntervalSince1970
}
class PostDataAd: Ad {
// Declare here your custom properties
struct PostData1
{
var postimage: String
var publisher: String
var timestring : String
var timestamp = Date().timeIntervalSince1970
}
}
class NativeAd: Ad {
// Declare here your custom properties
struct NativeAd
{
var nativeAds: [GADUnifiedNativeAd] = [GADUnifiedNativeAd]()
}
}
我的模型类将两个数据合并到一个 AnyObject Var
然后尝试通过执行此操作从 Firebase 追加数据
var ads: [Ad] = [PostDataAd(), NativeAd()]
let postList = PostDataAd.PostData1(postimage: postimage, publisher:
postpublisher, timestring: postid, timestamp: timestamp)
self.ads.insert(postList, at:0)
发生错误,提示无法将类型“PostDataAd.PostData1”的值转换为预期的参数类型“广告”
【问题讨论】:
-
什么是
PostData,什么是tableViewItems?它们是如何声明的? -
PostData 是来自 Firebase 的数据,而 tableViewItems 是我试图将我的 PostData 存储在其中的 AnyObject 数组
标签: ios swift xcode admob native-ads