Re: [swift-users] How to resolve "type(of: instance)" being shadowed by "instance.type"?
Ah, how come I never thought about trying that!? Thanks! Regards, Glen > On 23 Sep 2017, at 1:10 PM, Slava Pestov wrote: > > >> On Sep 22, 2017, at 10:10 PM, Glen Huang via swift-users >> wrote: >> >> I have a class like this: >> >> class File { >> type: FileType >> url: URL >> func fetch(from server: Server) { >> type(of: server).get(from: url) >> } >> } >> >> However, it fails to compile with "Cannot call value of non-function type >> ‘File’” inside the body of fetch(from:). I believe the reason is that >> self.type shadows type(of: server). >> >> Other than renaming the “type” property, is there any other way to work >> around it? I tried "Foundation.type(of: server)” and found out that it’s >> from the standard library and not Foundation. Is there a prefix that denotes >> the standard library? > > The standard library module is named ‘Swift’, so ‘Swift.type(of:)’ should do > the trick. > >> >> A more general question, since this is clearly a function call, why would it >> be shadowed by self.type, which is clearly a property access? >> >> I’m using Swift 4 in Xcode 9. >> >> Regards, >> Glen >> ___ >> swift-users mailing list >> swift-users@swift.org >> https://lists.swift.org/mailman/listinfo/swift-users > ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] How to resolve "type(of: instance)" being shadowed by "instance.type"?
> On Sep 22, 2017, at 10:10 PM, Glen Huang via swift-users > wrote: > > I have a class like this: > > class File { > type: FileType > url: URL > func fetch(from server: Server) { > type(of: server).get(from: url) > } > } > > However, it fails to compile with "Cannot call value of non-function type > ‘File’” inside the body of fetch(from:). I believe the reason is that > self.type shadows type(of: server). > > Other than renaming the “type” property, is there any other way to work > around it? I tried "Foundation.type(of: server)” and found out that it’s from > the standard library and not Foundation. Is there a prefix that denotes the > standard library? The standard library module is named ‘Swift’, so ‘Swift.type(of:)’ should do the trick. > > A more general question, since this is clearly a function call, why would it > be shadowed by self.type, which is clearly a property access? > > I’m using Swift 4 in Xcode 9. > > Regards, > Glen > ___ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
[swift-users] How to resolve "type(of: instance)" being shadowed by "instance.type"?
I have a class like this: class File { type: FileType url: URL func fetch(from server: Server) { type(of: server).get(from: url) } } However, it fails to compile with "Cannot call value of non-function type ‘File’” inside the body of fetch(from:). I believe the reason is that self.type shadows type(of: server). Other than renaming the “type” property, is there any other way to work around it? I tried "Foundation.type(of: server)” and found out that it’s from the standard library and not Foundation. Is there a prefix that denotes the standard library? A more general question, since this is clearly a function call, why would it be shadowed by self.type, which is clearly a property access? I’m using Swift 4 in Xcode 9. Regards, Glen ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users