Search code examples
swiftsingletonuifontnsmutableattributedstring

A func in a Singleton does not works


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...


Solution

  • You forgot to access the sharedInstance:

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