• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stuck in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stuck in Swift


  • Subject: Re: Stuck in Swift
  • From: Marco S Hyman <email@hidden>
  • Date: Thu, 14 Aug 2014 17:05:53 -0700

On Aug 14, 2014, at 1:51 AM, Gerriet M. Denkmann <email@hidden> wrote:

> Well, it should, but it does not. I still get the error: 'String' is not a subtype of 'AppDelegate'

Note the location of the error.  The compiler is complaining that
myStatusHandler is the wrong type in this line:

> 	let someThing = SomeClass(statusHandler: myStatusHandler)

And it is the wrong type.  myStatusHandler is a method of class
AppDelegate and only has meaning with respect to an instance of that
class.  You may know that AppDelegate is intended to be a singleton,
but the compiler does.  Assuming you really want to do this I think
you need to code it something like...

// because a class var isn't supported, yet.
var statusString : String?

class AppDelegate: NSObject
{

	let someThing = SomeClass(statusHandler: AppDelegate.myStatusHandler)

    class func myStatusHandler(s: String)
	{
		statusString = s
	}
}

class SomeClass
{
	var statusHandler:  (String) -> Void

	init( statusHandler: String -> Void)
	{
		self.statusHandler = statusHandler
	}
}


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Re: Stuck in Swift (From: Muhammad Hussein Nasrollahpour <email@hidden>)
 >Re: Stuck in Swift (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Translating to Swift
  • Next by Date: Re: Translating to Swift
  • Previous by thread: Re: Stuck in Swift
  • Next by thread: Abandoning NSDocument for an app
  • Index(es):
    • Date
    • Thread