[swift-corelibs-dev] non-inherited init

Philippe Hausler phausler at apple.com
Thu Mar 17 09:54:42 CDT 2016


Actually partially related. The /*@NSCopying*/  comments are hints that we left when initially importing that the return value should be copied. It is again a export from it’s objc nature. In this case having a property with copy.

e.g.

@property (copy) NSData *data;

exports as

@NSCopying public var data: NSData!

This is mainly there to preserve the copy nature when subclasses are implemented.

> On Mar 17, 2016, at 7:48 AM, Pushkar N Kulkarni <pushkar.nk at in.ibm.com> wrote:
> 
> Sorry for intruding!
> 
> I have the same question about /*@NSCopying*/  
> 
> Pushkar N Kulkarni,
> IBM Runtimes
> 
> Simplicity is prerequisite for reliability - Edsger W. Dijkstra
> 
> 
> 
> -----swift-corelibs-dev-bounces at swift.org <mailto:-----swift-corelibs-dev-bounces at swift.org> wrote: -----
> To: Daniel Eggert <danieleggert at me.com <mailto:danieleggert at me.com>>
> From: Philippe Hausler via swift-corelibs-dev 
> Sent by: swift-corelibs-dev-bounces at swift.org <mailto:swift-corelibs-dev-bounces at swift.org>
> Date: 03/17/2016 08:12PM
> Cc: Swift corelibs dev <swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>>
> Subject: Re: [swift-corelibs-dev] non-inherited init
> 
> That is a comment emitted by the importer, unfortunately it is impossible for non objc to mimic that behavior 100% because it is an init method that is constructed from a class method.
> 
> @interface Foo : NSObject
> + (Foo *)fooNamed:(NSString *)name; // this is not an inherited init method in that it will always return an instance of a Foo no matter the subclass it is called from
> @end
> 
> @interface Bar : Foo
> @end
> 
> // in objc it is like this:
> Foo *f = [Bar fooNamed:@“test”];
> 
> // in swift it is like this:
> let f = Bar(named:”test”)
> 
> but obviously by the method fooNamed always returns a Foo instead of an instancetype because it actually looks up Foo objects from a table.
> 
> > On Mar 17, 2016, at 7:35 AM, Daniel Eggert via swift-corelibs-dev <swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>> wrote:
> > 
> > There're some initializers (namely in NSURLSession) that have a comment:
> > 
> > public /*not inherited*/ init(...
> > 
> > What is this “not inherited” comment trying to convey, and how would one go about implementing this in Swift?
> > 
> > /Daniel
> > 
> > _______________________________________________
> > swift-corelibs-dev mailing list
> > swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>
> > https://lists.swift.org/mailman/listinfo/swift-corelibs-dev <https://lists.swift.org/mailman/listinfo/swift-corelibs-dev>
> 
> _______________________________________________
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev <https://lists.swift.org/mailman/listinfo/swift-corelibs-dev>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160317/8c3b9cf5/attachment.html>


More information about the swift-corelibs-dev mailing list