• 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
Swift: what is the difference between properties and functions?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Swift: what is the difference between properties and functions?


  • Subject: Swift: what is the difference between properties and functions?
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Fri, 01 Aug 2014 15:49:09 +0700

To be more exact:
What is the difference between a read-only property and a function with no arguments returning a value?

Like:

class Wether
{
	var temperature: String
	{
		get
		{
			return "37.2"	//	or return result of some computation
		}
	}

	func forecast() -> String
	{
		return "A thick coat of wool"	//	or return result of some deliberation
	}
}

let w = Wether()
println("The temperature is \(w.temperature)°C and the forecast is: \"\(w.forecast())\"")

Is one more efficient than the other? Or stylistically better?


Gerriet.



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Swift: what is the difference between properties and functions?
      • From: William Squires <email@hidden>
    • Re: Swift: what is the difference between properties and functions?
      • From: Jens Alfke <email@hidden>
  • Next by Date: XCode 5 - Logging
  • Next by thread: Re: Swift: what is the difference between properties and functions?
  • Index(es):
    • Date
    • Thread