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

Re: Swift: what is the difference between properties and functions?


  • Subject: Re: Swift: what is the difference between properties and functions?
  • From: William Squires <email@hidden>
  • Date: Fri, 01 Aug 2014 12:00:05 -0500

I'm not sure there is any. Even in ObjC (or other OO languages, such as VC#.Net, or Xojo) that have both syntactic constructs, the effect on the callee is negligible (if there is any syntactic difference.) Usually, I'll opt for a property, but that's just me. Remember, in ObjC, an @synthesize'd property (getter) is a function anyway, so:

i = foo.bar;

and:

i = [foo bar];

would do the same thing; if one is syntactically valid, the other will be too (at least in ObjC 2.0), assuming you've @synthesize'd the getter, or supplied it yourself. There may be an advantage, however, to writing it as a property, vis-a-vis KVC/KVO, however. Not sure on this point, just saying.

Also, as this is mostly a code issue, I'd probably post it to email@hidden instead of xcode users. :) At least until a dedicated email@hidden comes along... Which I suspect we'll see when Yosemite comes out, along with the official OS X 10.10/iOS 8 SDKs and Xcode 6 release.

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

> 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


 _______________________________________________
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: Roland King <email@hidden>
    • Re: Swift: what is the difference between properties and functions?
      • From: Quincey Morris <email@hidden>
References: 
 >Swift: what is the difference between properties and functions? (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Xcode burp on project load
  • Next by Date: Re: Swift: what is the difference between properties and functions?
  • Previous by thread: Re: Swift: what is the difference between properties and functions?
  • Next by thread: Re: Swift: what is the difference between properties and functions?
  • Index(es):
    • Date
    • Thread