swift2

Swift how to iterate float

主宰稳场 提交于 2019-12-25 08:15:05
问题 I tried to find this in Swift 2 docs, but can't find any info how to iterate floats. New swift iteration style make me crazy =) with dots and etc. for (i = 0; i < 100; i+=0.5) how to write it in Swift? This does not work as it's Double: for _ in 5.0.stride(100.0, by: 0.5) { } 回答1: This is the (exact) equivalent of your C-loop using stride Swift 2 for index in 0.0.stride(to: 99.5, by: 0.5) { print(index) } Swift 3 for index in stride(from:0.0, through: 99.5, by: 0.5) { print(index) } 来源: https

Firebase ,Swift: `runTransactionBlock()` returns null

孤街浪徒 提交于 2019-12-25 08:12:52
问题 Every time i run runTransactionBlock it Gives me null , Although there is a node at that location:- FIRMutableData (top-most transaction) (null) at the line :- print(totalPost) func updateTotalNoOfPost(){ let prntRef = FIRDatabase.database().reference().child("TotalPosts") prntRef.observeSingleEventOfType(.Value, withBlock: {(totalSnap) in if totalSnap.exists(){ prntRef.child("noOfTotalPost").runTransactionBlock({ (totalPost: FIRMutableData) -> FIRTransactionResult in print(FIRAuth.auth()!

Unable to interpret '|' character

大憨熊 提交于 2019-12-25 07:18:05
问题 I need your help because I dont understand what's going on with my auto constraints. The constraints of my switch make the app crash. When I remove them it work nicely. This is the error message that I get: Unable to interpret '|' character, because the related view doesn't have a superview H:|-100-[v0(35)]| thx for your help Here is my code : class selectionCustomCell: UITableViewCell{ var label: UILabel = { let attribution = UILabel() attribution.text = "Nom du label" attribution.textColor

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]

时光毁灭记忆、已成空白 提交于 2019-12-25 06:49:52
问题 I am trying to run app on the iphone 6 and I get this error. I get the error after making the facebook login. Normally, it is working successfully on the simulator. I couldn't find why it gives the error. Error: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray' *** First throw call stack: (0x181dcae38 0x18142ff80 0x181d41a6c 0x100418620 0x100417aa0 0x10042dbac 0x10006a3a0 0x10006aa0c

Getting object for tapped UITableViewCell in new UIView?

删除回忆录丶 提交于 2019-12-25 06:32:40
问题 What is the right way to segue from a cell in a UITableViewCell to a new view, passing parameter data? I have specified a segue from my prototype cell in my UITableViewCell, that links it to a new UIVIew and has it set to show (aka push) . The new UIView displays, but I am not sure how to make tell the UIView the section/row that was selected or tell it about the object associated with that selection. An abridged version of my code is shown below: class MyTableViewController :

Compilation errors in xCode 7 + Swift 2.0

随声附和 提交于 2019-12-25 06:19:07
问题 Since I have installed the xCode 7 beta2 + Swift 2.0, I'm getting some errors in my app. For example, I'm getting the following error "Cannot invoke 'requestAccessToEntityType' with an argument list of type '(EKEntityType, completion: (Bool, NSError!) -> _)' in this part of code: eventStore.requestAccessToEntityType(EKEntityType.Event, completion: {(granted: Bool, error:NSError!) in if !granted { print("Access to store not granted") } }) Also this error: Cannot invoke

How to check UITextField is not blank in Swift 2.0? Is there better way to count the string? [duplicate]

青春壹個敷衍的年華 提交于 2019-12-25 06:04:07
问题 This question already has answers here : Check empty string in Swift? (12 answers) Closed 4 years ago . I am try to check textfield is blank or not and what I am trying is if(EmailTextField.text.characters.count>0) { } but I can't use relation operator on this count method. Why? 回答1: By extension... To ensure that its not even take any blank spaces... extension String { var isBlank: Bool { get { let trimmed = stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) return

How to tap cell's buttons in UITableViewCell without actionning the cell's segue

隐身守侯 提交于 2019-12-25 03:53:45
问题 My custom cell have 2 buttons, and each custom cell also perform a segue. The segue is functionning properly, the problem come from the fact that my buttons are never fired. If I click on them then the segue is fired, but not the button. How to overcome this? Here goes the code of how the button's actions are defined : In the table view controller override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView

UITextFied in UIScrollView not enabled after scrolling

强颜欢笑 提交于 2019-12-25 03:50:14
问题 I Added a UIScrollView in a ViewController, And Added UIView under that UIScrollView I added total number 10 UITextFields in that UIView , Scrolling is Working fine While running App in Simulator/ iPhone, the First 6 UITextFields Working [Responding to touches] which are shown on the screen without scrolling, Remaining 4 UITextFields are not working [Not responding to the touches], which will shown after scrolling Please can any one guide me to resolve this issue? thank you UPDATE: I Used it

Alamofire, Swift 2.0, SwiftyJSON: Parse response body as JSON

早过忘川 提交于 2019-12-25 03:35:36
问题 I have successfully completed a POST request to server and I am trying to parse the response JSON but I have been unsuccessful. Alamofire.request(.POST, ServerConfig.ADD_SELLER_URL, parameters: sellerJSON, encoding: .JSON, headers: nil) .responseJSON(completionHandler: { responseRequest, responseResponse, responseResult in print(responseRequest!.URL) print(responseResponse) print(responseResult) let json = JSON(responseResponse!) print(json) }) I am using SwiftyJSON for JSON parsing. Here is