Search results for

“SwiftData inheritance relationship”

4,986 results found

Post

Replies

Boosts

Views

Activity

Reply to Protocol extension dispatch anomalies
>> This code behaves as it does because protocol extensions are compile-time constructs.The problem with this is that it doesn't seem to be viable, as a compiler behavior:1. In the case of a class type conforming to the protocol(s) involved, the existing semantics of inheritance say that it doesn't matter (to instances of a subclass) whether a method is implemented in the subclass or a base class (when it's only implemented in one place, I mean, I'm not talking about overrides). If that weren't true, then it wouldn't be safe to factor behavior out of subclasses into base classes.2. In your 'extension Foo' example, the issue isn't whether the doFoo method is a compile-time construct, but the fact that 'self' already means something in terms of method lookup — it means to start with the class of the instance that's executing the code**. Unfortunately, in the current Swift, it means something else, apparently to start with a class chosen at compile time. Whatever that is, it isn't what 'self' mean
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to Protocol extension dispatch anomalies
I'm not sure that I understand the point you're making here, so please correct me if I'm misinterpreting. (And note also, I'm going to just ignore potential @objc complications.)I think you're saying that given the following code context,protocol P { func p() } extension P { func p() { print(Called default p implementation) } } class C: P {} func someFunction(obj: C) { obj.p() }the dispatch of obj.p() on line 12 must take account of the fact that obj may in fact be a subclass of C with its own p() implementation, and that that subclass's implementation of p() should be called in preference to the default p(). Otherwise, OO method inheritance might be considered broken.However, that is not in fact the behavior of the current implementation:// This is a continuation of the previous code... class D: C { func p() { print(Called D's p implementation) } } someFunction(D()) // Calls the default p implementationI agree that this is weird. I'm just pointing out that this is how it works.Mechanically, I think
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to Protocol extension dispatch anomalies
>> However, that is not in fact the behavior of the current implementation:>> […]>> I agree that this is weird. I'm just pointing out that this is how it works.I'm saying it's not just weird, it's wrong. The really weird thing is that it's wrong in 3 completely separate ways:1. P's p and D's p are actually unrelated methods of the same name. Note that there's no error message stating that D's p needs an override keyword, or that the two p's conflict (which they do).2. Class D conforms to P, and it's documented that If a conforming type provides its own implementation of a required method or property, that implementation will be used instead of the one provided by the extension. It isn't used.3. If you put a definition of p in class C, then that implementation *is* used instead of the one provided by the extension. By what mechanism? It's not regular inheritance (again, there's no need of an 'override' keyword, which real inheritance would require, and it works for structs w
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to Both watchOS 1 and watchOS 2 in the same iOS app bundle
Have an existing Watchkit 1.x app and added 2.0 targets as mentioned by others. To use simulator of b3, we set project deployment target to 9.0, app deplyoment target to 7.0. Don't see a way to change deployment targets for 1.x watch app and extension, so guessing they stay as they were (8.2). Fo Watch 2, don't see where to specify deployment target either, so guessing since they are 'new' they will inherit deployment target from overall project (9.0). This allows us to build/run in the Simulators to test new Watch 2 targets. Since we are aiming to deploy one app to the store (not one for each ios version), we have Base SDK set as follows:Main app, 1.x watch app and extension set to Latest IOS (IOS9). 2 watch app and extension set to Latest Watch OS (watch OS2).We have not tried to build/run for earlier versions (1.x) using this beta. Really using this setup to test watch 2 but with all code/targets together.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’15
Reply to Swift's object syntax not the clearest or most efficient
I think the current syntax using final and override are fine. The reason is as follows. If you've made the decision to define a new class, most likely it is because, you are designing for inheritence or you are inheriting another class you need which may or may not be from Objective-C which has no concept of final classes. So, most likely you are using classes because you have made a decision that you need or want to embrace inheritance. With that decision comes the responsibility to manage inheritance which means deciding what is final and what is accessible.By default, classes, methods and properties have internal access. With whole module optimization, you get much of the benefit that you would get by marking members final when using internal access which is the default. Where things matter most from a safety and performance perspective is when you choose to make a class or member public. In doing so, you must take responsibility to decide whether to mark it final or not
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
isUniquelyReferenced and NonObjectiveCBase
I'm having trouble figuring out how these are supposed to be used.The following code gives the error Cannot invoke 'isUniquelyReferenced' with an argument list of type '(inout Test)'.class Test {} var t = Test() isUniquelyReferenced(&t)I tried to fix that by inheriting from NonObjectiveCBase as the documentation seems to indicate, however that also does not work. The following code gives the error 'NonObjectiveCBase.Type' does not have a member named 'init'.class Test: NonObjectiveCBase { init() { super.init() } }And of course if you try to omit the call to super.init you receive an initializer error.Does anyone have a working example of how this is used?
2
0
495
Jul ’15
Xcode7 Beta 4 and @objc problem
I've just installed Xcode 7 beta 4 and suddenly I'm getting a compiler error on@objc class UtilityFunctionssayingOnly classes that inherit from NSObject can be declared @objcThe 'Using Swift with Cocoa and Object-C (Swift 2 Prerelease)' book statesA Swift class or protocol must be marked with the @objc attribute to be accessible and usable in Objective-C. This attribute tells the compiler that this piece of Swift code can be accessed from Objective-C. If your Swift class is a descendant of an Objective-C class, the compiler automatically adds the @objc attribute for you.This was working fine in beta 3. I can get it to compile by making the class inheritfrom NSObject but that shouldn't be necessary according to the quote above. Anyone know what's going on? Has @objc suddenly been deprecated in favour of inheriting from NSObject?
3
0
4.1k
Jul ’15
typealias-assignment in protocol-associated-type-declaration grammar... a mistake??
Swift 2 Programming Language (Swift 2 Prerelease) rev. 2015-06-08 > Language Reference > Protocol Associated Type DeclarationGRAMMAR OF A PROTOCOL ASSOCIATED TYPE DECLARATIONprotocol-associated-type-declaration → typealias-headtype-inheritance-clause (opt) typealias-assignment (opt)I'm leaning towards believing that the inclusion of typealias-assignment (opt) in this grammar production must have been a mistake - if not, can anybody give an example of how this might reasonably be used?
7
0
2.2k
Jul ’15
Reply to typealias-assignment in protocol-associated-type-declaration grammar... a mistake??
I don't think it's a bug, but the combination of a subtyping constraint and a type assignment is strange because the subtyping part (type-inheritance-clause_opt) is superfluous in this case.Here's some code showing the various alternatives. Type alias assignments are most useful to instantiate abstract associated types.protocol Buffer { typealias Element var value: Element { get } } protocol EquatableBuffer: Buffer, Equatable { // Constraining Element type typealias Element: Equatable } protocol IntBuffer: Buffer { // Instantiating Element type typealias Element = Int } protocol SuperfluousIntBuffer: Buffer, Equatable { // Not sure about the usefulness of this typealias Element: Equatable = Int }
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Best practice to change the default view using interface builder ?
Hi,I wonder what is the best practice to change the default view from the storyboard and use a webview instead.From the storyboard, using drag and drop, I add a webview to the default view, but I wonder if it is the right way to do beacause, webview inherits from UIView ... can't I directly use the webview as the default view ?What should I do to directly use the webview as the default view using the storyboard ?Thanks in advance.Regards.
1
0
189
Jul ’15
Reply to Xcode7 Beta 4 and @objc problem
> Has @objc suddenly been deprecated in favour of inheriting from NSObject?Pretty much yes. @objc on Swift-rooted classes never quite behaved like an NSObject-rooted class, leading to various weirdness in the generated header and at runtime. You can still treat any Swift class instance as an AnyObject, mark methods and properties on a Swift class as @objc, and conform to Objective-C protocols; the class just isn't exposed in the generated header and doesn't default to having its members available in Objective-C.(And we should update the book. Thanks for catching that!)
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
statistically querying an NSArray holding core data fetched objects (with relationships)
Lets say I have fetched all objects from my store with entity Event which match event names 'Party'. Lets say I got 10 results and out of these 10 results 4 have an entity object of type People with name 'John' and 3 have People objects with name 'Mary' and 3 have both, at the relationship end. I want to query the fetch results array as to how many objects of Event Party have John in them. How do I do that?I am doing this so that I can show a pie chart of all events sliced by people name.Should I be doing a predicate search on the Events Array and then find out the count of each or is there a simpler way.My model is too complex for me to handle the various pie chart scenarios by code.I know I can use the MoC's- (NSUInteger)countForFetchRequest:(NSFetchRequest *)request error:(NSError **)errorbut that will query the store again. And I already have fetched results in my hand that can be overviewd in a pie chart in various ways (like show a pie chart based on events for all the people fetched in the sam
Topic: UI Frameworks SubTopic: AppKit Tags:
0
0
95
Jul ’15
Reply to Array declared in class but the value can't be accessed by more than one method in that class?
And, not an issue which could be causing sampleArray to not to be recognized, but...You are also setting the 'title' parameter inherited from UIViewController(var title: String? // Localized title for use by a parent controller.)instead of using a local variable.Is this what you intended?let title = sampleArray[indexPath.row] as StringAlso, there is a runtime issue you haven't hit yet if your code won't compile, but if the table is visible it will probably be asking for the data using tableView:cellForRowAtIndexPath: before tableView:didSelectRowAtIndexPath: is called and you will get a runtime exception because the array is still empty and tableView:numberOfRowsInSection: is saying there are 10 rows.If you want to fill your array with placeholder data, doing it in viewDidLoad() will make sure it is available for the other methods.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to Protocol extension dispatch anomalies
>> This code behaves as it does because protocol extensions are compile-time constructs.The problem with this is that it doesn't seem to be viable, as a compiler behavior:1. In the case of a class type conforming to the protocol(s) involved, the existing semantics of inheritance say that it doesn't matter (to instances of a subclass) whether a method is implemented in the subclass or a base class (when it's only implemented in one place, I mean, I'm not talking about overrides). If that weren't true, then it wouldn't be safe to factor behavior out of subclasses into base classes.2. In your 'extension Foo' example, the issue isn't whether the doFoo method is a compile-time construct, but the fact that 'self' already means something in terms of method lookup — it means to start with the class of the instance that's executing the code**. Unfortunately, in the current Swift, it means something else, apparently to start with a class chosen at compile time. Whatever that is, it isn't what 'self' mean
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to Protocol extension dispatch anomalies
I'm not sure that I understand the point you're making here, so please correct me if I'm misinterpreting. (And note also, I'm going to just ignore potential @objc complications.)I think you're saying that given the following code context,protocol P { func p() } extension P { func p() { print(Called default p implementation) } } class C: P {} func someFunction(obj: C) { obj.p() }the dispatch of obj.p() on line 12 must take account of the fact that obj may in fact be a subclass of C with its own p() implementation, and that that subclass's implementation of p() should be called in preference to the default p(). Otherwise, OO method inheritance might be considered broken.However, that is not in fact the behavior of the current implementation:// This is a continuation of the previous code... class D: C { func p() { print(Called D's p implementation) } } someFunction(D()) // Calls the default p implementationI agree that this is weird. I'm just pointing out that this is how it works.Mechanically, I think
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to Protocol extension dispatch anomalies
>> However, that is not in fact the behavior of the current implementation:>> […]>> I agree that this is weird. I'm just pointing out that this is how it works.I'm saying it's not just weird, it's wrong. The really weird thing is that it's wrong in 3 completely separate ways:1. P's p and D's p are actually unrelated methods of the same name. Note that there's no error message stating that D's p needs an override keyword, or that the two p's conflict (which they do).2. Class D conforms to P, and it's documented that If a conforming type provides its own implementation of a required method or property, that implementation will be used instead of the one provided by the extension. It isn't used.3. If you put a definition of p in class C, then that implementation *is* used instead of the one provided by the extension. By what mechanism? It's not regular inheritance (again, there's no need of an 'override' keyword, which real inheritance would require, and it works for structs w
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to Both watchOS 1 and watchOS 2 in the same iOS app bundle
Have an existing Watchkit 1.x app and added 2.0 targets as mentioned by others. To use simulator of b3, we set project deployment target to 9.0, app deplyoment target to 7.0. Don't see a way to change deployment targets for 1.x watch app and extension, so guessing they stay as they were (8.2). Fo Watch 2, don't see where to specify deployment target either, so guessing since they are 'new' they will inherit deployment target from overall project (9.0). This allows us to build/run in the Simulators to test new Watch 2 targets. Since we are aiming to deploy one app to the store (not one for each ios version), we have Base SDK set as follows:Main app, 1.x watch app and extension set to Latest IOS (IOS9). 2 watch app and extension set to Latest Watch OS (watch OS2).We have not tried to build/run for earlier versions (1.x) using this beta. Really using this setup to test watch 2 but with all code/targets together.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to HKWorkoutSession in Beta 4 seems to require a different setup?
Yes is does. It inherits NSObject and HKWorkoutSessionDelegate. The code was all working fine just yesterday, and after upgrading to xCode beta 4, I get errors on this code.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to Swift's object syntax not the clearest or most efficient
I think the current syntax using final and override are fine. The reason is as follows. If you've made the decision to define a new class, most likely it is because, you are designing for inheritence or you are inheriting another class you need which may or may not be from Objective-C which has no concept of final classes. So, most likely you are using classes because you have made a decision that you need or want to embrace inheritance. With that decision comes the responsibility to manage inheritance which means deciding what is final and what is accessible.By default, classes, methods and properties have internal access. With whole module optimization, you get much of the benefit that you would get by marking members final when using internal access which is the default. Where things matter most from a safety and performance perspective is when you choose to make a class or member public. In doing so, you must take responsibility to decide whether to mark it final or not
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
isUniquelyReferenced and NonObjectiveCBase
I'm having trouble figuring out how these are supposed to be used.The following code gives the error Cannot invoke 'isUniquelyReferenced' with an argument list of type '(inout Test)'.class Test {} var t = Test() isUniquelyReferenced(&t)I tried to fix that by inheriting from NonObjectiveCBase as the documentation seems to indicate, however that also does not work. The following code gives the error 'NonObjectiveCBase.Type' does not have a member named 'init'.class Test: NonObjectiveCBase { init() { super.init() } }And of course if you try to omit the call to super.init you receive an initializer error.Does anyone have a working example of how this is used?
Replies
2
Boosts
0
Views
495
Activity
Jul ’15
Xcode7 Beta 4 and @objc problem
I've just installed Xcode 7 beta 4 and suddenly I'm getting a compiler error on@objc class UtilityFunctionssayingOnly classes that inherit from NSObject can be declared @objcThe 'Using Swift with Cocoa and Object-C (Swift 2 Prerelease)' book statesA Swift class or protocol must be marked with the @objc attribute to be accessible and usable in Objective-C. This attribute tells the compiler that this piece of Swift code can be accessed from Objective-C. If your Swift class is a descendant of an Objective-C class, the compiler automatically adds the @objc attribute for you.This was working fine in beta 3. I can get it to compile by making the class inheritfrom NSObject but that shouldn't be necessary according to the quote above. Anyone know what's going on? Has @objc suddenly been deprecated in favour of inheriting from NSObject?
Replies
3
Boosts
0
Views
4.1k
Activity
Jul ’15
typealias-assignment in protocol-associated-type-declaration grammar... a mistake??
Swift 2 Programming Language (Swift 2 Prerelease) rev. 2015-06-08 > Language Reference > Protocol Associated Type DeclarationGRAMMAR OF A PROTOCOL ASSOCIATED TYPE DECLARATIONprotocol-associated-type-declaration → typealias-headtype-inheritance-clause (opt) typealias-assignment (opt)I'm leaning towards believing that the inclusion of typealias-assignment (opt) in this grammar production must have been a mistake - if not, can anybody give an example of how this might reasonably be used?
Replies
7
Boosts
0
Views
2.2k
Activity
Jul ’15
Reply to typealias-assignment in protocol-associated-type-declaration grammar... a mistake??
I don't think it's a bug, but the combination of a subtyping constraint and a type assignment is strange because the subtyping part (type-inheritance-clause_opt) is superfluous in this case.Here's some code showing the various alternatives. Type alias assignments are most useful to instantiate abstract associated types.protocol Buffer { typealias Element var value: Element { get } } protocol EquatableBuffer: Buffer, Equatable { // Constraining Element type typealias Element: Equatable } protocol IntBuffer: Buffer { // Instantiating Element type typealias Element = Int } protocol SuperfluousIntBuffer: Buffer, Equatable { // Not sure about the usefulness of this typealias Element: Equatable = Int }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Best practice to change the default view using interface builder ?
Hi,I wonder what is the best practice to change the default view from the storyboard and use a webview instead.From the storyboard, using drag and drop, I add a webview to the default view, but I wonder if it is the right way to do beacause, webview inherits from UIView ... can't I directly use the webview as the default view ?What should I do to directly use the webview as the default view using the storyboard ?Thanks in advance.Regards.
Replies
1
Boosts
0
Views
189
Activity
Jul ’15
Reply to Xcode7 Beta 4 and @objc problem
> Has @objc suddenly been deprecated in favour of inheriting from NSObject?Pretty much yes. @objc on Swift-rooted classes never quite behaved like an NSObject-rooted class, leading to various weirdness in the generated header and at runtime. You can still treat any Swift class instance as an AnyObject, mark methods and properties on a Swift class as @objc, and conform to Objective-C protocols; the class just isn't exposed in the generated header and doesn't default to having its members available in Objective-C.(And we should update the book. Thanks for catching that!)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
statistically querying an NSArray holding core data fetched objects (with relationships)
Lets say I have fetched all objects from my store with entity Event which match event names 'Party'. Lets say I got 10 results and out of these 10 results 4 have an entity object of type People with name 'John' and 3 have People objects with name 'Mary' and 3 have both, at the relationship end. I want to query the fetch results array as to how many objects of Event Party have John in them. How do I do that?I am doing this so that I can show a pie chart of all events sliced by people name.Should I be doing a predicate search on the Events Array and then find out the count of each or is there a simpler way.My model is too complex for me to handle the various pie chart scenarios by code.I know I can use the MoC's- (NSUInteger)countForFetchRequest:(NSFetchRequest *)request error:(NSError **)errorbut that will query the store again. And I already have fetched results in my hand that can be overviewd in a pie chart in various ways (like show a pie chart based on events for all the people fetched in the sam
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
0
Boosts
0
Views
95
Activity
Jul ’15
Download attempt goes to My Apple ID page
When I try to download El Capitan or Xcode 7 it goes to a 'My Apple ID' page. Logging in there only manages my account, but I never get an option to download.What is it looking for? What is the relationship between developer accounts and apple IDs.
Replies
5
Boosts
0
Views
445
Activity
Jul ’15
Reply to Array declared in class but the value can't be accessed by more than one method in that class?
And, not an issue which could be causing sampleArray to not to be recognized, but...You are also setting the 'title' parameter inherited from UIViewController(var title: String? // Localized title for use by a parent controller.)instead of using a local variable.Is this what you intended?let title = sampleArray[indexPath.row] as StringAlso, there is a runtime issue you haven't hit yet if your code won't compile, but if the table is visible it will probably be asking for the data using tableView:cellForRowAtIndexPath: before tableView:didSelectRowAtIndexPath: is called and you will get a runtime exception because the array is still empty and tableView:numberOfRowsInSection: is saying there are 10 rows.If you want to fill your array with placeholder data, doing it in viewDidLoad() will make sure it is available for the other methods.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15