考虑到VIPER结构
我有两个模块,A和B.第一个模块A,通过演示者,想要执行必须在模块B中完成的动作,因此告诉它的线框执行它.问题是,谁负责实例化整个模块(视图,交互者,演示者......).我看到了一些不同方法的例子:
考虑到线框负责路由,它是否还负责创建其模块?
我有一个NSTimer
间隔为3秒的火焰来减少一个值.当我执行一个增加该值的操作时,我想重新启动计时器,从该点开始计算3秒.
例如,如果我增加值并且计时器将在1秒内触发,我想改变它并使计时器在3秒内激活.我可以使计时器无效并再次创建吗?或者我可以setFireDate:
使用当前日期并添加3秒的间隔吗?
在iPad中.我有一个UIViewController,里面有另一个UIview,在底部.
____________
| |
| |
| UIView |
| Controller |
| |
| |
| X |
------------
Run Code Online (Sandbox Code Playgroud)
UIView是X.
我在UIViewController的viewDidLoad上为它定义了一个autoresizingMask
self.view.autoresizeSubviews = YES;
// xView creation
xView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
Run Code Online (Sandbox Code Playgroud)
但是这不起作用,xView旋转正常,但是在横向屏幕边界上.
我错过了什么?
这个问题从未发生在我身上.我在UINavigationController中有一个UIViewController.当收到内存警告(没关注级别)时,会调用可见控制器的viewDidUnload
方法,因此卸载视图,我得到一个很棒的黑屏(顶部有一个导航栏).
我在iOS 4.3.3上使用iPad 1进行测试.
有什么建议?
我试图避免在UIWebView
委托返回类似错误时生成的问题.我在委托实现中有共同的解决方法(我在Internet的任何地方都看到过)
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if ([error code] == NSURLErrorCancelled) return;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,这并不总是有效.有时加载网络,另一次加载网页的一部分(标题,文本的一部分......),并且几次不加载任何东西.
还有其他解决方案吗?存在任何正常运行的浏览器的开源实现?
我正在寻找可用__attribute__(())
指令列表,我找不到它们.我只知道__attribute__((objc_requires_super))
.
我发誓我搜索和搜索,我没有找到任何东西.也许我错过了一些包含在搜索中的术语.
非常感谢.
我想测试我的API的合同,所以,例如,如果创建了一个带有一些参数的对象,nil
则会引发断言,但如果断言被禁用(Release config),它只返回nil.
我的测试方案有Debug的构建配置,所以在我的API契约测试中,我检查是否创建了一个带有nil参数的对象返回一个nil对象.但是在XCTAssertNil
执行之前会引发构造函数的断言,因此我的测试总是失败.
我可以在测试时禁用断言吗?我试图添加NS_BLOCK_ASSERTIONS
在启动时传递的方案参数,但这不起作用.
我想加密/解密NSURLSession
使用AES256的所有缓存数据.我是使用Alamofire的新手,但我认为可以在不涉及图书馆本身的情况下进行.
我不确切知道在缓存之前加密数据的最无缝方式是什么,并在从缓存中检索后对其进行解密.
我看我可以使用Alamofire的SessionDelegate
和方法dataTaskWillCacheResponse
,并dataTaskWillCacheResponseWithCompletion
进行加密,但我没有看到从缓存中做解密所提取的数据有关的任何东西.
另一方面,我正在考虑NSURLProtocol
重写的自定义,cachedResponse
但我没有看到与该响应的缓存有关的任何内容,只有提取的数据.
总而言之,我不知道是否有可能实现这一点,或者我必须在NSURLSessionDelegate/SessionDelegate
和之间使用混合NSURLProtocol
,或者可能使用子类NSURLCache
来完成工作并将其传递给Alamofire会话,或者有更简单的东西,或者我非常错误:P
任何帮助将非常感激.
我正试图通过下一个实现来实现它.首先是缓存的一个非常简单的子类:
class EncryptedURLCache: URLCache {
let encryptionKey: String
init(memoryCapacity: Int, diskCapacity: Int, diskPath path: String? = nil, encryptionKey: String) {
guard !encryptionKey.isEmpty else {
fatalError("No encryption key provided")
}
self.encryptionKey = encryptionKey
super.init(memoryCapacity: memoryCapacity, diskCapacity: diskCapacity, diskPath: path)
}
override func cachedResponse(for request: URLRequest) -> CachedURLResponse? {
objc_sync_enter(self)
defer { objc_sync_exit(self) }
return super.cachedResponse(for: request)?.cloneDecryptingData(withKey: …
Run Code Online (Sandbox Code Playgroud) 我想使用多点连接框架将视频从一个设备发送到另一个设备。
\n\n在对等点之间建立连接后,我使用常规方法从前置摄像头捕获视频AVCaptureSession
.
我正在按照这些步骤操作。
\n\n1)打开流:
\n\nfunc setupStreaming() {\n if let stream = p2pSession.startStream() {\n stream.delegate = self\n stream.schedule(in: RunLoop.main, forMode: .defaultRunLoopMode)\n stream.open()\n self.outputStream = stream\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n该p2pSession.startStream()
方法创建一个到已建立的对等点的流MCSession
,如果没有异常则返回它。
2)当视频输出通知帧已被捕获时,它会调用其委托方法
\n\nfunc captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {\n // \xc2\xbf?\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n3)在委托方法中MCSession
我必须获取输入流并提取数据。
func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {\n stream.delegate = self\n stream.schedule(in: RunLoop.main, forMode: .defaultRunLoopMode)\n stream.open() …
Run Code Online (Sandbox Code Playgroud) 在异步测试中,至少对我来说,很常见的是必须知道期望的实现计数才能知道如何断言。
例如,检查此场景的测试:
func testOne() {
let expectData = expectation(description: "data")
expectData.expectedFulfillmentCount = 2
var expectDataFulfillmentCount = 0
sut.data = {
expectData.fulfill()
expectDataFulfillmentCount += 1
if expectDataFulfillmentCount == 1 {
XCTAssertEqual(sut.numberOfItems, 3)
sut.fetchNextPage()
} else if expectDataFulfillmentCount == 2 {
XCTAssertEqual(sut.numberOfItems, 6)
}
}
sut.fetch()
waitForExpectations(timeout: 0.1, handler: nil)
}
Run Code Online (Sandbox Code Playgroud)
我对这种模式并不满意。我知道我可以稍微改变我在有期望时的主张,这样:
func testTwo() {
let expectFirstData = expectation(description: "firstData")
let expectSecondData = expectation(description: "secondData")
sut.data = {
if sut.numberOfItems == 3 {
expectFirstData.fulfill()
sut.fetchNextPage()
} else if …
Run Code Online (Sandbox Code Playgroud) ios ×7
objective-c ×2
xcode ×2
alamofire ×1
architecture ×1
asynchronous ×1
avfoundation ×1
cocoa-touch ×1
ipad ×1
iphone ×1
llvm ×1
memory ×1
nstimer ×1
nsurlcache ×1
nsurlsession ×1
rotation ×1
swift ×1
testing ×1
uiview ×1
uiwebview ×1
unit-testing ×1
xctest ×1