swift3

String convert to Int and replace comma to Plus sign

喜夏-厌秋 提交于 2020-01-09 07:12:10
问题 Using Swift, I'm trying to take a list of numbers input in a text view in an app and create a sum of this list by extracting each number for a grade calculator. Also the amount of values put in by the user changes each time. An example is shown below: String of: 98,99,97,96... Trying to get: 98+99+97+96... Please Help! Thanks 回答1: Use components(separatedBy:) to break up the comma-separated string. Use trimmingCharacters(in:) to remove spaces before and after each element Use Int() to convert

xcode 8 beta 3: Expected ',' joining parts of a multi-clause condition

南楼画角 提交于 2020-01-08 21:51:24
问题 Getting a new warning in xcode 8 beta 3. What is wrong with this syntax, or is there a bug in xcode? SwiftyJSON.swift:772:35: Expected ',' joining parts of a multi-clause condition if let errorValue = error where errorValue.code == ErrorNotExist { } 回答1: It seems this feature has been included: 0099-conditionclauses.md Try this: if let errorValue = error, errorValue.code == ErrorNotExist { } 来源: https://stackoverflow.com/questions/38446598/xcode-8-beta-3-expected-joining-parts-of-a-multi

xcode 8 beta 3: Expected ',' joining parts of a multi-clause condition

爷,独闯天下 提交于 2020-01-08 21:49:07
问题 Getting a new warning in xcode 8 beta 3. What is wrong with this syntax, or is there a bug in xcode? SwiftyJSON.swift:772:35: Expected ',' joining parts of a multi-clause condition if let errorValue = error where errorValue.code == ErrorNotExist { } 回答1: It seems this feature has been included: 0099-conditionclauses.md Try this: if let errorValue = error, errorValue.code == ErrorNotExist { } 来源: https://stackoverflow.com/questions/38446598/xcode-8-beta-3-expected-joining-parts-of-a-multi

how to delete an element that contains a letter in array using swift

放肆的年华 提交于 2020-01-07 09:25:10
问题 I am having trouble trying to figure this topic out. Like the topic, How do I delete an element that contains a letter in Array. This is the code I have so far. let newline = "\n" let task = Process() task.launchPath = "/bin/sh" task.arguments = ["-c", "traceroute -nm 18 -q 1 8.8.8.8"] let pipe = Pipe() task.standardOutput = pipe task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String var

“Cannot assign to value: 'i' is a 'let' constant” error

♀尐吖头ヾ 提交于 2020-01-07 08:28:49
问题 I am updating my project to Swift 3. Most all has gone well, but I cannot figure the below out. I believe I have found how to correct the first of the two errors, but cannot figure out the second one "i = i + 1" as I am getting the error "Cannot assign to value: 'i' is a 'let' constant" I hired someone to do the coordinates on my app, so this is why I am not so accustomed to these types of errors. I have created 200 polygon regions and the below this is meant to take the users current

AVAssetExportSession.requestExportSession callback never called (swift 3, iOS10)

风流意气都作罢 提交于 2020-01-07 06:50:37
问题 The following code never calls the callback for export. The export session is created just fine. I see no error, and no progress. The CPU is 0%. I see no exceptions. Status is 1 (in progress), the progress is 0, the error is nil. The video plays in the gallery. I can successfully get an image for the video. I have extracted the code into a single UIViewController for testing, see below: I tested using iOS10.1.1 with a video I recorded on the iPad. import UIKit import Photos class

“NSURL” is not implicitly convertible to “URL”; did you mean to use “as” to explicitly convert? in swift 3

房东的猫 提交于 2020-01-07 06:42:33
问题 func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) } 回答1: In swift 3.0 , the method signature for openURL is: func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { return FBSDKApplicationDelegate

How to pass JSON data to another view controller from login function using post method?

余生颓废 提交于 2020-01-07 05:42:14
问题 I m having blank data in another view controller, I can pass data between table view controller but I m having a problem to parse data from login method and pass access token or username from JSON? @IBOutlet weak var username_textfield: UITextField! @IBOutlet weak var password_textfield: UITextField! var logindata : [Login] = [] var myResponse : JSON = nil func getlogin(){ let headers = [ "Content-Type": "application/x-www-form-urlencoded" ] let parameters = [ "UserName": username_textfield

How to pass JSON data to another view controller from login function using post method?

跟風遠走 提交于 2020-01-07 05:41:46
问题 I m having blank data in another view controller, I can pass data between table view controller but I m having a problem to parse data from login method and pass access token or username from JSON? @IBOutlet weak var username_textfield: UITextField! @IBOutlet weak var password_textfield: UITextField! var logindata : [Login] = [] var myResponse : JSON = nil func getlogin(){ let headers = [ "Content-Type": "application/x-www-form-urlencoded" ] let parameters = [ "UserName": username_textfield

How to embed and stream a video from the web within an Xcode macOS Cocoa Application?

爱⌒轻易说出口 提交于 2020-01-07 04:42:27
问题 I am trying to get my macOS Cocoa Application Xcode project to play some video when I feed it a specified URL. To simplify the question lets just use an empty Xcode project. I want to achieve the same level of control as I am able to get using AVPlayerViewController() in my iOS Single View Application . Within that app I am currently using the solution offered here. However, only the second example works in my macOS Cocoa Application when adapted like so : import Cocoa import AVFoundation