我正在检查.lazy高阶函数,并且得到了一些与flatMap函数相关的有趣编译错误(可能还有其他函数)
例子
let array = [1, 2, 3, 4, 5, 6]
array
.flatMap {
print("DD")
return $0 // Cannot convert return expression of type 'Int' to return type 'String?'
}
.forEach {
print("SS")
print($0)
}
评论一下
array
.flatMap {
// print("DD")
return $0
}
.forEach {
print("SS")
print($0)
}
一切正常......更有趣的例子
array
.flatMap {
let z = $0
return $0 // Or return z - all is the same "Cannot convert return expression of type 'Int' to return type … 我用UICollectionViewCompositionalLayout。所有部分都有圆形背景。背景刚刚添加到所有部分
let background = NSCollectionLayoutDecorationItem.background(elementKind: "background")
section.decorationItems = [background]
Run Code Online (Sandbox Code Playgroud)
后来注册了
layout.register(RoundedView.self, forDecorationViewOfKind: "background")
Run Code Online (Sandbox Code Playgroud)
问题是:如何更改背景视图的颜色?是否有使视图出队的功能?我已经尝试过了
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
preconditionFailure("")
}
Run Code Online (Sandbox Code Playgroud)
但它没有被调用
所有相关代码:相当愚蠢的背景视图
final class RoundedView: UICollectionReusableView {
override init(frame: CGRect) {
super.init(frame: frame)
config()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
config()
}
private func config() {
self.layer.cornerRadius = Constant.Dimens.cornerRadius
self.clipsToBounds = true
}
}
Run Code Online (Sandbox Code Playgroud)
进行布局
@available(iOS 13, *)
private static func makeLayout() -> UICollectionViewLayout {
let itemSize …Run Code Online (Sandbox Code Playgroud) 我需要将视频文件保存到临时目录并保存对其 URL 的引用。目前我尝试使用 fileManager 创建临时目录,然后 createFile(atPath: tempDirString,contents:vidData,attributes:nil)。但我无法保存对该文件的完整引用。
我尝试过的:
PHCachingImageManager().requestAVAsset(forVideo: (cell?.assetPH)!, options: nil) { (avAsset, _, _) in
if let avAsset = avAsset {
print(avAsset, " the avasset?")
// vidAVAsset = avAsset
let avPlayerItem = AVPlayerItem(asset: avAsset)
let avPlayer = AVPlayer(playerItem: avPlayerItem)
print(avPlayer, "<-- good?")
let finalURL = self.urlOfCurrentlyPlayingInPlayer(player: avPlayer)
print(finalURL, "<-- finalURL YEAH EYAHY YEAH?!?!?")
// newUserTakenVideo.videoURL = finalURL
let url = self.addVidToTempURL(vidURL: finalURL!)
newUserTakenVideo.videoURL = url
// let newUserTakenVideo = SelectedMedia(videoURL: finalURL, phAsset: (cell?.assetPH)!, thumbnailImg: (cell?.imageView.image)!, uniqueCellID: indexPath)
// …Run Code Online (Sandbox Code Playgroud)