bero
bero

Reputation: 201

iOS Argument labels '(named:)' do not match any available overloads

i get the error in this line after i modified it

 let CS = User(name: "Sporting Club", images: RoundImage(named: "1.png")! , coordinate:(41.844326 , 12.467619), type: "Sport", address: "Via dei Cocchieri, 1A")

by changing

images: UIImage(named: "1.png")!    

with

images: RoundImage(named: "1.png")! 

a custom class to have circular images; before the change the code work perfectly but now i get this error, someone can explain me how to solve it?

the class of RoundImage is this

import UIKit

@IBDesignable
class RoundImage: UIImageView {



    @IBInspectable var cornerRadius: CGFloat = 0 {
        didSet {
            self.layer.cornerRadius = cornerRadius
        }
    }
    @IBInspectable var borderWidth: CGFloat = 0 {
        didSet {
            self.layer.borderWidth = borderWidth
        }
    }

    @IBInspectable var borderColor: UIColor = UIColor.clear {
        didSet {
            self.layer.borderColor = borderColor.cgColor
        }
    }

}

Upvotes: 0

Views: 664

Answers (1)

rob mayoff
rob mayoff

Reputation: 386078

Your RoundImage is a subclass of UIImageView. UIImageView has no init(named:) initializer.

Perhaps you meant to subclass UIImage, not UIImageView. However, UIImage has no layer property, so your inspectable properties won't compile.

Your User class shouldn't know anything about the view hierarchy. Its initializer should not take a view parameter. A User object shouldn't care that its image is displayed in a round view.

I suggest three changes:

  1. Your User initializer should take a plain UIImage.

  2. You should rename your RoundImage class to RoundImageView.

  3. You should use a RoundImageView in your view hierarchy.

Upvotes: 1

Related Questions