Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jonpeter

macrumors member
Original poster
Sep 19, 2013
42
0
MI
So I have a struct set up for numerous instances i plan on putting in my array.
anyways, in my struct
I have
"var title: String
Var type: String
var pic: UIImageView"

and in my instance i Keep getting an error revolving around the image portion of the struct.

This is my code in the view controller btw. let restaurant3 = restaurantmodel(restitle: "space dungeon", restype: "cotton candy", resimage: "space.png")

Am i setting up my "pic" variable wrong?

thanks for any help.... beginning to learn swift...
 
Uh, i think there's a code tag.
Try formatting it with that?

Code:
struct restaurant_model { // Struct
      var title: String
      var type: String
      var picName: String
}

let restaurant3 = restaurant_model(title: "space dungeon", type: "cotton candy", picName: "space.img") // Restaurant 3

I fixed up some mistakes. You changed title to restitle, for example.
Also, you can define the picName as a string, and then use it like:

Code:
let image = UIImage(named: restaurant3.picName);
let imageView = UIImageView(image: image!)

I don't know much about Swift but that's what I found from my digging.
 
Last edited:
So I have a struct set up for numerous instances i plan on putting in my array.
anyways, in my struct
I have
"var title: String
Var type: String
var pic: UIImageView"

and in my instance i Keep getting an error revolving around the image portion of the struct.

This is my code in the view controller btw. let restaurant3 = restaurantmodel(restitle: "space dungeon", restype: "cotton candy", resimage: "space.png")

Am i setting up my "pic" variable wrong?

thanks for any help.... beginning to learn swift...

You have title, type and pic. In the next line you're trying to use restitle, restype and resimage. That is your first issue.

The second issue is that pic is of type UIImageView. You're trying to use a string "space.png" instead of UIImageView. I am pretty sure you intended UIImage, or pic should have been a string. You need to make that decision.

Having said that, stick to learning Swift as a pure programming language, before attempting to use Apple's classes designed to create applications. What you're trying to do is like trying to learn Russian with a Russian copy of The Brothers Karamazov
 
PHP:
I was able to figure that in my class, I had to create
"var resimage: UIImage?"
PHP:
and in my code, I had to use
"resimage: UIImage(named: "space.png")"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.