Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

Custom equates operator
Hi,I have a class that inherits from nsobject and I want to write a custom '==' operator for it. According to thishttps://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID28I should be able to just add: override func == (left: GPPlace, right: GPPlace) -> Bool { return (left.placeID == right.placeID) }but all that piece of code gets me is:GPPlace.swift:38:19: Operators are only allowed at global scopeGPPlace.swift:38:21: Consecutive declarations on a line must be separated by ';'GPPlace.swift:38:22: Expected declaration
3
0
435
Oct ’15
Reply to Custom equates operator
I have a class that inherits from nsobject and I want to write a custom '==' operator for it.If the class is derived from NSObject you’re probably better off overriding -isEqual:. That way, if the object ‘escapes’ into the Objective-C world (and that’s if not going to happen, why are you subclassing NSObject in the first place?) then equality will work over there as well. Share and Enjoy — Quinn The Eskimo! Apple Developer Relations, Developer Technical Support, Core OS/Hardware let myEmail = eskimo + 1 + @apple.com
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’15
about categories and overridden methods...
Hi,some of my classes are gowing very big. I would like to use categories for code management. I would also like to override some methods like viewDidLoad inside the category and continue its implementation from there.Now in inheritance we can call [super viewDidLoad] to see to it that the actualy implementation of viewDidLoad is always called before the trailing part of the method is executed in out subclass.How can we ensure this in a category?
Topic: UI Frameworks SubTopic: AppKit Tags:
7
0
1.5k
Oct ’15
Reply to Help Positioning Objects around another Object
Deeeds, Ok. Think of a molecule if that helps. You have a core (sphere) and I am wanting to position a bunch of related items connected to the sphere. One way to look at it is like the Sun with static planets around it. I want to be able to programmatically keep adding planets with a connector to the sun. These planets themselves will later have other suns connected to them. This is a visual way of defining relationships. If it helps, this is mapping servers and applications when I get it to work. So there could be 1000 applications running on one server. Those applications then will be attached to mulitple servers. So I want to visualize this complex world of connections visually in the 3D space. I expect to have spheres as servers and cubes perhaps as applications. I need to place them without knowing ahead of time how many connections I have and the data can change to add and delete connections. Does this help?John
Topic: Graphics & Games SubTopic: SceneKit Tags:
Oct ’15
Reply to Problem with Particle Editor
In your online travels, have you ever seen a list, online, that's titled Known Issues?These lists are sometimes created by the people building frameworks to benefit the developrs that use them and provide a point of communication between end users and creators.It's a very useful type of list. Saves users 1000's of hours of frustration, annoyance and extreme anger.These lists even generate goodwill, foster a sense of relationship between users and creators and possibly even provide the impetus and hub around which a community can form. Ultimately, I believe, these simple little lists lead to a better world, for everyone.Just a suggestion.// No, haven't filed a bug report as a feature suggestion. I assume you have a pen and paper, or a whiteboard. Perhaps even a notes app. Maybe even a todo list.
Topic: Graphics & Games SubTopic: SpriteKit Tags:
Oct ’15
Reply to Accessing a View Controller in a Show Segue
I think I have worked out whyAlthough in interface builder it looks as though the relationship is a segue, it is apparently not treated as such. It is a 'relationship' type and is made through containment (child / parent view controllers). Therefore I was able to pass down the represetedObject (the document) from my window to its children by implementing the following in my subclasses.- (void)setRepresentedObject:(id)representedObject { [super setRepresentedObject:representedObject]; self.document = representedObject; for (NSViewController *viewController in self.childViewControllers) { viewController.representedObject = representedObject; } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Oct ’15
constant property cannot be modified by a subclass
For class instances, a constant property can only be modified during initialization by the class that introduces it. It cannot be modified by a subclass.-《The Swift Programming Language》If I want to inherit a constant from super class and modified during subclass init.I konw it won't work.So I changed to this:class commonStyle { private var insidevar:someclass var outsidelet:someclass {return insidevar} init(){ insidevar = someclass() } } class iPhone6Style:commonStyle { override init() { super.init() insidevar = someclass(subclass value) } }Is there a better solution?Thanks a lot.
2
0
514
Oct ’15
Reply to Issues with memory leaks
If you have memory leaks from Core Data, then you're supposed to follow the instructions for Core Data memory management for reducing memory overhead: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Performance.html#//apple_ref/doc/uid/TP40001075-CH25-SW10Core Data relationships get represented as strong properties. As a result, if you load a hierarchy of entity values into memory, that can create strong reference cycles. If you get those memory cycles, you have use methods described under Reducing Memory Overhead to unload the objects so that the reference cycles break.
Oct ’15
Reply to Issues with memory leaks
Thank you both for yours answers.I already watchied past WWDC videos, and there are not memory cycles in the code, also for the test I am using a single CoreData Object withouth relationships to isolate the issue.I realized that the leaks are due to the use of multiple ManagedObjectContextsUsing Multiple ManagedObjectContext generate leaks:// AppDelegate.m - (NSManagedObjectContext *)managedObjectContext{ if (_managedObjectContext != nil) { return _managedObjectContext; } _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; _managedObjectContext.parentContext = [self writerManagedObjectContext]; return _managedObjectContext;}- (NSManagedObjectContext *)writerManagedObjectContext{ if (_writerManagedObjectContext != nil) { return _writerManagedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { _writerManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType
Oct ’15
Reply to Why can't a subclass mark a NS_DESIGNATED_INITIALIZER and use a convenience initializer from its superclass?
Hmm..that would be an odd choice for the programmer to make, I think. If the subclasser implemented initWithWindow: when initWithWindow is marked NS_UNAVAILABLE by the superclass...I'm not sure whether or not the subclass would be warned (never tried it)...I haven't really thought about it through, but if you mark the designated initializer of your superclass unavailable...and then in your subclass marked a different designated initializer, then a subclass of you (so now we are at the grandchild of the window controller) should use its daddy's designated initializer, or one of its conveniance initializers in its designated initializer, so long as they aren't marked unavailable.So this way, a subclass can inherit from its superclass by using a conveniance initializer, because a conveniance initializer should be able to set up a valid object for the superclass, but also take advantage of the conveniance of the initializer without having to reimplement stuff like nib loading. If there was a need to subc
Topic: Programming Languages SubTopic: General Tags:
Oct ’15
Reply to nullable, nonnull, can a subclass change its superclass' rules?
I see.I'll have to stop fighting it and make Output not be a subclass of Input, and just either redeclare the shared properties in Output that have the same name and attributes or move them to protocol or a base class. I'm still used to the more layed back ObjC I guess...where this stuff is not strictly enforced. Since this is all my code I sort of know changing the attributes wouldn't break. Input and Output conforms to NSSecureCoding...also kind of liked having Output inherit so it can inherit some decoding/encoding from the superclass (probably go with a base class). I do think these attributes are useful for catching bugs so I do want to use them.
Topic: Programming Languages SubTopic: General Tags:
Oct ’15
Reply to Why can't a subclass mark a NS_DESIGNATED_INITIALIZER and use a convenience initializer from its superclass?
Did the programming guide mention anything about programming on a desert island, with no access to the internet, and using a class hierarchy four-five levels deep from libraries where you don't have access to the source code, and that the header files weren't commented? Joking.But jokes aside. I'm still skeptical of this type of enforcement, it can sort of hinder advantages OO gives us (inheritance mainly). Forget ImagesWindowController. Let's say I wanted to make a new base window controller class to change the rules a bit. Call it InterfaceBuilderLoadingWindowController. InterfaceBuilderWindowController will do nothing more than change the designated initializer.@interface InterfaceBuilderLoadingWindowController : NSWindowController -(instancetype)initWithWindowNibName:(NSString *)windowNibName NS_DESIGNATED_INITIALIZER; -(instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE; -(instancetype)initWithWindow:(NSWindow *)window NS_UNAVAILABLE; @endAll potential classes that inherit from
Topic: Programming Languages SubTopic: General Tags:
Oct ’15
Reply to Best game structure to work with in SpriteKit
This is a really good question, and highlights one of the very (few) great things about Unity.The truly modular nature of the Entity/Component/Script relationships in Unity is fantastic.When I first read about the game loop methods within SceneKit and SpriteKit I thought Apple had done the world a favour and given us something similar.But it's not.Someone with more expertise in describing how these game loops and inter-object communication works - want to chime in and answer the question?Please!!!I've just poked around in the documentation, it is horrid. It's documentation in the lowest sense of the word. Not educational material, that's for sure. As reference material it's a mess, too.
Topic: Graphics & Games SubTopic: SceneKit Tags:
Oct ’15
Reply to Stored Properties don't always override a protocol extension
This has been coming up a lot, in various guises. Protocol extensions are just compile-time syntactic sugar. They don't create any actual hierarchy or overridable relationship.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’15
Custom equates operator
Hi,I have a class that inherits from nsobject and I want to write a custom '==' operator for it. According to thishttps://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID28I should be able to just add: override func == (left: GPPlace, right: GPPlace) -> Bool { return (left.placeID == right.placeID) }but all that piece of code gets me is:GPPlace.swift:38:19: Operators are only allowed at global scopeGPPlace.swift:38:21: Consecutive declarations on a line must be separated by ';'GPPlace.swift:38:22: Expected declaration
Replies
3
Boosts
0
Views
435
Activity
Oct ’15
Reply to Custom equates operator
I have a class that inherits from nsobject and I want to write a custom '==' operator for it.If the class is derived from NSObject you’re probably better off overriding -isEqual:. That way, if the object ‘escapes’ into the Objective-C world (and that’s if not going to happen, why are you subclassing NSObject in the first place?) then equality will work over there as well. Share and Enjoy — Quinn The Eskimo! Apple Developer Relations, Developer Technical Support, Core OS/Hardware let myEmail = eskimo + 1 + @apple.com
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’15
about categories and overridden methods...
Hi,some of my classes are gowing very big. I would like to use categories for code management. I would also like to override some methods like viewDidLoad inside the category and continue its implementation from there.Now in inheritance we can call [super viewDidLoad] to see to it that the actualy implementation of viewDidLoad is always called before the trailing part of the method is executed in out subclass.How can we ensure this in a category?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
7
Boosts
0
Views
1.5k
Activity
Oct ’15
Reply to Help Positioning Objects around another Object
Deeeds, Ok. Think of a molecule if that helps. You have a core (sphere) and I am wanting to position a bunch of related items connected to the sphere. One way to look at it is like the Sun with static planets around it. I want to be able to programmatically keep adding planets with a connector to the sun. These planets themselves will later have other suns connected to them. This is a visual way of defining relationships. If it helps, this is mapping servers and applications when I get it to work. So there could be 1000 applications running on one server. Those applications then will be attached to mulitple servers. So I want to visualize this complex world of connections visually in the 3D space. I expect to have spheres as servers and cubes perhaps as applications. I need to place them without knowing ahead of time how many connections I have and the data can change to add and delete connections. Does this help?John
Topic: Graphics & Games SubTopic: SceneKit Tags:
Replies
Boosts
Views
Activity
Oct ’15
Reply to Problem with Particle Editor
In your online travels, have you ever seen a list, online, that's titled Known Issues?These lists are sometimes created by the people building frameworks to benefit the developrs that use them and provide a point of communication between end users and creators.It's a very useful type of list. Saves users 1000's of hours of frustration, annoyance and extreme anger.These lists even generate goodwill, foster a sense of relationship between users and creators and possibly even provide the impetus and hub around which a community can form. Ultimately, I believe, these simple little lists lead to a better world, for everyone.Just a suggestion.// No, haven't filed a bug report as a feature suggestion. I assume you have a pen and paper, or a whiteboard. Perhaps even a notes app. Maybe even a todo list.
Topic: Graphics & Games SubTopic: SpriteKit Tags:
Replies
Boosts
Views
Activity
Oct ’15
Reply to Accessing a View Controller in a Show Segue
I think I have worked out whyAlthough in interface builder it looks as though the relationship is a segue, it is apparently not treated as such. It is a 'relationship' type and is made through containment (child / parent view controllers). Therefore I was able to pass down the represetedObject (the document) from my window to its children by implementing the following in my subclasses.- (void)setRepresentedObject:(id)representedObject { [super setRepresentedObject:representedObject]; self.document = representedObject; for (NSViewController *viewController in self.childViewControllers) { viewController.representedObject = representedObject; } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Oct ’15
constant property cannot be modified by a subclass
For class instances, a constant property can only be modified during initialization by the class that introduces it. It cannot be modified by a subclass.-《The Swift Programming Language》If I want to inherit a constant from super class and modified during subclass init.I konw it won't work.So I changed to this:class commonStyle { private var insidevar:someclass var outsidelet:someclass {return insidevar} init(){ insidevar = someclass() } } class iPhone6Style:commonStyle { override init() { super.init() insidevar = someclass(subclass value) } }Is there a better solution?Thanks a lot.
Replies
2
Boosts
0
Views
514
Activity
Oct ’15
Reply to Issues with memory leaks
If you have memory leaks from Core Data, then you're supposed to follow the instructions for Core Data memory management for reducing memory overhead: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Performance.html#//apple_ref/doc/uid/TP40001075-CH25-SW10Core Data relationships get represented as strong properties. As a result, if you load a hierarchy of entity values into memory, that can create strong reference cycles. If you get those memory cycles, you have use methods described under Reducing Memory Overhead to unload the objects so that the reference cycles break.
Replies
Boosts
Views
Activity
Oct ’15
Reply to Issues with memory leaks
Thank you both for yours answers.I already watchied past WWDC videos, and there are not memory cycles in the code, also for the test I am using a single CoreData Object withouth relationships to isolate the issue.I realized that the leaks are due to the use of multiple ManagedObjectContextsUsing Multiple ManagedObjectContext generate leaks:// AppDelegate.m - (NSManagedObjectContext *)managedObjectContext{ if (_managedObjectContext != nil) { return _managedObjectContext; } _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; _managedObjectContext.parentContext = [self writerManagedObjectContext]; return _managedObjectContext;}- (NSManagedObjectContext *)writerManagedObjectContext{ if (_writerManagedObjectContext != nil) { return _writerManagedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { _writerManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType
Replies
Boosts
Views
Activity
Oct ’15
Reply to Why can't a subclass mark a NS_DESIGNATED_INITIALIZER and use a convenience initializer from its superclass?
Hmm..that would be an odd choice for the programmer to make, I think. If the subclasser implemented initWithWindow: when initWithWindow is marked NS_UNAVAILABLE by the superclass...I'm not sure whether or not the subclass would be warned (never tried it)...I haven't really thought about it through, but if you mark the designated initializer of your superclass unavailable...and then in your subclass marked a different designated initializer, then a subclass of you (so now we are at the grandchild of the window controller) should use its daddy's designated initializer, or one of its conveniance initializers in its designated initializer, so long as they aren't marked unavailable.So this way, a subclass can inherit from its superclass by using a conveniance initializer, because a conveniance initializer should be able to set up a valid object for the superclass, but also take advantage of the conveniance of the initializer without having to reimplement stuff like nib loading. If there was a need to subc
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’15
Reply to nullable, nonnull, can a subclass change its superclass' rules?
I see.I'll have to stop fighting it and make Output not be a subclass of Input, and just either redeclare the shared properties in Output that have the same name and attributes or move them to protocol or a base class. I'm still used to the more layed back ObjC I guess...where this stuff is not strictly enforced. Since this is all my code I sort of know changing the attributes wouldn't break. Input and Output conforms to NSSecureCoding...also kind of liked having Output inherit so it can inherit some decoding/encoding from the superclass (probably go with a base class). I do think these attributes are useful for catching bugs so I do want to use them.
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’15
Reply to Why can't a subclass mark a NS_DESIGNATED_INITIALIZER and use a convenience initializer from its superclass?
Did the programming guide mention anything about programming on a desert island, with no access to the internet, and using a class hierarchy four-five levels deep from libraries where you don't have access to the source code, and that the header files weren't commented? Joking.But jokes aside. I'm still skeptical of this type of enforcement, it can sort of hinder advantages OO gives us (inheritance mainly). Forget ImagesWindowController. Let's say I wanted to make a new base window controller class to change the rules a bit. Call it InterfaceBuilderLoadingWindowController. InterfaceBuilderWindowController will do nothing more than change the designated initializer.@interface InterfaceBuilderLoadingWindowController : NSWindowController -(instancetype)initWithWindowNibName:(NSString *)windowNibName NS_DESIGNATED_INITIALIZER; -(instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE; -(instancetype)initWithWindow:(NSWindow *)window NS_UNAVAILABLE; @endAll potential classes that inherit from
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’15
Reply to Best game structure to work with in SpriteKit
This is a really good question, and highlights one of the very (few) great things about Unity.The truly modular nature of the Entity/Component/Script relationships in Unity is fantastic.When I first read about the game loop methods within SceneKit and SpriteKit I thought Apple had done the world a favour and given us something similar.But it's not.Someone with more expertise in describing how these game loops and inter-object communication works - want to chime in and answer the question?Please!!!I've just poked around in the documentation, it is horrid. It's documentation in the lowest sense of the word. Not educational material, that's for sure. As reference material it's a mess, too.
Topic: Graphics & Games SubTopic: SceneKit Tags:
Replies
Boosts
Views
Activity
Oct ’15
Reply to Custom images/dots in UIPageControl
You can only change UIPageControl's indicator tint color. I would make a custom class inherited from the UIControl.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Oct ’15