Search results for

“SwiftData inheritance relationship”

4,986 results found

Post

Replies

Boosts

Views

Activity

Using .sks files with custom classes as reference nodes?
What is the proper way to do this? For example: I have two .sks files that both have a custom class associated with them. If I include a reference node on one of them and link that reference node to the other .sks file and run the project I experience a crash.Attemped to add a SKNode which already has a parent: <SKSpriteNode> name:'SKSpriteNode_0' texture:['nil'] position:{596.5, 412.5} scale:{1.00, 1.00} size:{100, 100} anchor:{0.5, 0.5} rotation:0.00The reference node works without custom classes. I am also unsure whether I should be inheriting from SKScene, or SKNode in my custom classes. Doing either seems to cause a crash. If I inherit from SKNode I get the above message. If SKScene I get an error about adding a physics world to one that already exists, which makes sense.
2
0
921
Jun ’15
Do Generics not inherit initializers?
Four classes, first two normal, Two inherits from One, Two inherits One's initializers as expected.Second two are generic, Four<T> inherits from Three<T>, but everything else is the same. However Four doesn't inherit Three's initializer.Is that a bug or have I missed yet something else in the Swift book?public class One { public var value : Int public init( value : Int ) { self.value = value } } public class Two : One { public func foo() { print( value is (value) ) } } public class Three<T> { public var value : T public init( value : T ) { self.value = value } } public class Four<T> : Three<T> { public func foo() { print( value is (value) ) } } let x = Two( value : 123 ) // *** WORKS ****, Two inherits One's init(value:) method x.foo() let y = Four<Int>( value : 123 ) // Four<Int>' cannot be constructed because it has no accessible initializers y.foo()
0
0
981
Jun ’15
New behavior for `Create NSManagedObject Subclass…` bug?
With Xcode 7, two different files are created when you choose to `Create NSManagedObject Subclass`. One file is an extension that adds the properties that are added in the model editor. You aren't supposed to edit this file. Instead you edit the second file, the class file, that's created. This is where you add any custom functionality you want your NSManagedObject subclass to have. The point of this, as far as I can tell, is so that you can add your custom functionality, but when you later change the model, you can regenerate a new extension with the updated attributes/relationships without affecting or overwriting the custom code that you wrote.But...Xcode 7 beta 1 isn't doing this. Selecting `Create NSManagedObject Subclass` blows away both files. Is this a bug or am I missing something?Erik
1
0
423
Jun ’15
TIFF subviews
I've inherited an application that must read and process about 4000 multi-page tiff images. I'm not an image expert, and I'd love to utilize UIImage to view these, but it would appear that UIImage is ignoring any additional subviews in the tiff file. It will correctly report and display the first image.I was originally optimistic that I could utilize the images property, but since these are not animated images, this property returns nil. I'm able to verify that my images have multiple pages (subviews) utliizing SwiftView.if let img = UIImage(named: multipageTiff) { if let images = img.images as? [UIImage] { println(images (images.count)) } else { println(images is nil) } image = imgThe above code works great at assigning the original image to an UIImageView (image), however the println returns nil, so I'm stuck. Any suggestions would be greatly appreciated.Thanks!
3
0
807
Jun ’15
Protocol Extension Collision Question
Hi,If I have a struct that conforms to two protocols with the same method - that's fine. If both protocols implement the method in their extension then there is, of course, a problem. In other words, I expect the following to have issues because Thing can't decide which implementation of doThis() it supports. This is the classic diamond problem with multiple inheritance.=====protocol OneDoThisable { func doThis()}protocol TwoDoThisable { func doThis()}extension OneDoThisable { func doThis() { print(One's implementation) }}extension TwoDoThisable { func doThis() { print(Two's implementation) }}struct Thing: OneDoThisable, TwoDoThisable {}let thing = Thing()thing.doThis()=====What I'm asking is how could I disambiguate. I'd like to do something like this.====struct Thing: OneDoThisable, TwoDoThisable { func doThis() { (self as OneDoThisable).doThis() }}====In my own code I can just change the name of one of the methods. In case of two library protocols colliding... I can't always avoid such a collision
2
0
1.6k
Jun ’15
Swift Core Data Relationship to Same Entity
Hello,i'm new to Swift Programming and I'm struggling with Core Data a bit.My Data Model looks like the following:I have Items with multiple values like id, name, description, etc... nothing special, BUT Items can have parts that they are made of.For example:Item1ID: 1Name: OneParts: Subitem1ID:2Name: SubOneSubitem2ID: 3Name: SubTwoParts: Subsub1ID:4Name: SububTwoItem2ID: 5The setup in the xcdatamodelc is fairly simple, but i don't actually know how to fill it with data and save it.The data comes from a mysql database (there is a column isPartOf which specifies the parent-child relationship).I haven't found any resource on google which is addressing a similar setup, can anyone help me with my problem or knows Links/Books with information that can help me?Thank you
0
0
523
Jun ’15
How does one instantiate a generics-supported UIViewController subclass?
How does one instantiate a generics-supported UIViewController subclass?For example, consider a class likeclass SpecialViewController<T: UIView> : UIViewController{ }Interface Builder does not seem to handle these (in neither Storyboards nor simple .xibs)Furthermore, the default initializers seem to no longer be inherited (init, init(withNibName: String, bundle: ...), and even init(style: UITableViewStyle) for UITableViewController subclasses)Are there any known workarounds?
3
0
2.4k
Jun ’15
How to expose pure Swift classes to Objective-C correctly?
Consider this:MyFile.swift:@objc class SomeGuy { }MyClass.m:#import MyApp-Swift.h @interface SomeClass @end @implementation SomeClass - (void)someMethod { SomeGuy *someGuy = [[SomeGuy alloc] init]; } @endIn other words: have a pure Swift class annotated with @objc so it’s visible to Objective-C code. In Objective-C code, try to instantiate that class.If you were to run the above, you’d get compiler error: “no known class method for selector 'alloc'”One way to fix this would be to make SomeGuy inherit from NSObject. But I don’t want to do that, since I feel it adds too much cruft, the class isn’t really inheriting from NSObject by its nature, it is a pure swift class.Another way to fix: over on the Objective-C side, have a category:@interface SomeGuy (Dummy) + (instancetype)alloc; @endThis works and feels less weird, but still weird. It feels that the Swift-to-ObjC should autogenerate the alloc declaration for me in this case, since if I just add this category interface, everything works corr
0
0
1.5k
Jun ’15
How do I know which Foundation classes implement custom isEqual and not just inherit NSObject implementation?
For example, how can I be sure that UILocalNotification isEqual: result is not just result of comparing them by memory address?Should I rely on assumption that every class has custom isEqual implementation? Or should I treat every class like a not supporting isEqual if they don't have special description about isEqual in documentation?
4
0
435
Jun ’15
GKStateMachine: confusing terminology; feels kind of 'heavy'
Hello,I've been using the GKStateMachine in a bit of sample code to sort of take it out for a test drive. First off, I'm happy to say it does what it is meant to do: I'm able to establish states and move from one state to another and have the appropriate methods called at the right times.I'd like to mention the difficulties I have had in the process:1. The terminology of GKStateMachine seems confused when it comes to a state. Sometimes a state seems to be an instance and sometimes it seems to be a class. For example, in this property and the init method what is referred to as a state is an instance of GKState. var currentState: GKState? { get } init(states: [GKState])Whereas for these two methods, state refers to a class: func canEnterState(stateClass: AnyClass) -> Bool func enterState(stateClass: AnyClass) -> BoolOf course, the parameter name is an indication that a class is wanted, but when calling these, the parameter name is not specified (nor should it be).The confusion reaches its apex with this m
3
0
1.9k
Jun ’15
Handle object inaccessible exceptions with core data
Core Data has this nasty habit of object inaccessible exceptions if a relationship is missing. This is an area that iOS 9 and OS X 10.11 are going to fix (yay!), but for the reality of today what are the ways most of you guys handle this issue? In ObjC we just use a @try/catch which works well for this situation (we call it on specific relationship calls). Since no such thing exists in Swift…do you just make it an ObjC call?
0
0
170
Jun ’15
one to many relationship
I am trying to get my head around a problem involving a one to many relationship. I'm not sure that my approach to this design is a good one.I have two entities, address and rooms. An address can have many rooms. I have set up a one to many relationship between the address table and room table. The problem is differentiating the Living Room of address 1 from the Living Room of address 2. Currently when I call NSManagedObject, the table rows are displaying all the rooms regardless of the address being chosen. I am not sure how to uniquely identify a room with an address.Sorry this is so vague, but I'm pretty new to core data, and I'm not even sure if my approach is a valid one. Any help to get me pointe in the right direction would be greatly appreciated.
2
0
349
Jun ’15
Reply to one to many relationship
Typically you have the rooms specified to contain a to-one relationship address which is the inverse of that to-many relationship rooms.That's the simplest way of differentiating the living room of addressX from the living room of address Y.And that lets you do all sorts of convenient things like select an address from your list of addresses; pass that reference to another table view controller, and have it specify a predicate for your fetch request so that it filters to just that address: // Given address as the user selected Address instance NSPredicate *predicate = [NSPredicate predicateWithFormat @address = %@, address];
Jun ’15
Using .sks files with custom classes as reference nodes?
What is the proper way to do this? For example: I have two .sks files that both have a custom class associated with them. If I include a reference node on one of them and link that reference node to the other .sks file and run the project I experience a crash.Attemped to add a SKNode which already has a parent: <SKSpriteNode> name:'SKSpriteNode_0' texture:['nil'] position:{596.5, 412.5} scale:{1.00, 1.00} size:{100, 100} anchor:{0.5, 0.5} rotation:0.00The reference node works without custom classes. I am also unsure whether I should be inheriting from SKScene, or SKNode in my custom classes. Doing either seems to cause a crash. If I inherit from SKNode I get the above message. If SKScene I get an error about adding a physics world to one that already exists, which makes sense.
Replies
2
Boosts
0
Views
921
Activity
Jun ’15
Do Generics not inherit initializers?
Four classes, first two normal, Two inherits from One, Two inherits One's initializers as expected.Second two are generic, Four<T> inherits from Three<T>, but everything else is the same. However Four doesn't inherit Three's initializer.Is that a bug or have I missed yet something else in the Swift book?public class One { public var value : Int public init( value : Int ) { self.value = value } } public class Two : One { public func foo() { print( value is (value) ) } } public class Three<T> { public var value : T public init( value : T ) { self.value = value } } public class Four<T> : Three<T> { public func foo() { print( value is (value) ) } } let x = Two( value : 123 ) // *** WORKS ****, Two inherits One's init(value:) method x.foo() let y = Four<Int>( value : 123 ) // Four<Int>' cannot be constructed because it has no accessible initializers y.foo()
Replies
0
Boosts
0
Views
981
Activity
Jun ’15
New behavior for `Create NSManagedObject Subclass…` bug?
With Xcode 7, two different files are created when you choose to `Create NSManagedObject Subclass`. One file is an extension that adds the properties that are added in the model editor. You aren't supposed to edit this file. Instead you edit the second file, the class file, that's created. This is where you add any custom functionality you want your NSManagedObject subclass to have. The point of this, as far as I can tell, is so that you can add your custom functionality, but when you later change the model, you can regenerate a new extension with the updated attributes/relationships without affecting or overwriting the custom code that you wrote.But...Xcode 7 beta 1 isn't doing this. Selecting `Create NSManagedObject Subclass` blows away both files. Is this a bug or am I missing something?Erik
Replies
1
Boosts
0
Views
423
Activity
Jun ’15
Reply to How do I customize the tint color in SFSafariViewController?
Setting the tint color is not supported in seed 1, but it’s coming soon. Note that SFSafariViewController will not inherit your app’s tint color. You’ll need to set the property on the SFSafariViewController’s view prior to presenting it.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’15
TIFF subviews
I've inherited an application that must read and process about 4000 multi-page tiff images. I'm not an image expert, and I'd love to utilize UIImage to view these, but it would appear that UIImage is ignoring any additional subviews in the tiff file. It will correctly report and display the first image.I was originally optimistic that I could utilize the images property, but since these are not animated images, this property returns nil. I'm able to verify that my images have multiple pages (subviews) utliizing SwiftView.if let img = UIImage(named: multipageTiff) { if let images = img.images as? [UIImage] { println(images (images.count)) } else { println(images is nil) } image = imgThe above code works great at assigning the original image to an UIImageView (image), however the println returns nil, so I'm stuck. Any suggestions would be greatly appreciated.Thanks!
Replies
3
Boosts
0
Views
807
Activity
Jun ’15
Protocol Extension Collision Question
Hi,If I have a struct that conforms to two protocols with the same method - that's fine. If both protocols implement the method in their extension then there is, of course, a problem. In other words, I expect the following to have issues because Thing can't decide which implementation of doThis() it supports. This is the classic diamond problem with multiple inheritance.=====protocol OneDoThisable { func doThis()}protocol TwoDoThisable { func doThis()}extension OneDoThisable { func doThis() { print(One's implementation) }}extension TwoDoThisable { func doThis() { print(Two's implementation) }}struct Thing: OneDoThisable, TwoDoThisable {}let thing = Thing()thing.doThis()=====What I'm asking is how could I disambiguate. I'd like to do something like this.====struct Thing: OneDoThisable, TwoDoThisable { func doThis() { (self as OneDoThisable).doThis() }}====In my own code I can just change the name of one of the methods. In case of two library protocols colliding... I can't always avoid such a collision
Replies
2
Boosts
0
Views
1.6k
Activity
Jun ’15
Swift Core Data Relationship to Same Entity
Hello,i'm new to Swift Programming and I'm struggling with Core Data a bit.My Data Model looks like the following:I have Items with multiple values like id, name, description, etc... nothing special, BUT Items can have parts that they are made of.For example:Item1ID: 1Name: OneParts: Subitem1ID:2Name: SubOneSubitem2ID: 3Name: SubTwoParts: Subsub1ID:4Name: SububTwoItem2ID: 5The setup in the xcdatamodelc is fairly simple, but i don't actually know how to fill it with data and save it.The data comes from a mysql database (there is a column isPartOf which specifies the parent-child relationship).I haven't found any resource on google which is addressing a similar setup, can anyone help me with my problem or knows Links/Books with information that can help me?Thank you
Replies
0
Boosts
0
Views
523
Activity
Jun ’15
How does one instantiate a generics-supported UIViewController subclass?
How does one instantiate a generics-supported UIViewController subclass?For example, consider a class likeclass SpecialViewController<T: UIView> : UIViewController{ }Interface Builder does not seem to handle these (in neither Storyboards nor simple .xibs)Furthermore, the default initializers seem to no longer be inherited (init, init(withNibName: String, bundle: ...), and even init(style: UITableViewStyle) for UITableViewController subclasses)Are there any known workarounds?
Replies
3
Boosts
0
Views
2.4k
Activity
Jun ’15
How to expose pure Swift classes to Objective-C correctly?
Consider this:MyFile.swift:@objc class SomeGuy { }MyClass.m:#import MyApp-Swift.h @interface SomeClass @end @implementation SomeClass - (void)someMethod { SomeGuy *someGuy = [[SomeGuy alloc] init]; } @endIn other words: have a pure Swift class annotated with @objc so it’s visible to Objective-C code. In Objective-C code, try to instantiate that class.If you were to run the above, you’d get compiler error: “no known class method for selector 'alloc'”One way to fix this would be to make SomeGuy inherit from NSObject. But I don’t want to do that, since I feel it adds too much cruft, the class isn’t really inheriting from NSObject by its nature, it is a pure swift class.Another way to fix: over on the Objective-C side, have a category:@interface SomeGuy (Dummy) + (instancetype)alloc; @endThis works and feels less weird, but still weird. It feels that the Swift-to-ObjC should autogenerate the alloc declaration for me in this case, since if I just add this category interface, everything works corr
Replies
0
Boosts
0
Views
1.5k
Activity
Jun ’15
How do I know which Foundation classes implement custom isEqual and not just inherit NSObject implementation?
For example, how can I be sure that UILocalNotification isEqual: result is not just result of comparing them by memory address?Should I rely on assumption that every class has custom isEqual implementation? Or should I treat every class like a not supporting isEqual if they don't have special description about isEqual in documentation?
Replies
4
Boosts
0
Views
435
Activity
Jun ’15
GKStateMachine: confusing terminology; feels kind of 'heavy'
Hello,I've been using the GKStateMachine in a bit of sample code to sort of take it out for a test drive. First off, I'm happy to say it does what it is meant to do: I'm able to establish states and move from one state to another and have the appropriate methods called at the right times.I'd like to mention the difficulties I have had in the process:1. The terminology of GKStateMachine seems confused when it comes to a state. Sometimes a state seems to be an instance and sometimes it seems to be a class. For example, in this property and the init method what is referred to as a state is an instance of GKState. var currentState: GKState? { get } init(states: [GKState])Whereas for these two methods, state refers to a class: func canEnterState(stateClass: AnyClass) -> Bool func enterState(stateClass: AnyClass) -> BoolOf course, the parameter name is an indication that a class is wanted, but when calling these, the parameter name is not specified (nor should it be).The confusion reaches its apex with this m
Replies
3
Boosts
0
Views
1.9k
Activity
Jun ’15
Handle object inaccessible exceptions with core data
Core Data has this nasty habit of object inaccessible exceptions if a relationship is missing. This is an area that iOS 9 and OS X 10.11 are going to fix (yay!), but for the reality of today what are the ways most of you guys handle this issue? In ObjC we just use a @try/catch which works well for this situation (we call it on specific relationship calls). Since no such thing exists in Swift…do you just make it an ObjC call?
Replies
0
Boosts
0
Views
170
Activity
Jun ’15
one to many relationship
I am trying to get my head around a problem involving a one to many relationship. I'm not sure that my approach to this design is a good one.I have two entities, address and rooms. An address can have many rooms. I have set up a one to many relationship between the address table and room table. The problem is differentiating the Living Room of address 1 from the Living Room of address 2. Currently when I call NSManagedObject, the table rows are displaying all the rooms regardless of the address being chosen. I am not sure how to uniquely identify a room with an address.Sorry this is so vague, but I'm pretty new to core data, and I'm not even sure if my approach is a valid one. Any help to get me pointe in the right direction would be greatly appreciated.
Replies
2
Boosts
0
Views
349
Activity
Jun ’15
Reply to one to many relationship
Typically you have the rooms specified to contain a to-one relationship address which is the inverse of that to-many relationship rooms.That's the simplest way of differentiating the living room of addressX from the living room of address Y.And that lets you do all sorts of convenient things like select an address from your list of addresses; pass that reference to another table view controller, and have it specify a predicate for your fetch request so that it filters to just that address: // Given address as the user selected Address instance NSPredicate *predicate = [NSPredicate predicateWithFormat @address = %@, address];
Replies
Boosts
Views
Activity
Jun ’15
Reply to Covariant and contravariant generic type parameters
Well, variance for generic type parameters is about the interaction of generic types and subtyping relationships. For example, covariance is what allows you to store a Dog in an array defined to store Animals for example.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15