swift3

XMLParser.sharedParser.decode() in swift3

眉间皱痕 提交于 2019-12-25 08:31:09
问题 I used this code XMLParser.sharedParser.decode() in swift2. But I migrate swift3 this code didn't work. My code is here, func xmppStream(_ sender: XMPPStream!, didReceive message: XMPPMessage!) { let result1 = XMLParser.sharedParser.decode(String(message)) for (key, value) in result1 { let title = result1["title"] } if message.isChatMessage(){ sms = String(message.body()) if( sms == "" || message.body() == nil){ }else{ self.prefs.set(sms, forKey: "SMS") } } } 回答1: If you are using codes from

get thumbnail images in list and full size image when click on the item of list

纵饮孤独 提交于 2019-12-25 08:27:50
问题 So I am using below code to fetch all the images from library which is working fine : func grabPhotos(){ let imgManager = PHImageManager.default() let requestOptions = PHImageRequestOptions() requestOptions.isSynchronous = true requestOptions.deliveryMode = .highQualityFormat let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)] if let fetchResults : PHFetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions){

Value of “String” has no member 'indices' - moving to Swift 3.0

℡╲_俬逩灬. 提交于 2019-12-25 08:27:14
问题 I'm moving from Swift 2 (probably, 2.3) to 3.0 and have a hard time correcting following code : Now, I know that String is not a collection anymore. How do I correct this particular code? let separator = anyWord.indexOf("-")! anyWord.substring(with: (anyWord.indices.suffix(from: anyWord.index(anyWord.startIndex, offsetBy: separator + 1)))) 回答1: As a possible improvement to @dfri's first solution, you could use the upperBound of String 's range(of:) method (which is bridged from NSString ) –

Changing a table view cell in a standard view controller'

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 08:24:10
问题 I have a TableView and in it I have a cell that I need to change the background color of. I've tried searching for an answer to change the background color of the cell but the problem is that every answer I find has to do with an override tableview function, which will not work because I do not have a tableviewcontroller, rather it is a normal view controller with a UITableView embedded. How can I simply change the background color of the cell? 回答1: First give your table view cell an

Can't show the core data in tableview Swift

守給你的承諾、 提交于 2019-12-25 08:23:36
问题 class showPageViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! var records : [Record] = [] func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return records.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell() return cell } func tableView(

Retrieving an array from Parse.com

三世轮回 提交于 2019-12-25 08:19:18
问题 I am trying to download an array from Back4Apps.com (Parse.com equivalent). The below displays no errors, but when it gets to the line "downloadQuery.findObjectsInBackground { (objects, error) in", it simply skips over the rest of the code to the end of the function. I have tested the "username" and it seems to be correct. I am certain the class and subClass names are correct. The parse parameters are correct and I already have many other parse functions working. Any suggestions where to look

Pull to refresh and Alamofire using Swift 3

青春壹個敷衍的年華 提交于 2019-12-25 08:15:41
问题 I am using Alamofire to get data from a web URL(JSON). I am trying to implement pull to RefreshControl into my project. I have done it but don't know if it is correct or if the data is getting updated when refreshed. My code is: var refresh = UIRefreshControl() refresh.addTarget(self, action: #selector(self.refreshData), for: UIControlEvents.valueChanged) func refreshData() { Alamofire.request("https://www.example.com/api").responseJSON(completionHandler: { response in self.parseData(JSONData

Converting to Swift 3 (Swift and Firebase Project)

好久不见. 提交于 2019-12-25 08:07:53
问题 I have just updated my Xcode to Xcode8 and I have converted the project to swift 3. In signIn function here: Firth. Auth()?.signIn(withEmail: self.EmailTF.text!, password: self.PasswordTF.text!, completion: { (user: FIRUser?, error: NSError?) in if let error = error { print(error.localizedDescription) } else { self.ref.child("UserProfile").child(user!.uid).setValue([ "email": self.EmailTF.text!, "name" : self.NameTF.text!, "phone": self.PhoneTF.text!, "city" : self.CityTF.text!, ]) print(

Can't set URLRequest Authorization Header

若如初见. 提交于 2019-12-25 08:07:22
问题 Since swift 3 update I change my requests from NSMutableURLRequest to URLRequest. After that all my requests stopped worked due invalid credentials problem. Already tried and search everything. My service continue same as before and tested my requests from a request simulator and went fine. let url : NSString = "http://url.service.com/method?param=\(name)" as NSString var request = URLRequest(url: URL(string: url.addingPercentEscapes(using: String.Encoding.utf8.rawValue)!)!) request

NSDate which is returned is incorrect

白昼怎懂夜的黑 提交于 2019-12-25 08:03:20
问题 I am build a function to get the date for the Chinese new year from the date which is passed from a datePicker. the convertDateFormater converts a string formatted date to a date object. the date which i get back is Returned date = "03-Feb-2030" for the year "1970-05-22" but if i run the current date with "NSDate() as Date" i get the right output. for the year 2016. func convertDateFormater(date: String) -> Date { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd"/