Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

Reply to protocol extensions - default implementations vs. helper methods
It gets a little clearer if you understand that the relationship between methods in the protocol extension and methods in the conforming type is NOT inheritance. It's something new — call it replacement or something. This seems bizarre until you realize that protocol extensions are available for struct types as well as class types, and struct types do not have subclassing/inheritance. If conforming types were able to override protocol extension methods, then the subclassing mechanism would be effectively extended to struct types, which presumably is never going to happen.The difference of behavior between extension methods that appear as protocol requirements and ones that don't is explicitly documented, so you may not like it but it is what it is.However there is one horrible bug in the current implementation (bug #21470728). If you have a subclass of a class that adopts the protocol but the class does not provide its own version of a not-required method defined in the protocol ext
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’15
Inheriting from an objective-c static class in Swift
It might be a trivial issue, but I am not able to solve it. I have the following function in an objective-c superclass:+(instancetype) lineWithNumber: (NSString*)number;and I am trying to inherit in a swift subclass with:class func lineWithNumber(number:NSString)->LineYet if I put the override in front I get error:Method does not override any method from its superclassif on the other hand I omit the override keyword it reports:Method 'lineWithNumber' with Objective-C selector 'lineWithNumber:' conflicts with method 'lineWithNumber' from superclass 'Line' with the same Objective-C selectorI also tried replacing instancetype with Line as in the inheited function with no change.Calls in other classe would regularly access the Swift function if it were not for the error. What might be the problem, and is there a way to check how Xcode translates Objective-c signatures when they are imported in Swift?
7
0
2.7k
Dec ’15
Reply to Inheriting from an objective-c static class in Swift
Not very hard; this is the signature in the heading file of the Objective-c class:+(instancetype) lineWithNumber: (NSString*)number;As for the context, the upper class just inherit from NSObject and adopts a procol.The Swift class just inherits from the upper class. And the signature of the allegedly corresponding function is:override class func lineWithNumber(number:NSString)->LineI do not think it would be so much a problem for the playground, as the issue happens at compile time, not execution time.If only I could get the way in which Xcode exports the Objective-c heders, I would be done, but of course it seems just the reverse holds.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’15
Reply to Bug? "use of unimplemented initializer"
That looks to me like something is wrong with the library or the language.Seems to be related to both, and better send a Bug Report.The language Objective-C does not have much strict rules of initializing, and the library almost of all Apple's frameworks are written in Objective-C.So, - initWithArrangedSubviews: may (very likely) calling [self initWithFrame:] rather than [super initWithFrame:], in such cases this sort of runtime error may happen.As you may already know, inheriting init(frame:) would resolve your case: override init(frame: CGRect) { super.init(frame: frame) }In some cases, it is very hard to subclass such classes in Swift.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’15
Reply to Bug? "use of unimplemented initializer"
am I correct that overriding init(frame:) and calling super like that goes against the Swift docsNot very correct. From the Swift side of view, inherited init(frame:) of UIStackView is treated as another designated initializer. (Remember Swift classes can have multiple designated initializers.)I think I'll just subclassed UIView and put a stack inside it.Your choice is reasonalbe enough, as the behaviour of Swift's importing inconsistent Objective-C classes such as above is not well documented and may change in the future. Though I'm not sure which way I would do...
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’15
Generics and Optionals in Protocols
I have a couple of days off, so I thought I would try my hand at the Protocol Oriented Programming.One of the first projects I built in Swift was a set of protocols and classes representing expressions. I had 3 types of expressions: MathExpression, StringExpression, and BooleanExpression. These were protocols which inherited from a common Expression protocol. I then had classes representing various operations, etc....This worked fine, but there was A LOT of repeated code. Basically every type of expression had nearly identical code except for the types (e.g. String vs Bool). I am trying to take advantage of the swift 2.0 features to improve this (and potentially move everything to value types at the same time). The biggest problem I am running into is that protocols with self/associated types can't be used as types themselves. I am finally starting to understand why this is the way it is, but working around it requires a lot of thought.I would like to have a single Expression protocol which can be us
1
0
342
Dec ’15
Reply to App does not show up in search results.
Oh big deal. We sell our books, audio material, Windows and OSX software (CDs and downloads) directly to our customers and maintain a close relationship with them and have done so since 1991. Our iOS Apps for iPad have to go via the App Store where Apple does nothing and collects 30% for nothing. Also, as the App Store is based in $USD and because of the current exchange rate our iPad Apps seem overpriced in our own country. If we sold directly this would not be the case. We're a small developer but have a niche education market.
Dec ’15
Does apple allow hunting and fishing video content on their app store?
I sent a email asking this question before, but I have not gotten a response. Anyway in the app submission guidlines there is a line that states Apps portraying realistic images of people or animals being killed or maimed, shot, stabbed, tortured or injured will be rejected. I work for a company and most of what we are creating, VOD systems and websites are geared toward outdoorsman, being hunting and fishing content. I have published a channel for our content on Roku's channel store and I am in the middle of developing my first swift app for tvOS with the same content. However, one of my superviser's told me that another company we have a relationship with tried to submit similar content and was rejected. So before I can move forward with my project I have to see if the app will be rejected because of our content. It has been a blast learning Swift 2.0 and finally getting the chance to work with tvOS/iOS. Our plan was to submit a tvOS and iOS app, with different layouts.
4
0
502
Dec ’15
Required inits + convenience inits + inheritance == conundrum
While trying to convert an older Objective-C program to Swift, I've run into a hitch.So, let's say we've got a base class with a required initializer:class Base { required init(foo: Foo) { … } }and then we have a subclass, but the subclass includes a new parameter in the init, specific to the subclass, and satisfies the requirement via a convenience initializer:class Subclass: Base { required init(foo: Foo, bar: Bar) { ... super.init(foo: foo) ... } required convenience init(foo: Foo) { // Do some calculation to determine a default value for ‘bar’ from the input of ‘foo’. // Perhaps this calculation is quite a few lines of code. let bar = ... self.init(foo: foo, bar: bar) } }Now, that subclass gets subclassed once again:class SubSubclass: Subclass { required init(foo: Foo, bar: Bar) { … super.init(foo: Foo, bar: Bar) ... } required convenience init(foo: Foo) { // Uh oh. } }The trouble here is that we’re required to implement init(foo:) per the base class’s interface, but we cannot use Subclass’s perfectly ser
2
0
2k
Dec ’15
Reply to Required inits + convenience inits + inheritance == conundrum
Regarding this specific set of requirements, this is what I came up with in a playground:Ah, of course, that would work. D'oh, I'm not sure why I didn't consider that. Still not as nice as having the objects come in as non-optionals so the subclasses know exactly what they're getting, and still requires every subclass to implement a boilerplate convenience initializer that passes nil to the larger one, but still, it's much better than the workaround I'd been considering. Thanks.However, I don't understand the need for 'required'. What's the virtue of using it at all? I can't see any value in this case.Well, the example I showed above is an extremely simplified case, and is by no means representative of the entire class hierarchy. With that said, there are plenty of things that force you to put 'required' on your initializers in Swift, most of them having to do with anything involving any kind of polymorphism. If you are conforming to a protocol that contains an initializer, that initializer has to be marked a
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’15
Reply to SKStoreProductViewController
Hi PBK,I found a solution to the problem.Generate a class called e.g. StoreProductViewController inherited from SKStoreProductViewController. Added function:override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return [UIInterfaceOrientationMask.LandscapeLeft, UIInterfaceOrientationMask.LandscapeRight] }In my GLKViewController in function showStoreProductchangelet storeViewController:SKStoreProductViewController = SKStoreProductViewController()tolet storeViewController = StoreProductViewController()func showStoreProduct() { let productParameters = [SKStoreProductParameterITunesItemIdentifier : currentAppId] let storeViewController = StoreProductViewController() storeViewController.delegate = self storeViewController.loadProductWithParameters(productParameters, completionBlock: { (success: Bool, error: NSError?) -> Void in if success { self.presentViewController(storeViewController, animated: true, completion: nil) } else { print(ERROR: storeViewController: (error)) } })
Topic: App & System Services SubTopic: StoreKit Tags:
Dec ’15
Reply to getter and setter in Swift (from ObjC)
It seems my words are a little too short.The `imageFile` exists only in the class's implementation file, but `setRepresentedObject` method is another thing.As you added `override` on top of it, the property is declared in an anscestor class, which is written in Objective-C. The declaration looks like this, if rewritten in Swift: private var _representedObject: AnyObject? var representedObject: AnyObject? { get { return _representedObject } set { _representedObject = newValue } }Your overridden declaration re-declare the property as a renewed stored property, which means it has no relationship with the original backend store `_representedObject`.You need to override it as: override var representedObject: AnyObject? { get { return super.representedObject } set(newRepresentedObject) { super.representedObject = newRepresentedObject //... self.imageFile?.requestPreviewImage() } }To make all thing consistent with Objective-C ancestor class, you always need to override properties as computed property and ac
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’15
Reply to getter and setter in Swift (from ObjC)
In fact my code is pure Swift, no ObjC inside (ObjC is the sample code from WWDC than I am trying to port to Swift).If the sample code I'm seeing is near enough to the WWDC code, The `AAPLSlide` inherits `NSCollectionViewItem`, and I believe you have not rewritten NSCollectionViewItem (or its ancestor classes) in Swift. So, your code in Swift needs to interact with classes written in Objective-C.super refers to the var selected in ancestor class that I override ?Yes.The property `selected` is declared in NSCollectionViewItem class header as:@property (getter=isSelected) BOOL selected;Objective-C compiler interprets it as:- in the private ivar section BOOL _selected;- and accessor methods- (BOOL)isSelected; - (void)setSelected:(BOOL)selected;So, if `setSelected` is overridden in the Objective-C code, only setter of the property is overridden.As you know, Swift cannot override only setter, so you need to keep getter as defined in the ancestor class, that is the part: get { return super.selected }and it
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’15
Reply to protocol extensions - default implementations vs. helper methods
It gets a little clearer if you understand that the relationship between methods in the protocol extension and methods in the conforming type is NOT inheritance. It's something new — call it replacement or something. This seems bizarre until you realize that protocol extensions are available for struct types as well as class types, and struct types do not have subclassing/inheritance. If conforming types were able to override protocol extension methods, then the subclassing mechanism would be effectively extended to struct types, which presumably is never going to happen.The difference of behavior between extension methods that appear as protocol requirements and ones that don't is explicitly documented, so you may not like it but it is what it is.However there is one horrible bug in the current implementation (bug #21470728). If you have a subclass of a class that adopts the protocol but the class does not provide its own version of a not-required method defined in the protocol ext
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’15
Inheriting from an objective-c static class in Swift
It might be a trivial issue, but I am not able to solve it. I have the following function in an objective-c superclass:+(instancetype) lineWithNumber: (NSString*)number;and I am trying to inherit in a swift subclass with:class func lineWithNumber(number:NSString)->LineYet if I put the override in front I get error:Method does not override any method from its superclassif on the other hand I omit the override keyword it reports:Method 'lineWithNumber' with Objective-C selector 'lineWithNumber:' conflicts with method 'lineWithNumber' from superclass 'Line' with the same Objective-C selectorI also tried replacing instancetype with Line as in the inheited function with no change.Calls in other classe would regularly access the Swift function if it were not for the error. What might be the problem, and is there a way to check how Xcode translates Objective-c signatures when they are imported in Swift?
Replies
7
Boosts
0
Views
2.7k
Activity
Dec ’15
Reply to Inheriting from an objective-c static class in Swift
Not very hard; this is the signature in the heading file of the Objective-c class:+(instancetype) lineWithNumber: (NSString*)number;As for the context, the upper class just inherit from NSObject and adopts a procol.The Swift class just inherits from the upper class. And the signature of the allegedly corresponding function is:override class func lineWithNumber(number:NSString)->LineI do not think it would be so much a problem for the playground, as the issue happens at compile time, not execution time.If only I could get the way in which Xcode exports the Objective-c heders, I would be done, but of course it seems just the reverse holds.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’15
Reply to Bug? "use of unimplemented initializer"
That looks to me like something is wrong with the library or the language.Seems to be related to both, and better send a Bug Report.The language Objective-C does not have much strict rules of initializing, and the library almost of all Apple's frameworks are written in Objective-C.So, - initWithArrangedSubviews: may (very likely) calling [self initWithFrame:] rather than [super initWithFrame:], in such cases this sort of runtime error may happen.As you may already know, inheriting init(frame:) would resolve your case: override init(frame: CGRect) { super.init(frame: frame) }In some cases, it is very hard to subclass such classes in Swift.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’15
Reply to Bug? "use of unimplemented initializer"
am I correct that overriding init(frame:) and calling super like that goes against the Swift docsNot very correct. From the Swift side of view, inherited init(frame:) of UIStackView is treated as another designated initializer. (Remember Swift classes can have multiple designated initializers.)I think I'll just subclassed UIView and put a stack inside it.Your choice is reasonalbe enough, as the behaviour of Swift's importing inconsistent Objective-C classes such as above is not well documented and may change in the future. Though I'm not sure which way I would do...
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’15
Generics and Optionals in Protocols
I have a couple of days off, so I thought I would try my hand at the Protocol Oriented Programming.One of the first projects I built in Swift was a set of protocols and classes representing expressions. I had 3 types of expressions: MathExpression, StringExpression, and BooleanExpression. These were protocols which inherited from a common Expression protocol. I then had classes representing various operations, etc....This worked fine, but there was A LOT of repeated code. Basically every type of expression had nearly identical code except for the types (e.g. String vs Bool). I am trying to take advantage of the swift 2.0 features to improve this (and potentially move everything to value types at the same time). The biggest problem I am running into is that protocols with self/associated types can't be used as types themselves. I am finally starting to understand why this is the way it is, but working around it requires a lot of thought.I would like to have a single Expression protocol which can be us
Replies
1
Boosts
0
Views
342
Activity
Dec ’15
Reply to App does not show up in search results.
Oh big deal. We sell our books, audio material, Windows and OSX software (CDs and downloads) directly to our customers and maintain a close relationship with them and have done so since 1991. Our iOS Apps for iPad have to go via the App Store where Apple does nothing and collects 30% for nothing. Also, as the App Store is based in $USD and because of the current exchange rate our iPad Apps seem overpriced in our own country. If we sold directly this would not be the case. We're a small developer but have a niche education market.
Replies
Boosts
Views
Activity
Dec ’15
Does apple allow hunting and fishing video content on their app store?
I sent a email asking this question before, but I have not gotten a response. Anyway in the app submission guidlines there is a line that states Apps portraying realistic images of people or animals being killed or maimed, shot, stabbed, tortured or injured will be rejected. I work for a company and most of what we are creating, VOD systems and websites are geared toward outdoorsman, being hunting and fishing content. I have published a channel for our content on Roku's channel store and I am in the middle of developing my first swift app for tvOS with the same content. However, one of my superviser's told me that another company we have a relationship with tried to submit similar content and was rejected. So before I can move forward with my project I have to see if the app will be rejected because of our content. It has been a blast learning Swift 2.0 and finally getting the chance to work with tvOS/iOS. Our plan was to submit a tvOS and iOS app, with different layouts.
Replies
4
Boosts
0
Views
502
Activity
Dec ’15
siri is not saving dictation
Hi all,I just bought a new IPhone 6s and used Siri. I've dictated to call my sister, the relationship was saved according to Siri and when i asked to call again i had to do the whole process again. It doesn't seem to remember the relationship. The Software is IOS 9.2. Any information on this issue?Thank you!
Replies
0
Boosts
0
Views
84
Activity
Dec ’15
Required inits + convenience inits + inheritance == conundrum
While trying to convert an older Objective-C program to Swift, I've run into a hitch.So, let's say we've got a base class with a required initializer:class Base { required init(foo: Foo) { … } }and then we have a subclass, but the subclass includes a new parameter in the init, specific to the subclass, and satisfies the requirement via a convenience initializer:class Subclass: Base { required init(foo: Foo, bar: Bar) { ... super.init(foo: foo) ... } required convenience init(foo: Foo) { // Do some calculation to determine a default value for ‘bar’ from the input of ‘foo’. // Perhaps this calculation is quite a few lines of code. let bar = ... self.init(foo: foo, bar: bar) } }Now, that subclass gets subclassed once again:class SubSubclass: Subclass { required init(foo: Foo, bar: Bar) { … super.init(foo: Foo, bar: Bar) ... } required convenience init(foo: Foo) { // Uh oh. } }The trouble here is that we’re required to implement init(foo:) per the base class’s interface, but we cannot use Subclass’s perfectly ser
Replies
2
Boosts
0
Views
2k
Activity
Dec ’15
Reply to Required inits + convenience inits + inheritance == conundrum
Regarding this specific set of requirements, this is what I came up with in a playground:Ah, of course, that would work. D'oh, I'm not sure why I didn't consider that. Still not as nice as having the objects come in as non-optionals so the subclasses know exactly what they're getting, and still requires every subclass to implement a boilerplate convenience initializer that passes nil to the larger one, but still, it's much better than the workaround I'd been considering. Thanks.However, I don't understand the need for 'required'. What's the virtue of using it at all? I can't see any value in this case.Well, the example I showed above is an extremely simplified case, and is by no means representative of the entire class hierarchy. With that said, there are plenty of things that force you to put 'required' on your initializers in Swift, most of them having to do with anything involving any kind of polymorphism. If you are conforming to a protocol that contains an initializer, that initializer has to be marked a
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’15
Reply to Xcode crashes when I try to make a storyboard reference the target of a relationship segue
I'm having the same problem always when I try to do a relationship segue.
Replies
Boosts
Views
Activity
Dec ’15
Reply to SKStoreProductViewController
Hi PBK,I found a solution to the problem.Generate a class called e.g. StoreProductViewController inherited from SKStoreProductViewController. Added function:override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return [UIInterfaceOrientationMask.LandscapeLeft, UIInterfaceOrientationMask.LandscapeRight] }In my GLKViewController in function showStoreProductchangelet storeViewController:SKStoreProductViewController = SKStoreProductViewController()tolet storeViewController = StoreProductViewController()func showStoreProduct() { let productParameters = [SKStoreProductParameterITunesItemIdentifier : currentAppId] let storeViewController = StoreProductViewController() storeViewController.delegate = self storeViewController.loadProductWithParameters(productParameters, completionBlock: { (success: Bool, error: NSError?) -> Void in if success { self.presentViewController(storeViewController, animated: true, completion: nil) } else { print(ERROR: storeViewController: (error)) } })
Topic: App & System Services SubTopic: StoreKit Tags:
Replies
Boosts
Views
Activity
Dec ’15
Reply to getter and setter in Swift (from ObjC)
It seems my words are a little too short.The `imageFile` exists only in the class's implementation file, but `setRepresentedObject` method is another thing.As you added `override` on top of it, the property is declared in an anscestor class, which is written in Objective-C. The declaration looks like this, if rewritten in Swift: private var _representedObject: AnyObject? var representedObject: AnyObject? { get { return _representedObject } set { _representedObject = newValue } }Your overridden declaration re-declare the property as a renewed stored property, which means it has no relationship with the original backend store `_representedObject`.You need to override it as: override var representedObject: AnyObject? { get { return super.representedObject } set(newRepresentedObject) { super.representedObject = newRepresentedObject //... self.imageFile?.requestPreviewImage() } }To make all thing consistent with Objective-C ancestor class, you always need to override properties as computed property and ac
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’15
Reply to getter and setter in Swift (from ObjC)
In fact my code is pure Swift, no ObjC inside (ObjC is the sample code from WWDC than I am trying to port to Swift).If the sample code I'm seeing is near enough to the WWDC code, The `AAPLSlide` inherits `NSCollectionViewItem`, and I believe you have not rewritten NSCollectionViewItem (or its ancestor classes) in Swift. So, your code in Swift needs to interact with classes written in Objective-C.super refers to the var selected in ancestor class that I override ?Yes.The property `selected` is declared in NSCollectionViewItem class header as:@property (getter=isSelected) BOOL selected;Objective-C compiler interprets it as:- in the private ivar section BOOL _selected;- and accessor methods- (BOOL)isSelected; - (void)setSelected:(BOOL)selected;So, if `setSelected` is overridden in the Objective-C code, only setter of the property is overridden.As you know, Swift cannot override only setter, so you need to keep getter as defined in the ancestor class, that is the part: get { return super.selected }and it
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’15