• 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: Class in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Class in Swift


  • Subject: Re: Class in Swift
  • From: Charles Srstka <email@hidden>
  • Date: Sat, 16 Aug 2014 15:53:09 -0500

On Aug 16, 2014, at 6:32 AM, Gerriet M. Denkmann <email@hidden> wrote:

> How to translate into Swift:
>
> - (void)myFunctionWithClass: (Class)someClass
> {
> 	for(...)
> 	{
> 		p = ...
> 		if ( p is not special ) continue;
>
> 		id <MyProtocol> aClass = [[ someClass alloc] initWithParameter: p ];
> 		... do something with aClass ...
> 	}
> }
>
> Assuming that someClass is costly to initialize and myFunctionWithClass does so only under certain circumstances.
> Or that myFunctionWithClass creates many instances of someClass.
>
> Assuming also, that there is an unlimited number of classes (all implementing MyProtocol).
>
> Which means that there is no way that the caller of myFunctionWithClass could create a someClass and pass it to the method.
>
> How to do this in Swift?
>
> Gerriet.

You can't. Swift does not have as many dynamic features as Objective-C.

Charles


_______________________________________________

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: Class in Swift
      • From: Quincey Morris <email@hidden>
References: 
 >Class in Swift (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Creating pdf document
  • Next by Date: Re: Class in Swift
  • Previous by thread: Class in Swift
  • Next by thread: Re: Class in Swift
  • Index(es):
    • Date
    • Thread