Tag: swift3

Swift – 显示时间的更新/刷新标签

我有一个以12小时格式显示当前时间的标签。 但是,它不会每分钟/小时变化更新/刷新时间。 我需要它自动更改标签到当前时间,当时间改变。

如何使用Swift 3.0设置BarChart X轴和Y轴标签

在Swift 2.3中,我可以为x轴和y轴设置标签。 但在Swift 3.0中,我无法设置它。 func setChart(dataPoints: [String], values: [Double]) { barChartView.noDataText = "You need to provide data for the chart." for i in 0..<dataPoints.count { let dataEntry = BarChartDataEntry(x: Double(i), yValues: [values[i]]) dataEntries.append(dataEntry) } let chartDataSet = BarChartDataSet(values: dataEntries, label: "INR Rates(₹)/$") let chartData = BarChartData(dataSet: chartDataSet) barChartView.data = chartData barChartView.xAxis.labelPosition = .bottom barChartView.rightAxis.enabled = […]

定期的背景同步

我相当新的iOS编程,现在想要实现定期的后台同步来同步我的服务器数据与客户端数据。 我想要实现的是与Android SyncAdapter相媲美,您可以在其中定义一个时间间隔(例如每30分钟),系统将在后台自动触发定义的任务。 到目前为止,我无法findSwift 3.0的这种机制,所以我需要问问somone对我有没有经验或者一些提示。 我想要做的事听起来很简单: 当应用程序第一次启动时,应用程序应该设置一个同步pipe理器,每30分钟自动触发一个后台任务。 后台任务负责同步服务器和客户端数据(使用Alamofire)。 我怎样才能做到这一点?

如何在日历中获取前一个和下一个月

我试图通过点击button得到前一个和下个月,但这已经改变了我的一年,而不是一个月。 我正在尝试使用这个链接,但它在Objective-C中。 func firstDateOfMonth(){ let components = calendar.components([.Year, .Month], fromDate: date) let startOfMonth = calendar.dateFromComponents(components)! print(dateFormatatter.stringFromDate(startOfMonth)) // 2015-11-01 } func lastDateOfMonth(){ let components = calendar.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: date) let month = components.month let year = components.year let startOfMonth1 = ("01-\(month)-\(year)") var startOfMonth : NSDate? var lengthOfMonth : NSTimeInterval = 0 calendar.rangeOfUnit(.Month, […]

NS在Swift 3中的通知

新通知目前不在Swift 3中工作吗? 我在做: NotificationCenter.default().post(name: DidTouchParticleView, object: self.particle as? AnyObject) 在自定义视图的touchesBegan()中,我需要发送particle对象到视图控制器(如果有的话)。 所以我这样做: NotificationCenter.default().addObserver(forName: DidTouchParticleView, object: self, queue: OperationQueue.main(), using: presentParticleDisplayView(notification:)) 在视图控制器的viewDidLoad()中。 我确定那个特定的视图控制器是当我点击我的自定义视图时呈现的,但是,函数presentParticleDisplayView(notification:)从来没有被调用过。 另外, DidTouchParticleView是这样定义的: let DidTouchParticleView = NSNotification.Name("didTouchParticleView") 这是由于testing版,或者我做错了什么?

不符合协议'NSCoding' – Swift 3

我看过几个类似于我的问题。 然而,这些都属于迅速2/1,我目前正在使用迅速3.我相信苹果已经稍微改变了它。 class Person: NSObject, NSCoding { var signature: UIImage init(signature: UIImage) { self.signature = signature } required convenience init(coder aDecoder: NSCoder) { let signature = aDecoder.decodeObject(forKey: "signature") as! UIImage self.init(signature: signature) } func encodeWithCoder(aCoder: NSCoder) { aCoder.encode(signature, forKey: "signature") } } 你会注意到Swift 3如何迫使我使用required convenience init(而不是required init(或许这与它有关)。 我该如何解决这个问题? 谢谢!

Swift 3.0中的NSIndexPath和IndexPath

我最近把我的代码转换成了Swift 3.0。 我的集合视图和表视图数据源方法现在在它们的方法签名中包含IndexPath而不是NSIndexPath 。 但是在方法定义里面仍然是对NSIndexPathtypes转换IndexPath。 即 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell : NNAmenitiesOrFurnishingCollectionViewCell = self.amenitiesOrFurnishingCollectionView.dequeueReusableCell(withReuseIdentifier: "NNAmenitiesOrFurnishingCollectionViewCell", for: indexPath) as! NNAmenitiesOrFurnishingCollectionViewCell cell.facilityImageName = self.facilityArray[(indexPath as NSIndexPath).row].imageName cell.facilityLabelString = self.facilityArray[(indexPath as NSIndexPath).row].labelText return cell } 任何人都可以告诉我为什么indexPathtypes转换为NSIndexPath 。

Swift 3 Decimal,NSDecimal和NSDecimalNumber

我想用Swift 3 Decimal来使用NumberFormatter ,但我很困惑如何实现Decimal 。 我遇到的问题是Decimal是一个结构体,所以每次我想使用一个格式化程序时,我都必须将其连接到一个NSDecimalNumber ,这是我想避免的。 let formatter = NumberFormatter() formatter.numberStyle = .decimal let decimal = Decimal(integerLiteral: 3) let string = formatter.string(from: decimal as NSDecimalNumber) 是这个实现我自己的扩展需要Decimal的理想解决方法? extension NumberFormatter { open func string(from number: Decimal) -> String? { return string(from: number as NSDecimalNumber) } } 更一般地说,每次我需要传递一个对象types时,我将需要桥接Decimal或写更多的扩展? 编辑 我想我一般NSDecimal知道Swift 3中的NSDecimal Decimal和NSDecimalNumber 。我不清楚这里发生了什么事情。 我应该用Swift 3的DecimalreplaceNSDecimalNumber吗? 该文档写道: Swift覆盖到Foundation框架提供了Decimal结构,它桥接到NSDecimalNumber类。 […]

如何正确加载数千条logging到领域?

我试图使用Realm将大约8000条logging保存到磁盘中,但它阻止了UI。 因此,我使用Realm.asyncOpen在后台线程中执行数据保存。 当我尝试以这种方式保存大量logging时,问题是100%的CPU使用率。 如何正确加载数千条logging到领域?

Facebook SDK使用Swift 3 iOS 10login

我通过Cocoapods安装了Facebook的Swift SDK: pod 'FacebookCore', :git => "https://github.com/facebook/facebook-sdk-swift" pod 'FacebookLogin', :git => "https://github.com/facebook/facebook-sdk-swift" 我遵循Facebook的Swift SDK( https://developers.facebook.com/docs/swift/login )的login说明,但无法正常工作。 在我的视图控制器里面我有以下几点: @objc fileprivate func facebookSignIn() { let loginManager = LoginManager() print("LOGIN MANAGER: \(loginManager)") loginManager.logIn([ .publicProfile, .email ], viewController: self) { loginResult in print("LOGIN RESULT! \(loginResult)") switch loginResult { case .failed(let error): print("FACEBOOK LOGIN FAILED: \(error)") case .cancelled: print("User cancelled […]