taskIdentifer throws error (NSUrlSessionDataTask)

var placesTask = NSURLSessionDataTask()
var session : NSURLSession{
        return NSURLSession.sharedSession()
    }
func fetchPlacesNearCoordinate(coordinate: CLLocationCoordinate2D, radius: Double, types:[String], completion: (([GooglePlace]) -> Void)) -> () 
{ 
var urlString = "https:/ let typesString = types.count > 0 ? types.joinWithSeparator("|") : "food" urlString += "&types=\(typesString)" 
urlString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! 
if placesTask.taskIdentifier > 0 && placesTask.state == .Running { placesTask.cancel() 
} 
UIApplication.sharedApplication().networkActivityIndicatorVisible = true 

placesTask = session.dataTaskWithURL(NSURL(string: urlString)!) {data, response, error in UIApplication.sharedApplication().networkActivityIndicatorVisible = false 
var placesArray = [GooglePlace]() if let json = (try? NSJSONSerialization.JSONObjectWithData(data!, options:[])) as? NSDictionary { 
if let results = json["results"] as? NSArray 
{ 
for rawPlace:AnyObject in results 
{ 
let place = GooglePlace(dictionary: rawPlace as! NSDictionary, acceptedTypes: types) placesArray.append(place) 
if let reference = place.photoReference 
{ self.fetchPhotoFromReference(reference) 
{ image in place.photo = image } 
}}}
} dispatch_async(dispatch_get_main_queue()) 
{ completion(placesArray) 
} 
} placesTask.resume() 
}


The error I m getting after compiling :

-[NSURLSessionDataTask taskIdentifier]: unrecognized selector sent to instance 0x7f8eba441e60

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLSessionDataTask taskIdentifier]: unrecognized selector sent to instance 0x7f8eba441e60'


This code seems to work on xcode 6.4 but doesn't work on the xcode 7 beta 6 which is currently using.


Can someone help me for solution?


Thank you

var placesTask = NSURLSessionDataTask()

You can’t construct an NSURLSessionDataTask like that. Rather, tasks must be created by a session. You do this correctly elsewhere in the code, so I’m not entirely sure why you’re doing it wrongly here.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi.Thanks for the reply.


Actually, I have already added NSURLSession from start, it is just that I didnt add in the code here. 🙂

Were you able to resolve the issue?

taskIdentifer throws error (NSUrlSessionDataTask)
 
 
Q