swift3

accessing nested firebase data in swift

情到浓时终转凉″ 提交于 2019-12-24 06:24:09
问题 I am working wth a data structure, and I am looping through a couple nodes and here is the json data I get. Snap (20171012) { "-KwM45HyW4UduQgKTGn6" = { ImageName = "Screen Shot 2017-10-13 at 11.24.51 AM.png"; fileURL = ""; thumbFileUrl = ""; user = "User not defined"; }; "-KwM4limD2aRyHgeKE5P" = { ImageName = "test.png"; fileURL = ""; thumbFileUrl = ""; user = "User not defined"; }; } After this, I can access the "snap" value using my data.key to get the "20171012" ref.child(myselected_spot!

Swift parse string with different formats

99封情书 提交于 2019-12-24 06:08:12
问题 I am working on a String parser in which the input can have various formats, and I don't know in advance which format is being used, so I need to write something that is flexible. The first step is to check the first few characters, I can check that by using eg: func parse(input: String) -> String { let result: String if (input.hasPrefix("foo") { result = doFoo(input) } else if (input.hasPrefix("bar") { result = doBar(input) } else if (input.hasPrefix("baz") { result = doBaz(input) } else {

Swift error Cannot convert value of type '(AFHTTPRequestOperation?, AnyObject?) -> ()

廉价感情. 提交于 2019-12-24 05:52:33
问题 After I update xcode Version 8.0 (8A218a) swift 3, I got this error Cannot convert value of type '(AFHTTPRequestOperation?, AnyObject?) -> ()' to expected argument type '((AFHTTPRequestOperation?, Any?) -> Void)!' This is the following code that's shown error above. jsonmanager.post( "http://myapi.com", parameters: nil, success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in if(responseObject.object(forKey: "meta")?.object(forKey: "status")?.intValue == 200){.... Am i

Swift error Cannot convert value of type '(AFHTTPRequestOperation?, AnyObject?) -> ()

我的梦境 提交于 2019-12-24 05:52:21
问题 After I update xcode Version 8.0 (8A218a) swift 3, I got this error Cannot convert value of type '(AFHTTPRequestOperation?, AnyObject?) -> ()' to expected argument type '((AFHTTPRequestOperation?, Any?) -> Void)!' This is the following code that's shown error above. jsonmanager.post( "http://myapi.com", parameters: nil, success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in if(responseObject.object(forKey: "meta")?.object(forKey: "status")?.intValue == 200){.... Am i

How to give unit tests access to Core Data models

China☆狼群 提交于 2019-12-24 05:49:12
问题 Let's say I've made Core Data models in my project. I have other classes with methods that take in these models and perform some function based on their properties. How do I unit test those classes? With normal Swift files I select them in Xcode and tick a box which makes any classes defined in those files visible to the unit test part of the project. My question is essentially, how do I make my Core Data models also visible to the tests? Note that I don't want to perform any operations on

Can someone tell me why I keep getting error “unexpected non-void return value in void function”

喜欢而已 提交于 2019-12-24 05:47:17
问题 I get an error when trying to return a true or false Bool value... Can someone help ? I was trying to check if user exists in Firebase database. func checkIfUserExists(email: String) -> Bool{ FIRDatabase.database().reference().child("users").observe(.childAdded, with: { (snapshot) in if let dictionary = snapshot.value as? [String: AnyObject]{ switch email { case dictionary["email"] as! String!: return true break default: return false break } } }, withCancel: nil) } 回答1: change it this way

Value of type 'CustomButton' has no member 'touchDown'

拥有回忆 提交于 2019-12-24 05:45:11
问题 I have created custom button class and override all touches methods. It works fine in swift 2 and Xcode 7.3.1 . But when I open same app in Xcode 8.0 , it will show errors : Value of type 'CustomButton' has no member 'touchDown' Value of type 'CustomButton' has no member 'touchUpInside' Value of type 'CustomButton' has no member 'touchDragExit' Value of type 'CustomButton' has no member 'touchDragEnter' Value of type 'CustomButton' has no member 'touchCancel' Here is my code : import UIKit

Permission is not working prior iOS 10 in Swift

半腔热情 提交于 2019-12-24 04:55:07
问题 I have defined the permission of Camera and Photo library in Info.plist and is working fine in iOS 10 but it is not working prior iOS 10. Camera Permission: Privacy - Camera Usage Description : $(PRODUCT_NAME) camera use Photo Library Permission: Privacy - Photo Library Usage Description : $(PRODUCT_NAME) photo use Please,suggest me something. 回答1: set '$(PRODUCT_NAME)' to "Bundle Display Name" in plist is the thing that worked for me 来源: https://stackoverflow.com/questions/41759601

How to stretch image into custom shape (swift3)

拈花ヽ惹草 提交于 2019-12-24 04:36:06
问题 The code list below crops the image. I would like the image to be transformed/ stretched and not cropped in the shape. All of the image contents are still in the transformed picture. It will just look different. extension UIImageView { func addMask(_ bezierPath: UIBezierPath) { let pathMask = CAShapeLayer() pathMask.path = bezierPath.cgPath layer.mask = pathMask } } let myPicture = UIImage(data: try! Data(contentsOf: URL(string:"https://scontent-iad3-1.xx.fbcdn.net/v/t31.0-8/14196150

View tableview cell text on table view cell button

血红的双手。 提交于 2019-12-24 04:31:49
问题 I have a table view where I have created a label and two buttons. I am stuck while getting the text from the label on button click. I have created an array list like: let arrayList: [String] = [ "aaa" , "bbb" , "ccc"] I want if I click the button on index[0] I shall get "aaa" and if index[2] I shall get "ccc" @IBOutlet weak var titleLable: UILabel! @IBOutlet weak var infoButton: UIButton! myCell.titleLable.text = self.arrayList[indexPath.row] myCell.infoButton.tag = indexPath.row myCell