Tag: 迅速

typesMCSessionState不符合协议“AnyObject”

我收到以下代码的错误: var dict: Dictionary<String, AnyObject> = [ "peerID": peerID, "state": state ] 我正在使用MultipeerConnectivity :peerID的types为MCPeerID(例如, MCPeerID(displayName: "morpheus") ),并且状态是MCSessionState(枚举,例如, MCSessionState.Connected )。 显然,我不能将枚举转换为AnyObject? 我该如何解决这个问题? 最好。 编辑:我尝试使用Dictionary <String,Any>,但现在我在下一个调用中得到一个exception。 代码如下: func session(session: MCSession!, peer peerID: MCPeerID!, didChangeState state: MCSessionState) { var dict: Dictionary<String, Any> = [ "peerID": peerID, "state": state ] NSNotificationCenter.defaultCenter().postNotificationName( "MCDidChangeStateNotification", object: nil, userInfo: dict ) } Xcode表示“userInfo:dict”行,例外: […]

保存图像到领域

我想知道是否有可能将图像保存到领域数据库。 如果是,我该怎么做? 我只懂Swift! 先谢谢你

调用一个计时器来更新swift的path

我有这个代码,它工作很好 class CircleView: UIView { required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! } override init(frame: CGRect) { super.init(frame: frame) } func degreesToRadians (number: Int) -> CGFloat { return CGFloat(number) * CGFloat(M_PI) / 180.0 } override func drawRect(rect: CGRect) { let startAngle: CGFloat = degreesToRadians(0) let endAngle: CGFloat = degreesToRadians(270) let radius: CGFloat = 40.0 let […]

如何在iOS应用程序中将.svg url显示为图像

我从服务器获取.svgurl。 我怎样才能在我的应用程序中显示它的形象。 我试图在UIWebView中显示它,但我无法调整内容图像的大小。 我正在使用这个代码 let request: NSURLRequest = NSURLRequest(url: URL(string: "https://upload.wikimedia.org/wikipedia/en/c/c3/Flag_of_France.svg")!) webView.scalesPageToFit = true webView.contentMode = .scaleAspectFit webView.loadRequest(request as URLRequest) 我的问题是什么

用2行截断UILabel的头部

我有一个UI的标签numberOfLines为2和lineBreakMode =截断头 但是当我运行它而不是像第一行截断头 …1st Line Content 2nd Line Content 它截断像 1st Line Content …2nd Line Content 我如何在第一行截断标签的头部?

Firebase快照顺序错误

我尝试将我在firebase中存储的post加载到我的tableView中。 我使用.childAdded函数按发布顺序(首先到最后)获取post。 首先它似乎工作,但现在它不再工作,我不知道为什么。 所以我给post添加了一个时间戳,并使用queryOrderedByChild(“timestamp”)。 依然错误的顺序! 这是我的代码: posts.removeAll() let ref = FIRDatabase.database().reference() ref.child("Posts").queryOrderedByChild("timestamp").observeEventType(.ChildAdded, withBlock: { (snapshot:FIRDataSnapshot) in print(snapshot.value!["timestamp"] as! Int) if snapshot.value == nil { return } let post = Post() post.title = snapshot.value!["Title"] as? String post.postType = snapshot.value!["postType"] as? Int post.postDescription = snapshot.value!["Description"] as? String if post.postType == 2 { post.imageAURL = snapshot.value!["imageAURL"] as? String […]

Swift 3'?' 不能转换为''

我有一个从Swift 2转换到Swift 3的TVOS应用程序,我得到以下错误。 我不确定如何保持沉默。 '[UIApplicationLaunchOptionsKey:Any]?' 不能转换为'[String:NSString]' 它显示在这段代码中 appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL if let launchOptions = launchOptions as? [String: AnyObject] { for (kind, value) in launchOptions { appControllerContext.launchOptions[kind] = value } } 添加: /* Copyright (C) 2015 Hani Hamrouni. All Rights Reserved. */ import UIKit import TVMLKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDelegate { // MARK: Properties […]

保证在正确的时间ios交付的UILocalNotification

我的本地通知存在问题: 如果设备处于closures状态或更改电话date ,通知将保持在队列中,并随着下一个通知一起开始。 为什么? 由于需要非常关注通知date。如何保证正确的通知发送? 我们应该在哪里放置删除过期通知的代码?

用SecRandomCopyBytes生成范围内的随机数

我使用SecRandomCopyBytes来生成一个安全的随机数字。 有没有办法指定一个“范围”? 我需要获得这段Java代码的相同的行为: SecureRandom r = new SecureRandom(); char x = (char)(r.nextInt(26) + 'a'); 任何提示将感激! UPDATE 看到我做了一个愚蠢的问题,我觉得不得不分享解决scheme,扩大了Inttypes: public extension Int { /** Create a random num Int in range :param: lower number Int :param: upper number Int :return: random number Int */ public static func random(#min: Int, max: Int) -> Int { return Int(arc4random_uniform(UInt32(max – […]

如何从新的Firebase存储下载和查看图像?

我可以将图片上传到Firebase存储,但我无法下载它们。 这是我的代码下载图像: let storage = FIRStorage.storage() let localURL : NSURL! = NSURL(string: "file:///Documents/co.png") // i also tried let localURL : NSURL! = NSURL.fileURLWithPath("file:///Documents/co.png") func download() { let storageRef = storage.referenceForURL("gs://project-5547819591027666607.appspot.com") let imageRef = storageRef.child("co.png") let downloadTask = imageRef.writeToFile(localURL) { (URL, error) -> Void in if (error != nil) { print(error?.localizedDescription) } else { self.imageView.image = […]