if let buttonBeep = self.setupAudioPlayerWithFile("ButtonTap", type: "wav") {
            
            self.buttonBeep = buttonBeep
        }
        if let secondBeep = self.setupAudioPlayerWithFile("SecondBeep", type: "wav") {
           
            self.secondBeep = secondBeep
        }
        if let backgroundMusic = self.setupAudioPlayerWithFile("HallOfTheMountainKing", type: "mp3") {
            
            self.backgroundMusic = backgroundMusic
        }

这样写就报错了initializer for conditional binding must have optional type not AVAudioPlayer。

最后将代码改为:

if let buttonBeep: AnyObject = self.setupAudioPlayerWithFile("ButtonTap", type: "wav") {
            
            self.buttonBeep = buttonBeep as? AVAudioPlayer
        }
        if let secondBeep:AnyObject = self.setupAudioPlayerWithFile("SecondBeep", type: "wav") {
           
            self.secondBeep = secondBeep as? AVAudioPlayer
        }
        if let backgroundMusic:AnyObject = self.setupAudioPlayerWithFile("HallOfTheMountainKing", type: "mp3") {
            
            self.backgroundMusic = backgroundMusic as? AVAudioPlayer
        }

就没有问题了。

initializer for conditional binding must have optional type not AVAudioPlayer的更多相关文章

  1. Initializer for conditional binding must have Optional type, not 'String'

    今天看到问Swift问题:  Initializer for conditional binding must have Optional type, not 'String' 以前没遇到过这个问题, ...

  2. swift:Optional Type 、Swift和Objective-C混编的讲解

    ❤️❤️❤️swift中的Optional Type的?和!含义:其实就是一个装包和拆包的过程 optional的含义: Optional事实上是一个枚举类型,Optional包含None和Some两 ...

  3. 随手记Swift基础和Optional Type(问号?和感叹号!)

    距离Apple推出Swift已经有几天了,网上也时不时出现"急招Swift程序猿,要求有一天工作经验"的帖子. 看到Swift,除了苹果放的另外一门语言的链接(http://swi ...

  4. eslint报错: Unexpected any value in conditional. An explicit comparison or type cast is required

    原代码: record.modifiedTime? 修改后代码:typeof record.modifiedTime !== 'undefined' ?   (isAddType === true ? ...

  5. 使用swift 中的注意,不断完善中

    1. 应该充分利用swfit的新特性 比如如果按照oc里的习惯,调用一个delegate中都optional函数应该这样写 if delegate != nil && delegate ...

  6. swift的一些知识点(不断完善中)

    首先,隆重推荐文章http://www.infoq.com/cn/articles/swift-brain-gym-optional swift 烧脑体操!目前有4篇文章,说的都很好! 1. 应该充分 ...

  7. Swift的Optional类型

    我们使用Swift这个苹果新推出的编程语言已经有一段时间了.其中的一个极大的优点就是苹果称为“optional types”的东西.几乎所有的objective-c程序员都知道用nil来表示某个引用类 ...

  8. When do we use Initializer List in C++?

    Initializer List is used to initialize data members of a class. The list of members to be initialize ...

  9. [翻译]理解Swift中的Optional

    原文出处:Understanding Optionals in Swift 苹果新的Swift编程语言带来了一些新的技巧,能使软件开发比以往更方便.更安全.然而,一个很有力的特性Optional,在你 ...

随机推荐

  1. Atitit.一个cms有多少少扩展点,多少api wordpress  cms有多少api。。扩展点

    Atitit.一个cms有多少少扩展点,多少api wordpress  cms有多少api..扩展点 1. Api分类 WordPress APIs1 1.1. 1 函数分类2 1.2. 函数api ...

  2. 重要选择器querySelector和querySelectorAll

    他们的作用是根据 CSS 选择器规范,便捷定位文档中指定元素. 目前几乎主流浏览器均支持了他们.包括 IE8(含) 以上版本. Firefox. Chrome.Safari.Opera. queryS ...

  3. 推送(PUSH)

    一.本地推送 1.建立本地推送 UILocalNotification *notification = [[UILocalNotification alloc] init]; //推送的内容 noti ...

  4. 图片代替radio

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  5. [转]Jquery easyui开启行编辑模式增删改操作

    本文转自:http://www.cnblogs.com/nyzhai/archive/2013/05/14/3077152.html Jquery easyui开启行编辑模式增删改操作先上图 Html ...

  6. dipole antenna simulation by HFSS

    工作频点为1GHz,新建工程,添加新设计,编辑添加下面的变量 建立天线模型,即两个金属圆柱.编辑完一个振子后,另一半可以用镜像命令产生参数如下设置 ,材料为PEC 两个圆柱间建立一个矩形片,连接两个圆 ...

  7. 【NOIP合并果子】uva 10954 add all【贪心】——yhx

    Yup!! The problem name reects your task; just add a set of numbers. But you may feel yourselvesconde ...

  8. codeforces 484B B. Maximum Value(二分)

    题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. css3中box-flex的使用

    语法: box-flex:<number> 其中number取值:使用浮点数指定对象所分配其父元素剩余空间的比例.设置或检索伸缩盒对象的子元素如何分配其剩余空间. html代码: < ...

  10. HDU 2298 Toxophily 【二分+三分】

    一个人站在(0,0)处射箭,箭的速度为v,问是否能够射到(x,y)处,并求最小角度. 首先需要判断在满足X=x的情况下最大高度hmax是否能够达到y,根据物理公式可得 h=vy*t-0.5*g*t*t ...