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

macphreak2011

macrumors newbie
Original poster
Oct 7, 2011
25
4
I am having a strange problem and I was wondering if you could help me out with it. I have this code:

Code:
import Cocoa


@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var lblLeadsCount: NSTextField!
    @IBOutlet weak var lblLastChecked: NSTextField!


    func applicationDidFinishLaunching(aNotification: NSNotification?) {
        // Insert code here to initialize your application
    }

    func applicationWillTerminate(aNotification: NSNotification?) {
        // Insert code here to tear down your application
    }

    @IBAction func checkLeads(sender: AnyObject) {
        var url = NSURL(string: "http://*********************")
        let theRequest = NSURLRequest(URL: url!)
        
        NSURLConnection.sendAsynchronousRequest(theRequest, queue: nil, completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
            if data.length > 0 && error == nil {
                let response : AnyObject! = NSJSONSerialization.JSONObjectWithData(data,
                    options: NSJSONReadingOptions.MutableContainers, error: nil)
                
                lblLeadsCount.text = response
            }
        })
    }

}

However, when it gets to the line that says:
Code:
lblLeadsCount.text = response

I am getting this error:
"'NSTextField' does not have a member named 'text'"

Any ideas why I can't set a simple Label? Thanks!
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
Maybe NSTextField doesn't have a member named 'text'.

Maybe you're thinking of UITextField, which DOES have a member named text.

In general, when you think the compiler is mistaken in cases like this, the first step is to check the reference documentation for the class in question. Also be sure to check superclasses.


Here's an example with Swift code and an NSTextField:
https://forums.macrumors.com/threads/1741694/
 

macphreak2011

macrumors newbie
Original poster
Oct 7, 2011
25
4
For someone else looking for this answer, I found mine:

NSTextField is correct. However, the post chown33 linked to, helped me find the correct answer (thanks chown33!).

You need to have this line of code:
Code:
self.lblLeadsCount.stringValue = "test";

To get past the compiler errors. This worked for me.

Thanks again chown33!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.