swift3

UIUserNotificationType was deprecated in iOS10 Swift 3.0

僤鯓⒐⒋嵵緔 提交于 2019-12-21 12:22:06
问题 I am getting this warning in iOS 10 which previously is working fine on iOS 9 :- Is there another function to fix this warning in iOS 10, appreciated if anyone would have idea for this issue. 回答1: in iOS10 UIUserNotificationType has deprecated , use UNUserNotificationCenter dont forget to enable this for Swift3 for sample see this import the UserNotifications framework and add the UNUserNotificationCenterDelegate in Appdelegate import UserNotifications @UIApplicationMain class AppDelegate:

how to compare date in swift 3.0?

China☆狼群 提交于 2019-12-21 12:19:30
问题 I have two dates and I want to compare it. How can I compare dates? I have to date objects. Say modificateionDate older updatedDate . So which is the best practice to compare dates? 回答1: Date now conforms to Comparable protocol. So you can simply use < , > and == to compare two Date type objects. if modificateionDate < updatedDate { //modificateionDate is less than updatedDate } 回答2: Per @NiravD's answer, Date is Comparable . However, if you want to compare to a given granularity, you can use

Swift 3 and NumberFormatter (.currency) == ¤?

强颜欢笑 提交于 2019-12-21 11:07:28
问题 Xcode 8.0 (8A218a) GM Target : iOS 10 (Swift 3) Consider the following code: let number = NSDecimalNumber(decimal: 22.4) let numberFormatter = NumberFormatter() numberFormatter.numberStyle = .currency numberFormatter.locale = Locale.current let result = numberFormatter.string(from: number) print(result!) The result is: ¤22.40 (I have no idea what ¤ means.) But if I initialize the locale such as: numberFormatter.locale = Locale(identifier: "en_US") The result will be: $22.40 ... which is what

NSFontAttributeName vs NSAttributedStringKey.font

怎甘沉沦 提交于 2019-12-21 09:59:29
问题 I am having some trouble with Swift code in a library I have been using for a while. It seems related to some kind of version conflict, but I am not sure. Here is the code: let attribMsg = NSAttributedString(string: msg, attributes: [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 23.0)]) Here is the error message I get from the compiler: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font' Did you mean 'zone'? Fix(button) Using this code in different project I noticed that

NSDate from Swift 2.3 to Date from Swift 3 Conversion

♀尐吖头ヾ 提交于 2019-12-21 09:28:34
问题 So I've just updated to Xcode 8 and converted my Swift 2.3 code to Swift 3, and Swift 3 just converted all NSDate to Foundation.Date And I had an extension for NSDate , now called Foundation.Date , it looked like this: extension NSDate { var firstDayOfTheMonth:NSDate { var date: NSDate? NSCalendar.currentCalendar().rangeOfUnit(.Month, startDate:&date , interval: nil, forDate: self) return date! } } And Swift 3 converted it to this: extension Foundation.Date { var firstDayOfTheMonth:Foundation

How to insert new data to entity in Swift3?

删除回忆录丶 提交于 2019-12-21 09:17:10
问题 In swift previously, I was able to use a code like this to add new data to my "TestEntity" in my data model. NSManagedObject was created for my "TestEntity" and I was able to set its attributes with the "dot" syntax At the end, I would save the context let entity=NSEntityDescription.insertNewObject(forEntityName: "TestEntity", into: context) as! TestEntity entity.testAttribute="test value" context.save() This code does not work in Swift3. When I run it, i get the following runtime error:

How to make a screenshot of all the content of a Scrollview?

那年仲夏 提交于 2019-12-21 09:11:12
问题 I want to create a screenshot of a UIScrollView which should contain the whole content of the scroll view, even that content, which is currently not visible to the user. For that I tried the following two methods: func snapShot(view:UIView) -> UIImage { UIGraphicsBeginImageContextWithOptions(view.bounds.size, true, 0); view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true); let image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } func

SWIFT 3 - take out html tags from string taken from JSON web url

99封情书 提交于 2019-12-21 09:07:13
问题 I was wondering how can HTML tags be stripped out of JSON from a web url. Do I have to use NSString of something similar. So I am looking to strip out the html tags that are in the summary value. I looked around abit and it says NSString can be used but I was not sure if that was something that could be implemented into Swift 3. Any Help would be appreciated. My code: import UIKit import Alamofire struct postinput { let mainImage : UIImage! let name : String! let author : String! let summary

Swift 3 making sha1, sha256 and md5 functions

我们两清 提交于 2019-12-21 08:23:10
问题 In Swift 2, I used the following code to extend string variables and to be able to make sha1, sha256, and md5. After moving to swift 3, the code is not working any more! I tried to convert it but run into continuous errors. Any idea how can I solve this? extension NSData { func hexString() -> String { var string = String() for i in UnsafeBufferPointer<UInt8>(start: UnsafeMutablePointer<UInt8>(bytes), count: length) { string += Int(i).hexString() } return string } func MD5() -> NSData { let

Perform action in host app from Today extension(Widget) Without opening app ios

ぐ巨炮叔叔 提交于 2019-12-21 06:59:28
问题 I want to manage some action in containing app from today extension(Widget). Full description: in my containing app, some action (like play/pause audio) perform. And want to manage that action also from today extension(widget). An action continues to perform in background state as well. In today extension, the same action will perform. so for that, if in the main containing app already starts an action and send it into background state, a user can pause action from a widget. and the user also