-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageViewController.swift
74 lines (63 loc) · 2.55 KB
/
ImageViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ImageViewController.swift
// InsTag
//
// Created by student8 on 23/12/14.
// Copyright (c) 2014 student8. All rights reserved.
//
import UIKit
class ImageViewController : UIViewController{
var url : String!
var userImageUrl: String!
var userName : String!
var captionText : String!
var userID : String!
var json: [String: AnyObject]!
var entries : NSDictionary!
@IBOutlet weak var caption: UITextView!
@IBOutlet weak var userProfileImageView: UIImageView!
@IBOutlet weak var userNameTextLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
if let nsurl = NSURL(string: url) {
if let nsdata = NSData(contentsOfURL: nsurl) {
imageView.image = UIImage(data: nsdata)
}
}
if let nsurl = NSURL(string: userImageUrl) {
if let nsdata = NSData(contentsOfURL: nsurl) {
userProfileImageView.image = UIImage(data: nsdata)
}
}
userNameTextLabel.text = userName
caption.text = captionText
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let userProfileVC = segue.destinationViewController as UserProfileViewController
userProfileVC.userName = userName
userProfileVC.userPhotoUrl = userImageUrl
let url = "https://api.instagram.com/v1/users/"+userID+"/?access_token=583685231.1fb234f.ddba925fe0dd43089d69d6c414657ddb"
let nsurljson = NSURL(string: url)
let nsdata = NSData(contentsOfURL: nsurljson!)
entries = NSJSONSerialization.JSONObjectWithData(nsdata!, options: NSJSONReadingOptions.AllowFragments, error: nil) as NSDictionary
if let jsn : AnyObject = entries["data"]{
json = jsn as [String: AnyObject]
}
if let countsT : AnyObject = json["counts"]{
let counts = countsT as [String:AnyObject]
if let followerstemp : AnyObject = counts["followed_by"]{
let followers = followerstemp as String
userProfileVC.followers = followers
}
if let followingstemp : AnyObject = counts["follows"]{
let followings = followingstemp as String
userProfileVC.following = followings
}
if let mediaTemp : AnyObject = counts["media"]{
let media = mediaTemp as String
userProfileVC.posts = media
}
}
}
}