小编use*_*103的帖子

将ObjC-Blocks转换为Swift Closures

我试图将一些Objective-C Code翻译成Swift.我将Autolayout的Cocoapod"Masonry"添加到我的项目中,并添加了一个Bridging-Header,以便能够在Swift中使用Objective-C方法.

这个ObjC方法:

[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(self.view);
}];
Run Code Online (Sandbox Code Playgroud)

应该像以下关闭:

tableView.mas_makeConstraints({ (make : MASConstraintMaker!) -> Void? in
    make.edges.equalTo(self.view)
})
Run Code Online (Sandbox Code Playgroud)

但我得到一个"找不到成员'mas_makeConstraints'",这不是错误,因为该方法已编入索引并且autocomletion给了我以下内容:

tableView.mas_makeConstraints(block: ((MASConstraintMaker!) -> Void)?)
Run Code Online (Sandbox Code Playgroud)

?!

我在这里做错了吗?

closures objective-c ios objective-c-blocks swift

10
推荐指数
2
解决办法
2481
查看次数

单元测试 PHFetchResult

我正在尝试对检索 assetCollection 和 asset 进行单元测试。为了能够访问我的相册,我必须授予权限。这通常发生在第一次调用函数(如)期间,fetchAssetCollections或者通过手动调用PHPhotoLibrary.requestAuthorization().

现在的问题是,在运行单元测试时如何假设我有权限?因为我PHAssetCollection.fetchAssetCollections(withLocalIdentifiers: [ album ], options: nil)一打电话就收到了PHUnauthorizedFetchResult

unit-testing ios swift phphotolibrary

5
推荐指数
0
解决办法
710
查看次数