let renderEncoderOpt = commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor)
if let renderEncoder = renderEncoderOpt {
renderEncoder.setRenderPipelineState(pipelineState)
renderEncoder.setVertexBuffer(vertexBuffer, offset: 0, atIndex: 0)
renderEncoder.drawPrimitives(.Triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
renderEncoder.endEncoding()
}
上面的代码抛出一个
Initializer for conditional binding must have Optional type, not 'MTLRenderCommandEncoder'
如果我尝试将 renderEncoderOpt 设为可选,问题仍然存在。我已经尝试使用 guard let 与 if let 进行测试,并尝试将其设置为可选项,并重新声明类型等,但它一直回到这个问题。这在 swift 1/1.2 中工作正常
有人指点吗?
最佳答案
renderCommandEncoderWithDescriptor 不返回可选值,因此您应该完全删除 if let 条件绑定(bind),直接使用结果。
let renderEncoder = commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor)
renderEncoder.setRenderPipelineState(pipelineState)
renderEncoder.setVertexBuffer(vertexBuffer, offset: 0, atIndex: 0)
renderEncoder.drawPrimitives(.Triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
renderEncoder.endEncoding()
关于Swift to swift 2 守卫让,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34124474/
有没有办法制作一个简单的守卫watch?我想在特定目录中的文件更改时运行rake任务,并且完成所有这些步骤对于这个一次性任务来说太多了。https://github.com/guard/guard/wiki/Create-a-guard我尝试将它添加到Guardfile中,但它不起作用。guard:docdowatch(%r{^documentation}){"rakedoc:build"}endwatch("/documentation"){"rakedoc:build"}那么当文件更新为guard时,您是否知道一种运行rake任务的简单方法?? 最佳答案
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭9年前。Improvethisquestion我目前正在使用guard来监视我的.coffee和.scss文件的变化并适本地编译它们。现在,gruntjs和yeoman提供了类似的功能。从guard转向gruntjs或yeoman的动机是什么?使用yeoman和gruntjs有什么好处,反之亦然?谢谢!
我的索引路由定义为:{path:'/',adminOnly:false,component:Main},有没有办法访问“adminOnly”属性?在这段代码中似乎没有办法这样做:routes.beforeEach((to,from,next)=>{console.log(to)next();});我的路线文件:importVuefrom'vue';importVueRouterfrom'vue-router';importMainfrom'../components/Main.vue';importAboutfrom'../components/About.vue';constNotF
我知道我们可以将位于一个模块中的路由分组。像那样:canActivate:[AuthGuard],children:[{path:'',children:[{path:'crises',component:ManageCrisesComponent},{path:'heroes',component:ManageHeroesComponent},{path:'',component:AdminDashboardComponent}],}但我应该将那个守卫添加到每个模块的路由文件中。我有很多。我希望用户在未经授权的情况下不能转到除一条(登录路线)以外的任何路线。给所有的人加守卫的正确方法
如果我在一条路线上指定了三个守卫,似乎所有守卫都会被立即评估。{路径:'',组件:OptionsComponent,canActivate:[GuardOne,GuardTwo,GuardThree]}我遇到的问题是我不希望GuardTwo在GuardOne完成之前运行。有什么办法可以实现吗? 最佳答案 我认为这在4.1.3中是不可能的。Here是运行守卫的代码:privaterunCanActivate(future:ActivatedRouteSnapshot):Observable{constcanActivate=futur
我有一个使用两个守卫的Angular设置。canLoad和canActivate两者都通过@select从@angular-redux/store获取相同的可观察值问题:为什么canActivate与@select返回的可观察对象一起工作,而canLoad会中断所有路由然后呢?这两个守卫有什么区别?相关Angular问题:https://github.com/angular/angular/issues/18991auth.guard.ts@Injectable()exportclassAuthGuardimplementsCanLoad,CanActivate{@select()re
我有一个像下面这样的路由守卫@Injectable()exportclassAuthGuardimplementsCanActivate{constructor(privaterouter:Router,privateauthenticationSvc:AuthenticationService){}canActivate():Observable{returnthis.authenticationSvc.getAuthenticatedUser().map(r=>{if(this.authenticationSvc.isAuthenticated()){//loggedinsoret
我有一个在Windows机器上安装jdk8的windows_package资源,它看起来像这样:java_source="C:\\chef_solo\\utils\\jdk-8u121-windows-x64.exe"package_name="Java(TM)SEDevelopmentKit8(64-bit)"windows_packagepackage_namedosourcejava_sourceaction:installinstaller_type:customoptions"/s#{additional_options}"end问题是每个Chef都运行,它安装相同的jdk并
前言:最近在做项目时候,遇到了返回时候如果用户没有保存表单,需要拦截路由跳转,并给出提示信息是否要退出。相信做过vue项目的小伙伴都对vue的路由守卫并不陌生,react中如何实现呢?(本分享是针对react-router的v5版本)一、使用Prompt组件来完成闲话不多说直接上干货,react-router包里边给我们提供了一个组件,来帮助我们完成路由守卫。它有两个参数when和message。参数名称类型作用whenbooleantrue弹窗false顺利跳转messagefunction或者字符串函数返回true就顺利跳转,false停止跳转字符串就弹窗字符串并停止跳转。when值mes
在我的项目中,我有两个守卫。AuthGuard和PermissionGuard。我需要首先运行AuthGuard,当它解决时,如果permissionGuard为真,permissionGuard开始但现在这个守卫并行运行并且permissionGuard不能正常工作。我用于此问题的方法是在Permissionguard中调用AuthGuardCanActivate方法,但我认为有更好的方法来执行此操作。 最佳答案 我见过的最好的方法是在子路由上公开路由守卫。这是一个workingexample.{path:'',canActiva