swift2

cannot subscript a value of type 'inout' [String :Double] (aka inout Dictionary<String, Double>)

点点圈 提交于 2019-12-17 21:36:04
问题 How can if i try to add three menus in the dictionary i wont let me and throws an error when i try to force unwrap the 3rd item in the menu. However if i force unwrap two of them, i can get them sum of two var menu = ["fish": 10.99, "chips": 5.99, "kebab": 6.99] var totalCost = menu["fish"]! + menu["chips"]! + menu["kebab"]! print("The total cost of the three items is \(totalCost)") But when i tried it this way it worked var menu = ["fish": 10.99, "chips": 5.99, "kebab": 6.99] var totalCost =

Swift 2 array of tuples not working as in swift 1

社会主义新天地 提交于 2019-12-17 21:23:21
问题 Array: var rows: [(title: String, body: String, icon: String, iconColor: UIColor)] = [] rows.append(title: "Foo", body:"Bar", icon: "Bas", iconColor: UIColor(netHex: 0x4285f4)) the append line is giving me following error since I upgraded to swift 2: Cannot invoke append with argument list of type (title: String, body: String, icon: String, iconColor: UIColor) in swift 1 it was working fine. Any idea whats wrong? 回答1: You're appending the parameters list, not the tuple itself: you're missing

Swift 2.0 NSURLConnection sendSynchronousRequest

妖精的绣舞 提交于 2019-12-17 20:33:21
问题 I am using the code below to check for an internet connection. It was working correctly but after the Swift 2.0 update I now see an error on the line var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: nil) as NSData? saying extra argument 'error' in call. class func isConnectedToNetwork()->Bool{ var Status:Bool = false let url = NSURL(string: "http://google.com/") let request = NSMutableURLRequest(URL: url!) request.HTTPMethod = "HEAD" request

Swift 2.0 - `nil` or `0` enum arguments

不问归期 提交于 2019-12-17 20:08:09
问题 I've run into this a on a couple functions in Swift 2.0 and wondering if there is a work around. There seems to be no way to not specify enum arguments in Swift 2.0 now. For example, these two methods seem to require something other than nil or 0 be passed in. Is there a way around this? // Cannot invoke '...' with argument list of type ... options: Int NSCalendar.currentCalendar().dateByAddingComponents(components, fromDate: self.date, options: 0) NSJSONSerialization.JSONObjectWithData(data,

Protocol Extension Initializer

喜欢而已 提交于 2019-12-17 19:35:01
问题 I would like to know what the protocol equivalent is for an initializer in a simple class that only contains initializing functionality and is only intended to be extended in a concrete class. So probably the easiest is to show the code - I'm looking for the protocol extension equivalent of the following: import UIKit class Thing { var color:UIColor init(color:UIColor) { self.color = color } } class NamedThing:Thing { var name:String init(name:String,color:UIColor) { self.name = name super

UITableView Pagination - Bottom Refresh to Load New Data in Swift

不羁的心 提交于 2019-12-17 19:34:00
问题 I am trying to implement loading data from my backend with pagination. I have seen this, but it loads all the data, all then time. Is this the right way or am I doing something wrong? Thanks in advance. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell print(indexPath.row) if (indexPath.row + 1 < self.TotalRowsWithPages) { cell

How to fix my orientation issue with merging videos from front and back camera

白昼怎懂夜的黑 提交于 2019-12-17 19:10:54
问题 I am merging multiply videos (implantation of pause button) and everything working fine exept when merging video from back camera with video from front camera then one of the videos comes turned upside down in the new video(merged video). My code: let mixComposition = AVMutableComposition() let videoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID()) let trackAudio = mixComposition.addMutableTrackWithMediaType(AVMediaTypeAudio,

AdMob 7.3.1 and Swift 2.0 - Module not found

China☆狼群 提交于 2019-12-17 18:56:53
问题 I have a problem using the Google AdMob Framework with Swift 2.0. I'm using AdMob for the first time so I do not know if the problem is with AdMob or Swift 2.0. I have included the AdMob Framework and import it like that in my ViewController: import GoogleMobileAds The error I am getting is: No such Module GoogleMobileAds A bridging header is also not working: #import <GoogleMobileAds/GoogleMobileAds.h> The Error: GoogleMobileAds/GoogleMobileAds.h file not found How should I include AdMob? I

SWIFT 2: Loop through JSON array

元气小坏坏 提交于 2019-12-17 18:28:40
问题 I am getting this json from a url, the return JSON is: [{"id":1,"name":"Mary"},{"id":2,"name":"John"}] I want to display the names in a TableView on IOS. My Swift2 Code is: class ViewController: UIViewController, UITableViewDelegate { var NumberOfPersons = 0 var NameOfPerson = [String]() override func viewDidLoad() { super.viewDidLoad() parseJSON() } func parseJSON(){ do { let data = NSData(contentsOfURL: NSURL(string: "http://zzzzzz.com/API/name.php")!) let jsonResult = try

SafariViewController: How to grab OAuth token from URL?

大城市里の小女人 提交于 2019-12-17 17:57:06
问题 Trying to use Facebook OAuth with the SafariViewController. First I open the authURL with SafariViewController, which if the user is logged in to Facebook on Safari, will redirect them and return an OAuth URL with the token for that specific service, e.g. Instagram RESPONSE: https://www.facebook.com/connect/login_success.html#access_token=BLAHTOKENRESPONSE&expires_in=5114338 When SafariViewController has redirected I want to grab the response URL and store it so I can grab the token. Here is