草庐IT

as-patterns

全部标签

ios - 开启 UIButton title : Expression pattern of type 'String' cannot match values of type 'String?!'

我正在尝试在@IBAction方法中使用一个开关,该方法连接到多个按钮@IBActionfuncbuttonClick(sender:AnyObject){switchsender.currentTitle{case"Button1":print("ClickedButton1")case"Button2":print("ClickedButton2")default:break}当我尝试上述操作时,出现以下错误:Expressionpatternoftype'String'cannotmatchvaluesoftype'String?!' 最佳答案

design-patterns - 协议(protocol):为什么一致性检查和可选要求需要@ObjC?

Swiftdocumentation以下是关于协议(protocol)的内容:Youcancheckforprotocolconformanceonlyifyourprotocolismarkedwiththe@objcattribute,asseenfortheHasAreaprotocolabove.ThisattributeindicatesthattheprotocolshouldbeexposedtoObjective-CcodeandisdescribedinUsingSwiftwithCocoaandObjective-C.Evenifyouarenotinteroper

objective-c - swift 2 : no delegate callbacks for push notifications as opposed to objective-c

我已经创建了2个示例(单一View)项目来测试推送通知,除了如下通知设置代码外,我没有添加任何代码:项目1(Swift2):funcapplication(application:UIApplication,didFinishLaunchingWithOptionslaunchOptions:[NSObject:AnyObject]?)->Bool{letsettings=UIUserNotificationSettings(forTypes:[.Alert,.Badge,.Sound],categories:nil)UIApplication.sharedApplication().

ios - Xcode 7 : show same console log for release build as development build?

Thisanswer解决了如何在Xcode中显示控制台日志,但出现在应用开发版本中的Swift中使用print函数打印的输出不会出现在发布版本中。需要说明的是,该应用程序是从AppStore下载的,然后打开了Xcode,控制台日志显示如SO答案所述。Thisanswer建议print函数继续将输出发送到控制台,即使对于发布版本也是如此。但是,为开发版本打印到控制台的行不再出现在AppStore版本中。您如何查看与开发版本相同的控制台输出? 最佳答案 即使是发布版本,打印功能也会继续发送输出,但它不会出现在控制台上。要查看输出,请转至

ios - NSKeyValueObservation : Cannot remove an observer for the key path from object because it is not registered as an observer

我的应用出现随机崩溃(我无法在我拥有的设备上重现),但有以下异常(exception):CannotremoveanobserverFoundation.NSKeyValueObservation0xaddressforthekeypath"readyForDisplay"fromAVPlayerLayer0xaddressbecauseitisnotregisteredasanobserver.当我释放一个包含AVPlayerLayer的UIView时会发生这种情况。我的初始化:privatevarplayerLayer:AVPlayerLayer{returnself.layera

swift - "NSURL"不能隐式转换为 "URL";您的意思是使用 "as"进行显式转换吗?

我有最新的xcodebeta,只是想在应用程序中加载网页。importUIKitclassViewController:UIViewController{@IBOutletvarwebView:UIWebView!overridefuncviewDidLoad(){super.viewDidLoad()//Doanyadditionalsetupafterloadingtheview,typicallyfromanib.leturl=NSURL(string:"https://www.google.com");letrequestObj=NSURLRequest(URL:url!);w

cocoa - 在 Swift 中使用 as 和 as 向下转型?

这两个代码片段有什么区别:letcell=tableView.dequeueReusableCellWithIdentifier("cellId")asUITableViewCell?//vsletcell=tableView.dequeueReusableCellWithIdentifier("cellId")as?UITableViewCell结果不完全一样吗? 最佳答案 在该代码中没有区别,在这两种情况下它的计算结果都是UITableViewCell?真正的区别在于:在第一种情况下,向下转换为UITableViewCell?预

xcode - iOS 错误 "Embedded binary is not signed with the same certificate as the parent app"

这是我在IOS应用程序开发中的第一步,我遇到了一些我无法弄清楚的问题。error:Embeddedbinaryisnotsignedwiththesamecertificateastheparentapp.Verifytheembeddedbinarytarget'scodesignsettingsmatchtheparentapp's.EmbeddedBinarySigningCertificate:NotCodeSignedParentAppSigningCertificate:iPhoneDeveloper:EmilAdz(9QNEF95395)我不明白,什么是嵌入式二进制签名证

generics - 为什么这个协议(protocol)可以 "only be used as a generic constraint"?

我正在尝试在Swift中执行以下操作:protocolProtocolWithAlias{typealiasT}protocolAnotherProtocol{funcsomeFunc()->ProtocolWithAlias}但我收到错误:Protocol'ProtocolWithAlias'canonlybeusedasagenericconstraintbecauseithasSelforassociatedtyperequirements。有没有可能做这样的事情?错误消息(或者至少是“onlybeusedasagenericconstraint”部分)对我来说似乎没有多大意义。

swift - "as?"、 "as!"和 "as"之间有什么区别?

在升级到Swift1.2之前,我可以编写以下行:ifletwidth=imageDetails["width"]asInt?现在它迫使我写下这一行:ifletwidth=imageDetails["width"]as!Int?我的问题是,如果我被迫像上面那样写,难道我不能只写下面的代码并且它会做同样的事情吗?它会在imageDetails的所有值中给我相同的结果吗?ifletwidth=imageDetails["width"]asInt 最佳答案 用于向上转型和向下转型的as关键字://BeforeSwift1.2varaView