1

As the title suggest I'm occurred in a little problem with a fun in a singleton. this is my code:

    import UIKit

class InterfaceManager: NSObject
{
    class var sharedInstance: InterfaceManager
    {
        get
        {
            struct Static
            {
            static var instance: InterfaceManager? = nil
            static var token: dispatch_once_t = 0
            }
            dispatch_once(&Static.token) { Static.instance = InterfaceManager()
            }
            return Static.instance!
        }
    }

    func chooseAttributedString(string: NSString, font: UIFont, color: UIColor)
    {
        let string: NSString = string
        var stringMutable = NSMutableAttributedString()
        stringMutable = NSMutableAttributedString(string: string as String , attributes: [NSFontAttributeName: font, NSForegroundColorAttributeName: color])
    }
}

but when I'm going to call the method in a class Xcode gives me an error "Extraneous argument label 'string' in call". following my lines code:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CellSquadreController
        let squadra = DataManager.sharedInstance.arrayCori[indexPath.row]

        cell.backgroundColor = UIColor.clearColor()
        cell.nomeSquadra.attributedText = InterfaceManager.sharedInstance.chooseAttributedString(string: squadra.nome, font: UIFont(name: "Noteworthy-Light", size: 23)!, color: UIColor.whiteColor())
        return cell
    }

PS: I've just revised a little mistake, but but still it does not work...

Fabio Cenni
  • 841
  • 3
  • 16
  • 30
  • You forgot to access the `sharedInstance`. `InterfaceManager.sharedInstance.chooseA..` – Jack Aug 21 '15 at 21:24
  • Also, your singleton implementation is needlessly complicated, see http://stackoverflow.com/questions/24024549/dispatch-once-singleton-model-in-swift/24024762#24024762 – Jack Aug 21 '15 at 21:25
  • @JackWu Thanks a lot, I'm going to read that post! – Fabio Cenni Aug 21 '15 at 21:52

1 Answers1

0

You forgot to access the sharedInstance:

InterfaceManager.sharedInstance.chooseAttributedString(squadra.nome, font: UIFont(name: "Noteworthy-Light", size: 23)!, color: UIColor.whiteColor())

Jack
  • 16,677
  • 8
  • 47
  • 51
  • I tried to implement other fun in the singleton and all works except my chooseAttributedString() fun, in the tableViewController class appear the error "Extraneous argument label 'string' in call"... I don't know how it is possible! – Fabio Cenni Aug 21 '15 at 22:12
  • That makes sense, the first variable name doesn't need the external param. I've edited my answer. You should remove the `string:` label. – Jack Aug 22 '15 at 00:56
  • Ok, that was the mistake! You solved my problem, thanks a lot! – Fabio Cenni Aug 22 '15 at 10:34