swift3

Generic Swift Dictionary Extension for nil filtering

荒凉一梦 提交于 2019-12-30 07:14:14
问题 I'm looking for a type safe, generic version of this answer. This is the method signature I'm looking for: extension Dictionary where Value == Optional<T> { func filterNil() -> <Key, T> } Is there any way to express this in Swift 3? Edit: My motivation for creating a Dictionary with optional values is that I need something like this: struct User { var mail: String? var name: String? func marshaled() -> [String: Any] { return [ "mail": mail, "name": name ].filterNil() } } I much prefer the

Only Alphabet and whitespace allowed in UITextField Swift

拥有回忆 提交于 2019-12-30 06:39:13
问题 I want to validate my textField that check only Alphabet & whitespace allowed, If number was given then it will return warning error. //First I declare my value to variable var nameValue: String = mainView.nameTextField.text! //Then I declare this let set = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ") //And this is the validation if(nameValue.rangeOfCharacter(from: set.inverted) != nil ){ self.showAlert(message: "Must not contain Number in Name") } else

URLSessionUploadTask getting automatically cancelled instantly

这一生的挚爱 提交于 2019-12-30 06:29:49
问题 I'm having this weird issue in which a newly created URLSessionUploadTask gets cancelled instantly. I'm not sure if it's a bug with the current beta of Xcode 8. I suspect it might be a bug because the code I'm about to post ran fine exactly once. No changes were made to it afterwards and then it simply stopped working. Yes, it literally ran once, and then it stopped working. I will post the error near the end. I will post the code below, but first I will summarize how the logic here works. My

Xcode 8 and Swift 3 NSCalendar

徘徊边缘 提交于 2019-12-30 05:46:10
问题 I implemented my watch project in Swift and now I am migrating to Swift 3 because of Xcode 8. I let Xcode 8 change the source code to Swift 3. However, there are errors in the code and I can not figure it out. let unitFlags: Calendar = [.hour, .firstWeekday, .monthSymbols, .year, .minute, .firstWeekday] var calendar = NSCalendar.current calendar.timeZone = NSTimeZone(identifier: "UTC")! let components = (calendar as NSCalendar).components(unitFlags, from: reservationDate) Xcode gives error in

How to draw a text using CoreGrahpics & Core animation

只愿长相守 提交于 2019-12-30 05:27:25
问题 I want to achieve this type of animation.please check this URL https://www.dropbox.com/s/gz9vfy5refsh7a5/Screen.mov?dl=0 I am adding Code which I have used in the project where I have used Core Graphics to render the text with animation but I am not able to animate text which is being shown in the mentioned link This is code which i am using to render the text on the screen let context = UIGraphicsGetCurrentContext()! context.saveGState() context.setAlpha(noLightText) let nOLIGHTRect = CGRect

Swift 3, URLSession dataTask completionHandler not called

烈酒焚心 提交于 2019-12-30 03:30:27
问题 I am writing a library, So not using UIKit, Even in my iOS app same code works, but when i execute in command line in doesn't . In PlayGround also it seems working. For some reason callback is not getting triggered, so print statements are not executing. internal class func post(request: URLRequest, responseCallback: @escaping (Bool, AnyObject?) -> ()) { execTask(request: request, taskCallback: { (status, resp) -> Void in responseCallback(status, resp) }) } internal class func

Ambiguous use of 'sd_setImage(with:placeholderImage:completed:)' with Swift 3

只谈情不闲聊 提交于 2019-12-30 01:45:14
问题 I am making the following call using SDWebImage on my imageView , which works fine with Swift 2 but gives an error with XCode 8 beta 5 compiling with Swift 3 : imageView.sd_setImage(with:url, placeholderImage:placeholder, completed: { (image: UIImage?, error: Error?, cacheType: SDImageCacheType, imageURL: URL?) in ... }); The error is: Ambiguous use of 'sd_setImage(with:placeholderImage:completed:)' I suspect I have something wrong in the signature for the completed handler, but I can't

Sending an email from swift 3

拜拜、爱过 提交于 2019-12-29 19:06:04
问题 I am trying to set up an app with send email option. I have this code: import Foundation import MessageUI import UIKit class emailClass: UIViewController, MFMailComposeViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() if !MFMailComposeViewController.canSendMail() { print("Mail services are not available") return } sendEmail() } func sendEmail() { let composeVC = MFMailComposeViewController() composeVC.mailComposeDelegate = self // Configure the fields of the interface

Sending an email from swift 3

折月煮酒 提交于 2019-12-29 19:04:07
问题 I am trying to set up an app with send email option. I have this code: import Foundation import MessageUI import UIKit class emailClass: UIViewController, MFMailComposeViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() if !MFMailComposeViewController.canSendMail() { print("Mail services are not available") return } sendEmail() } func sendEmail() { let composeVC = MFMailComposeViewController() composeVC.mailComposeDelegate = self // Configure the fields of the interface

Convert matrix_float4x4 to x y z space

半腔热情 提交于 2019-12-29 18:50:10
问题 I'm using ARKit and trying to get the position of the camera as a rotation and (x,y,z) coordinates in real world space. All I can manage to get is a matrix_float4x4 , which I don't really understand, and euler angles only show the rotation. Here's what I currently have: let transform = sceneView.session.currentFrame?.camera.transform let eulerAngles = sceneView.session.currentFrame?.camera.eulerAngles Here's the output I'm getting: eulerAngles: float3(-0.694798, -0.0866041, -1.68845)