• 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
Possible to defer initialization of let variable?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible to defer initialization of let variable?


  • Subject: Possible to defer initialization of let variable?
  • From: Rick Mann <email@hidden>
  • Date: Tue, 07 Jul 2015 01:08:38 -0700

I thought I saw some Swift code that did this:

	let someString : String?

	if some things
	{
		// some stuff

		someString = <a string from something>

		// some other stuff
	}

	//  use someString

But I can't get Swift 2 to let me.

Basically, I want to make someString available outside the scope in which it's initialized, but I don't want its assignment to ever change after that. I could do the former with var instead of let, of course, but I'd like it to be treated as a let after the first assignment. Is that possible?

--
Rick Mann
email@hidden



_______________________________________________

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


  • Follow-Ups:
    • Re: Possible to defer initialization of let variable?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: cannot invoke 'substringToIndex' with an argument list of type '(Int)'
  • Next by Date: Re: Possible to defer initialization of let variable?
  • Previous by thread: Re: cannot invoke 'substringToIndex' with an argument list of type '(Int)'
  • Next by thread: Re: Possible to defer initialization of let variable?
  • Index(es):
    • Date
    • Thread