-2
import UIKit
import Alamofire

 protocol VideoModelDelegate{
 func dataReady()
 }

 class VideoModel: NSObject {

let API_KEY = ""
let UPLOADS_PLAYLIST_ID = ""


var videoArray = [Video]()

var delegate:VideoModelDelegate?

func getFeedVideos() -> [Video] {

       Alamofire.request(.GET, "",parameters: ["part":"snippet",           "playlistId":UPLOADS_PLAYLIST_ID  ,"key":API_KEY], 
encoding: ParameterEncoding.URL, headers: nil).responseJSON {(response) -> Void in

        if let JSON = response.result.value{

            var arrayOfVideos = [Video]()

            for video in JSON["items"] as! NSArray {
                print(video)
                let videoObj = Video()
      videoObj.videoId = video.valueForKeyPath("snippet,resourceId,      videoId")
                String
      videoObj.videoTitle = video.valueForKeyPath("snippet.title") as! String
      videoObj.videoDescription = video.valueForKeyPath("snippet.description") as!
                String
                videoObj.videoThumbnailUrl = video.valueForKeyPath("snippet.thumbnails.maxres.url") as! String
                arrayOfVideos.append(videoObj)
        }

            self.videoArray = arrayOfVideos

            if self.delegate != nil {
                self.delegate!.dataReady()

            }

        }
    }
        }
    func getVideos() -> [Video] {
    var videos = [Video]()

    let video1 = Video()

    video1.videoId = ""
    video1.videoTitle = ""

    videos.append(video1)

    return videos

}

}

[Additional Errors][Error]1How to make my viewcontroller conform to protocol "UITableViewDataSource, and Video Mode Delegate"?

I have tried a number of suggested changes in the previous threads, but nothing got me through, Please help me out.

Thanks in advance

import UIKit
import Alamofire

class tab: UIViewController, UITableViewDataSource, UITableViewDelegate, VideoModelDelegate ERROR- Type 'tab' does not conform to protocol 'UITableViewDataSource'

{

@IBOutlet weak var table: UITableView!

@IBOutlet weak var name: UILabel!

    var videos : [Video] = [Video]()
var selectedVideo:Video?
let model:VideoModel = VideoModel()
var arrRes = [[String:AnyObject]]() //Array of dictionary


override func viewDidLoad() {
    super.viewDidLoad()


    self.model.delegate = self
    //self.videos = model.getVideos()

    model.getFeedVideos()


    self.table.dataSource = self
    self.table.delegate = self


    /*Alamofire.request(.GET, "http://online.m-tutor.com/mtutor/gateway/mtutorAPI_1.php?type=university").response { (req, res, data, error) -> Void in
        print(res)
        let outputString = NSString(data: data!, encoding:NSUTF8StringEncoding)
        print(outputString)
    }


    Alamofire.request(.GET, "http://online.m-tutor.com/mtutor/gateway/mtutorAPI_1.php?type=university").responseJSON { response in
        if let swiftyJsonVar = response.data
        {

        print("swiftyJsonvar:\(swiftyJsonVar)")
        }
    }*/



    Alamofire.request(.GET, "http://online.m-tutor.com/mtutor/gateway/mtutorAPI_1.php?type=university").responseJSON { (responseData) -> Void in
        let swiftyJsonVar = JSON(responseData.result.value!)

        if let resData = swiftyJsonVar["contacts"].arrayObject {
            self.arrRes = resData as! [[String:AnyObject]]
        }
        if self.arrRes.count > 0 {
            self.table.reloadData()
        }
    }
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.

    func dataReady(){
        self.videos = self.model.videoArray

        self.table.reloadData()
    }


    func tableView(table: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) ->
        CGFloat {
            return(self.view.frame.size.width / 320) * 180
    }

    func tableview(table:UITableView, numberOfRowsInSection section: Int ) ->Int{
        return videos.count
    }

    func tableVie(table: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->
        UITableViewCell{
            let cell = table.dequeueReusableCellWithIdentifier("jsonCell")!

        let videoTitle = videos[indexPath.row].videoTitle



            let label = cell.viewWithTag(2) as! UILabel
            label.text = videoTitle



            //cell.textLabel?.text = videoTitle

let videoThumbnailUrlString = videos[indexPath.row].videoThumbnailUrlString;)ERROR:Expected Expression

let videoThumbnailUrl != nil ERROR-'!= is not a prefix unary operator' and 'Type annotation missing in pattern'

{

                let request = NSURLRequest(URL: videoThumbnailUrl!)

                let session = NSURLSession.sharedSession()

                let dataTask = session.dataTaskWithRequest(request, completionHandler: {(data:NSData?, response:NSURLResponse?, error:NSError) -> Void in



                    dispatch_async(dispatch_get_main_queue(), { () -> Void in

                    let imageView = cell.viewWithTag(1) as! UIImageView

                    imageView.image = UIImage(data: data!)


                })


                })
                dataTask.resume()
            }



            return cell



            func tableView(table: UITableView, didSelectRowAtIndexPath indexpath: NSIndexPath){

                self.selectedVideo = self.videos[indexpath.row]
                self.performSegueWithIdentifier("toVDVC", sender: self)

    }

            func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
                let detailViewController = segue.destinationViewController as! VDViewController
                detailViewController.selectedVideo = self.selectedVideo
            }
}

} }

re

Martin
  • 846
  • 1
  • 9
  • 23
Manee ios
  • 1,112
  • 11
  • 14

1 Answers1

1

It looks as though you haven't closed the method didReceivedMemoryWarning: and the tableview delegate methods are then effectively inside this method causing your issue. Add a closing bracket and it should be fine:

Update: Here is the updated code. There was some more formatting issues with brackets and an error with your if statement in the cellForRowAtIndex:

import UIKit
import Alamofire


class tab: UIViewController, UITableViewDataSource, UITableViewDelegate, VideoModelDelegate { 

    @IBOutlet weak var table: UITableView!
    @IBOutlet weak var name: UILabel!

    var videos : [Video] = [Video]()
    var selectedVideo:Video?
    let model:VideoModel = VideoModel()
    var arrRes = [[String:AnyObject]]() //Array of dictionary

    override func viewDidLoad() {
        super.viewDidLoad()


        self.model.delegate = self
        //self.videos = model.getVideos()

        model.getFeedVideos()


        self.table.dataSource = self
        self.table.delegate = self


        /*Alamofire.request(.GET, "http://online.m-tutor.com/mtutor/gateway/mtutorAPI_1.php?type=university").response { (req, res, data, error) -> Void in
            print(res)
            let outputString = NSString(data: data!, encoding:NSUTF8StringEncoding)
            print(outputString)
        }


        Alamofire.request(.GET, "http://online.m-tutor.com/mtutor/gateway/mtutorAPI_1.php?type=university").responseJSON { response in
            if let swiftyJsonVar = response.data
            {

            print("swiftyJsonvar:\(swiftyJsonVar)")
            }
        }*/



        Alamofire.request(.GET, "http://online.m-tutor.com/mtutor/gateway/mtutorAPI_1.php?type=university").responseJSON { (responseData) -> Void in
            let swiftyJsonVar = JSON(responseData.result.value!)

            if let resData = swiftyJsonVar["contacts"].arrayObject {
                self.arrRes = resData as! [[String:AnyObject]]
            }
            if self.arrRes.count > 0 {
                self.table.reloadData()
            }
        }
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    } //ADDED CLOSING BRACKET HERE

    func dataReady(){
        self.videos = self.model.videoArray

        self.table.reloadData()
    }

    func tableView(table: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) ->
        CGFloat {
            return(self.view.frame.size.width / 320) * 180
    }

    func tableview(table:UITableView, numberOfRowsInSection section: Int ) ->Int{
        return videos.count
    }

    func tableVie(table: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->
        UITableViewCell{
        let cell = table.dequeueReusableCellWithIdentifier("jsonCell")!
        let videoTitle = videos[indexPath.row].videoTitle

        let label = cell.viewWithTag(2) as! UILabel
        label.text = videoTitle

        //cell.textLabel?.text = videoTitle

        //CHANGE THESE TWO LINES:
        //let videoThumbnailUrlString = videos[indexPath.row].videoThumbnailUrlString;)
        //if let videoThumbnailUrl != nil {
        //TO THIS:
        if let videoThumbnailUrl = videos[indexPath.row].videoThumbnailUrlString {
            let request = NSURLRequest(URL: videoThumbnailUrl!)

            let session = NSURLSession.sharedSession()

            let dataTask = session.dataTaskWithRequest(request, completionHandler: {(data:NSData?, response:NSURLResponse?, error:NSError) -> Void in



                dispatch_async(dispatch_get_main_queue(), { () -> Void in

                let imageView = cell.viewWithTag(1) as! UIImageView

                imageView.image = UIImage(data: data!)


            })


            })
            dataTask.resume()
        }
        return cell
    }

    func tableView(table: UITableView, didSelectRowAtIndexPath indexpath: NSIndexPath){
        self.selectedVideo = self.videos[indexpath.row]
        self.performSegueWithIdentifier("toVDVC", sender: self)
    }

    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
        let detailViewController = segue.destinationViewController as! VDViewController
        detailViewController.selectedVideo = self.selectedVideo
    }
}
Joe Benton
  • 3,703
  • 1
  • 21
  • 17
  • Sir, I made the changes, but still the error exists. The Xcode is suggesting me these changes for this line "let videoThumbnailUrl != nil "(Suggestions:1- Unary operator cannot be separated from its operand, 2- Consecutive statements on line should be separated by ';') and other error do remain as if the same. Kindly help me... – Manee ios Mar 24 '16 at 10:21
  • Just spotted some more syntax issues, check comments in update. – Joe Benton Mar 24 '16 at 10:26
  • Sir the error count has reduced, as of now I am getting these two errors if let videoThumbnailUrl = videos[indexPath.row].videoThumbnailUrlString {(ERROR- Value of type 'video' has no member ' videoThumbnailUrlString' ) and the other ERROR is "Type 'tab' does not conform to protocol 'UITableViewDataSource'" – Manee ios Mar 24 '16 at 10:32
  • What are the two errors. (sorry I dont have xCode at the minute to test, just doing this from reading your code snippets) – Joe Benton Mar 24 '16 at 10:40
  • 1) Value of type 'video' has no member ' UITableViewDataSource' 2) Type 'tab' does not conform to protocol 'UITableViewDataSource – Manee ios Mar 24 '16 at 10:42
  • That first issue is whatever you have called it in your video model? Maybe check incase videoThumbnailUrlString should be something else? – Joe Benton Mar 24 '16 at 10:47
  • Dear Joe I have attached the videomodel code above, please have a look – Manee ios Mar 24 '16 at 10:54