vendredi 31 juillet 2015

How to enter parameters for latitude longitude

I am using the Yelp API and this is the search method:

func searchWithTerm(term: String, success: (AFHTTPRequestOperation!, AnyObject!) -> Void, failure: (AFHTTPRequestOperation!, NSError!) -> Void) -> AFHTTPRequestOperation! {
        // For additional parameters, see http://ift.tt/QXVBgL
        var parameters = ["term": term, "ll": "37.77493,-122.419415"]
        return self.GET("search", parameters: parameters, success: success, failure: failure)
    }

This is currently hardcoded with the given ll parameter. I have a the user's location stored in a different VC and when i try to pass in the lat and long to replace the hardcoded values, I get errors...

What am i doing wrong? It should be rather simple to pass in a value of double...

Send local notification when download completes through NSURLSession / NSURLSessionDownloadTask

I am using NSURLSessionDownloadTask objects on an NSURLSession to allow users to download documents while the app is in the background / device locked. I also want to inform the user that individual downloads have finished through a local notification.

To that end, I am triggering a local notification in the -URLSession:downloadTask:didFinishDownloadingToURL: download task delegate method, however I am wondering if there might be a better place to add the code triggering a notification, since the way Apple explains it, the download task will be passed to the system, and from that I am deriving that those delegates will not be called anymore on the download task's delegate once (or shortly after) the app is backgrounded.

My question: What is the best place to add the code for triggering the local notifications? Has anybody had any previous experience in adding this sort of a functionality to their application?

Load an image from an asset catalog off the main thread?

I'm trying to load an image from an asset catalog into a UIImage off of the main thread, but can't seem to find any way to do it. If the image was not in an asset catalog I would use pathForResource and imageWithContentsOfFile:

NSString *path = [[NSBundle mainBundle] pathForResource:icon ofType:nil];
if(path) {
  image = [UIImage imageWithContentsOfFile:path];
}

But pathForResource: does not work for images in asset catalogs. Is there any way to do this without having to go to the main thread to load the image? Im guessing the answer is no.

What won't work:

  • Manually creating the path for the image based on the main bundle path. I have images in multiple asset catalogs, and asset catalogs can be compiled in a binary form.
  • [UIImage imageNamed:] is not thread safe, and can not be used off the main thread. The docs have said it's not thread safe for at least the last several major releases of iOS, and starting in iOS 8 it really does crash when used off the main thread.

What i'm doing now:

dispatch_sync(dispatch_get_main_queue(), ^{
  image = [UIImage imageNamed:icon];
});

Implement *find* friends in parse.com

There are multiple examples on the net to implement friend/follower relationships between users. But I am unable to find a clever solution to search for the friends. Every example assumes that I selected the user objects already but it has no example how to find them prior to that.

Given an application that allows ad-hoc registration, combined with facebook/twitter login what would be the search criteria? Username does not work because finding a user registered with facebook is not possible as facebook logins won't have a usable and easy to remember username. Natural name will lead to too many "John Smiths" so I do not like the idea again. Email address sounds reasonable (as it can be extracted from facebook profile and we can ask email verification for ad-hoc registrations) but with that I have a bit of security concerns: is there a risk that someone reads the whole database storing the email addresses? Also how do I store those addresses? Do I store them in a separate class with a pointer to the user object? But then how do I prevent the "hackers" from reading the whole list?

Will apple reject apps built with xcode 5.1

I just want to know that will apple reject app build with xcode5.1 since i ready that you need xcode6 after 1st june , but the apple documentation says you need apps built with 64bit arch and ios8 , and xcode 5.1 has both so it will be accepted ? i just want to know if i am correct .

Swift: My custom UITableViewDataSource class thinks it doesn't conform to protocol 'UITableViewDataSource'

I have checked a few other questions out there, of which the answers seem to be in the datasource methods' declarations. However, I cannot find what's wrong with my methods declarations.

Here is my class:

import UIKit

class GuestControl: UITableViewDataSource, UITableViewDelegate {
    @IBOutlet weak var leftTable: UITableView!
    @IBOutlet weak var rightTable: UITableView!
    var userList = [User]() //even numbers including 0 go on the left table, odd numbers go on the

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    //Here is where we link to that user's contact page
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell: GuestTableViewCell = tableView.dequeueReusableCellWithIdentifier("guestCell") as! GuestTableViewCell

    if tableView == leftTable {
        cell.configureCellWithUser(userList[indexPath.row+indexPath.row])
    } else {
        cell.configureCellWithUser(userList[indexPath.row+indexPath.row+1])
    }

    return cell
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    let num = Double(userList.count) / 2.0
    if tableView == leftTable {
        return Int(round(num)) //round up
    } else {
        return Int(num) //round down
    }
}

}

And here is the exact error:

Protocol requires function 'tableView(_:numberOfRowsInSection:)' with type '(UITableView, numberOfRowsInSection: Int) -> Int'
Candidate is not '@objc', but protocol requires it
Protocol requires function 'tableView(_:cellForRowAtIndexPath:)' with type '(UITableView, cellForRowAtIndexPath: NSIndexPath) -> UITableViewCell'
Candidate is not '@objc', but protocol requires it

What is wrong?

How to detect if the image of UIImageView has changed

I have an app where the user can choose an image from the camera roll and than that image is loaded into an UIImageView. However, if the image is big there is a delay till the selected image actually appears in the UIImageView (Setting the image is not performed on the main thread so the UI does not get frozen). Until the image is set, I would like to show an activity indicator which notifies the user that the app did not freeze, its just loading the image. However I don't know how to detect when the image got set in the UIImageView to hide the activity indicator. I am guessing maybe KVO could help here, but I am not sure how to implement it properly.

Sorry for the noob question! :)