swift3

How to use sin(_ : ) with a FloatingPoint value in Swift 3 [duplicate]

旧巷老猫 提交于 2019-12-22 10:23:01
问题 This question already has answers here : Making Swift generics play with overloaded functions (2 answers) Closed last year . import Foundation public func sine <T: FloatingPoint > (_ x: T ) -> T{ return sin(x) } // Error: Cannot invoke 'sin' with an argument list of type '(T)' Is there a way around this? Many thanks. 回答1: You can make a sin method that accepts FloatingPoint type also as follow: import UIKit func sin<T: FloatingPoint>(_ x: T) -> T { switch x { case let x as Double: return sin

URLSessionTask runs always into an error

怎甘沉沦 提交于 2019-12-22 10:11:47
问题 In my ExtensionDelegate I'm starting a URLSessionTask with following code: func scheduleNextURLSessionTask() { let backgroundConfigObject = URLSessionConfiguration.background(withIdentifier: "myIdentifier") let backgroundSession = URLSession(configuration: backgroundConfigObject, delegate: self, delegateQueue: nil) let retrieveTask = backgroundSession.dataTask(with: URL(string: "https://api.wedtec.net/cryptocoins/index.php?bitcoin&simple")!) retrieveTask.resume() } My ExtensionDelegate

Cannot invoke initializer for type 'UnsafeMutablePointer'

无人久伴 提交于 2019-12-22 10:09:08
问题 I'm trying to update Reachability.swift to swift 3.0 and I'm having trouble passing the Reachability instance to the call back function. Here is my snippet: * please note self = Reachability class var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil) context.info = UnsafeMutablePointer(Unmanaged.passUnretained(self).toOpaque()) Where the compiler throws an error saying: Cannot invoke initializer for type 'UnsafeMutablePointer<_>'

How to add a attachment in outlook programatically swift 3

Deadly 提交于 2019-12-22 09:24:21
问题 I have opened the outlook app and send a file in it. I am able to open the outlook and set the To,Subject and Body but not sure how to attach file in the document directory The file is at path var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let documentsDirectory = paths[0] let fileName = "supportdata.log" let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName) let scheme : String = "ms-outlook://compose?tosupport@tech.com

How to add a attachment in outlook programatically swift 3

半世苍凉 提交于 2019-12-22 09:23:08
问题 I have opened the outlook app and send a file in it. I am able to open the outlook and set the To,Subject and Body but not sure how to attach file in the document directory The file is at path var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let documentsDirectory = paths[0] let fileName = "supportdata.log" let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName) let scheme : String = "ms-outlook://compose?tosupport@tech.com

Set Timer on Swift

怎甘沉沦 提交于 2019-12-22 08:57:13
问题 Im trying to execute the function pepe() repeated times, i get no errors but it doesnt work. Here is my code: public class MyClass { var timer = Timer() @objc func pepe() -> String { let hola = "hola" return hola } func startTimer(){ let seconds = 1.0 timer = Timer.scheduledTimer(timeInterval: seconds, target: ().self, selector: #selector(pepe), userInfo: nil, repeats: false) } func stopTimer() { timer.invalidate() } init() { self.startTimer() self.stopTimer() } } var pepe = MyClass() pepe

Error: Ambiguous reference to member 'subscript' in Swift 3

允我心安 提交于 2019-12-22 08:57:06
问题 I downloaded the Xcode 8 beta and converted my syntax to Swift 3. When I did, I got the eponymous error with this code (this didn't happen before): Swift 3: do { let fileAttributes = try FileManager.default().attributesOfItem(atPath: fileURL.path!) // Error here let fileSizeNumber = fileAttributes[NSFileSize] as! NSNumber fileSize = fileSizeNumber.longLongValue } catch _ as NSError { print("Filesize reading failed") } Swift 2: do { let fileAttributes = try NSFileManager.defaultManager()

how can I change style of pre-selected words in my textView?

核能气质少年 提交于 2019-12-22 08:35:28
问题 This is a follow up to this question How can I change style of some words in my UITextView one by one in Swift? Thanks to @Josh's help I was able to write a piece of code that highlights each word that begins with # - and do it one by one. My final code for that was: func highlight (to index: Int) { let regex = try? NSRegularExpression(pattern: "#(\\w+)", options: []) let matches = regex!.matches(in: hashtagExplanationTextView.text, options: [], range: NSMakeRange(0,

How to document parameters of a closure that's a parameter

馋奶兔 提交于 2019-12-22 08:29:07
问题 My attempt at documenting a closure parameter to a function: /** sends the request out. - Parameter pzurl: request description including url, method, formdata. - Parameter responseProcessor: closure that's on success invokes - Parameter json: a json array or dictionary - Parameter timestamp: and the same `timestamp` that this function returns - parameter failure: closure is invoked when json could not be parsed or remote indicated failure - Returns: timestamp to identify responses */ internal

xcode 8 beta ios 10 push notifications stopped working

我们两清 提交于 2019-12-22 08:17:34
问题 After switching to xcode 8 beta my push notifications have stopped working. My code signing identity for release is set to distribution. I am registering the device, receiving the token and successfully uploading it to my server without any problem. But the status of the push messages is failed. Just wondering if i need to make any changes or if it will not work with a beta version of xcode. 回答1: In the targets, under Capabilities and Push Notifications I needed to add the push notification