Search results for

“SwiftData inheritance relationship”

4,986 results found

Post

Replies

Boosts

Views

Activity

Reply to AppleScript: Error -1728 "Messages got an error: Can’t get service of item 1 of every text chat."
hmmm... Actually text chat should inherit properties from chat anyway - whether it should also inherit responses too, I'm not sure. Your script works on my 10.10.4 - but you already know that...But where text chat is identified by name, chat is identified by id. What does:tell application Messages to accept item 1 in chatsandtell application Messages to return connection status of service of item 1 in chatsyield?
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’15
Reply to can core data be used with cloud kit/document storage?
I believe your question was to NotMyName. In anycase I find cloudkit confusing so wanna avoid that as much as possible. Its sad that cd with icloud has been avaialbel for so long and apple hasnt fixed the most fundamental aspect of its working, over the years! So here I am, a first time developer on my debut project, and i have learnt and ser up everything but cant test it (let alone ship it) cause of the problems. Like i said, the valaidation errors of non optional relationships being nil after deletinng a record happens only when importing changes to another peer. When i use the local store (without icloud) these exceptions arent thrown.
Jul ’15
Reply to Abstract methods and protocol extensions
While you can require a conforming type to have a particular property, you can't actually declare and allocate storage for that property just by conforming to a protocol, while you can do that by inheriting from a class.Let me explain what I mean. I have a protocol that creates a linked list of handlers:protocol HandlerType: class { var nextHandler: HandlerType? { get set } func handleThing(thing: Thing) } extension HandlerType { func insertHandler(handler: HandlerType) { handler.lastHandler.nextHandler = self.nextHandler self.nextHandler = handler } var lastHandler: HandlerType { return nextHandler?.lastHandler ?? self } }There's nothing about nextHandler's behavior that needs be customized by any HandlerType. It should always be a stored property, be gettable by anybody but set only by the insertHandler(_:) method, should not have property observers, and should never be customized by the handler in any way. Managing nextHandler is rightly HandlerType's responsibility. But when I go to implement a c
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to protocol extensions - default implementations vs. helper methods
I think we need to realize that the people who work on Swift understand that, while inheritance and protocol implementation can't solve the model of self-as-many-things, they can't divulge that they're solving that problem, and that they're giving us band-aids via protocols in the meantime. It's not worth their time to get this right, if it's going to be disallowed in a year.If that doesn't make sense, a basic problem that Swift doesn't solve yet is that an object, to be able to model reality, must be able to call different code, with the same method signature. But when doing so, it must be clear which. Casting doesn't model the problem correctly. Delegates and other helper objects don't model the problem correctly. We're moving towards a place where segmentation of functionality will allow these methods, but we don't have syntax for it yet. Protocols, and this as-yet-unnamed concept, are stepping on each others' toes in the meantime.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
NSFetchedResults Returning Old Data After Saving the Persistent MOC
## ContextI've a simple Core Data stack: `MainQueueMOC -> PrivateBackgroundMOC -> PersistentStoreCoordinator` that is managed by my `TTPersistenceManager` that looks like this:typedef NS_ENUM(NSInteger, TTPersistenceType) { TTPersistenceTypeInMemory, TTPersistenceTypeSQLite }; @interface TTPersistenceManager : NSObject @property (strong, nonatomic, readonly) NSManagedObjectContext *managedObjectContext; // this is the MainQueueMOC - (id)initWithPersistenceType:(TTPersistenceType)persistenceType; - (void)initializeCoreData; - (void)save; - (void)persist;Currently we only use the in memory store.It is inspired by this article from Marcus Zarra. So the MainQueueMOC is the single source of truth, and the PrivateBackgroundMOC is only used to save to the store in background, and it is never publicly exposed. If you read the article you'll notice that I added a method called `persist`, the difference between `save` and `persist` is:- `save`, saves the MainQueueMOC using `performBlockAndWait`- `persist`, saves
0
0
181
Jul ’15
Reply to Cannot invoke 'self()' in beta 2
I'm seeing the same problem with your code in Xcode 7 beta 3.(You need to explictly include .init now, so you would have self.init() but that just gets you the similar error that init can't be invoked without arguments.)It seems that the version of init() inherited from NSObject isn't being recognized when using .init() on a reference to a metatype.This is probably a bug in the Swift compiler, since it seems to be applying the rules for Swift initializer inheritance to a class that has been imported from objC, when accessing it through a dynamic type object (like self in a type method, or a variable holding a metatype).It recognizes the designated initializers inherited from UIView (which could be automatically inherited due to the rules for Swift initializer inheritance), but not designated initializers from ancestors past that point (which would be hidden in a Swift class after UIView declared it's own designated initializers).As a workaround, you might be able t
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to Proper Way to Identify Bluetooth Peripheral
The correct solution now is to use the NSUUID *identifier on CBPeripheral objects.The identifier property is now moved to the CBPeer object, but as CBPeripheral is an object of type CBPeer, the NSUUID *identifier property is available to your CBPeripheral objects.What the documentation says is technically correct, albeit confusing. The property is indeed deprecated as a direct property, even though it is still available through inheritance.
Jul ’15
OS X Storyboard Window Content View Controller is nil
Can someone tell me why this is happening?I have converted an OS X app to use Storyboards. Some of my NSViewControllers have an associated NSWindowController. I created a 'window content' relationship from the Window Controller to the View Controller. I create a segue to the Window Controller. In prepareForSegue, I get the destination controller, which is the window controller, but I really want the contentViewController. However, the issue is that the contentViewController is nil. I want to do something like the following.NSWindowController *wc = [segue destinationController];MyViewController *mvc = (MyViewController *)wc.window.contentViewController;But looking at wc in the debugger, its contentViewController is nil.
3
0
2.1k
Jul ’15
CoreData on watchOS 2 from 1
In watchOS 1, I have access to my core data file and can load the database on the watch. This is great becasue it has all of the data I use in the app and I can update it from the watch and its automatically on the phone. In watchOS 2, I heard that this is not allowed now. My app is a TV Show tracker, and it seems hard to be able to make a watch app/glance/complication without access to my entire database. The main reason I would like to continue having access to my database is because of the relationships. I have to display the show data, and episode data and I need to know which episode belongs to which shows. It would seem like a pain to transfer over core data and have a separate smaller database on the watch. Also when a episode is marked as watched I need to check for the next episode to be able to make the relationship.What would be the best alternative or easiest way to provide the same functionalities on my watchOS 2 app from my watchOS 1 app? Should I just remove these functionalities and o
0
0
325
Jul ’15
Compiler Crash: Must be my Type Specification
protocol Identifies : Hashable {} // Something is Identifiable if it has an Identifier protocol Identifiable : Hashable { typealias Identifier : Identifies var identifier : Identifier { get } } extension String : Identifies {} class Person : Identifiable { var identifier : String = avoid init for now } protocol Service { typealias Object : Identifiable func lookup (id : Object.Identifier) -> Object? } class PersonService <P:Person> : Service { // crashes here... func lookup(id: P.Identifier) -> P? { return nil } }The crash is avoidable withP:Person where P:IdentifiableWhy?Also, assume I want to avoid all type inferencing of the protocol typealiases. How would I modify the code to be as explicit as possible regarding type relationships?
0
0
223
Jul ’15
Protocol extension methods not inherited?
I find this very surprising:protocol State { func enterState () func test () } extension State { func enterState () { print (State) } func test () { enterState () } } class State0: State { } class State1: State0 { func enterState () { print (State1) } } let x = State1 () x.enterState () // prints State1 x.test () // prints StateNotice that in that last line, in method 'test' an object of class State1 invokes State.enterState (), not self.enterState (). Is this intentional or a bug?The current documentation saysIf 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.To my mind, 'State1' is a conforming type, and it does provide its own implementation of 'enterState', but that implementation isn't being used.
1
0
615
Jul ’15
Creating a xib based custom control in swift
Hello, I was wondering if it was possible to create a swift based iOS control, say a UserInformation control, that would use a xib and inherit UIView or UIControl I want to use a xib to setup the constraints of the custom control, and ultimately be able to drop the control onto my main storyboard with @IBDesignable working. Every example I've seen created the custom control via code. I really didn't want to go through the pain of creating a control and constraints manually if I could do it with a xib. Let me know if this is possible in Swift.Thanks.
1
0
285
Jul ’15
Reply to Heterogeneous Constraints with Protocols
Just be aware that this kind of equality test recreates a flaw in objc equality testing, and is very fragile and problematic in one of the ways that Swift was intended to fix.It only works dependably if all types which conform to the protocol are value-types, and can give false positives if the two Drawable instances involved have types that are parent and subclass.For example (in a playground in Xcode 7 beta 3):protocol Place { var size: CGSize {get} func isEqualToPlace(place: Place) -> Bool } extension Place where Self: Equatable { func isEqualToPlace(place: Place) -> Bool { guard let other = place as? Self else { return false } return self == other } } class EmptyLot: Equatable, Place { var size: CGSize = CGSize(width: 10, height: 10) } func == (lhs: EmptyLot, rhs: EmptyLot) -> Bool {return lhs.size == rhs.size} class Minefield: EmptyLot { var hasMines: Bool = true } func == (lhs: Minefield, rhs: Minefield) -> Bool {return (lhs.size == rhs.size) && (lhs.hasMines == rhs.hasMines)} let x
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Use of Inherited Protocol as Typealias
In the following code example, I get a does not conform to protocol on MyStruct.protocol OutsideProtocol { typealias T: InsideProtocol } protocol InsideProtocol { } protocol InheritingProtocol: InsideProtocol { } struct MyStruct: OutsideProtocol { typealias T = InheritingProtocol }This would compile if InheritingProtocol were a struct or class. Is this a known limitation and is there a workaround?
1
0
433
Jul ’15
Reply to Protocol extension dispatch anomalies
I dunno, but it looks like it might be the same thing as this:https://forums.developer.apple.com/thread/11126Specifically, there's something like inheritance that's supposed to be going on here, but it isn't like any kind of inheritance that we know elsewhere in the language. It may be a bug, or it may be a limitation.My example was reported as bug #21885544, if you're inclined to report yours as a duplicate.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to AppleScript: Error -1728 "Messages got an error: Can’t get service of item 1 of every text chat."
hmmm... Actually text chat should inherit properties from chat anyway - whether it should also inherit responses too, I'm not sure. Your script works on my 10.10.4 - but you already know that...But where text chat is identified by name, chat is identified by id. What does:tell application Messages to accept item 1 in chatsandtell application Messages to return connection status of service of item 1 in chatsyield?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to can core data be used with cloud kit/document storage?
I believe your question was to NotMyName. In anycase I find cloudkit confusing so wanna avoid that as much as possible. Its sad that cd with icloud has been avaialbel for so long and apple hasnt fixed the most fundamental aspect of its working, over the years! So here I am, a first time developer on my debut project, and i have learnt and ser up everything but cant test it (let alone ship it) cause of the problems. Like i said, the valaidation errors of non optional relationships being nil after deletinng a record happens only when importing changes to another peer. When i use the local store (without icloud) these exceptions arent thrown.
Replies
Boosts
Views
Activity
Jul ’15
Reply to Abstract methods and protocol extensions
While you can require a conforming type to have a particular property, you can't actually declare and allocate storage for that property just by conforming to a protocol, while you can do that by inheriting from a class.Let me explain what I mean. I have a protocol that creates a linked list of handlers:protocol HandlerType: class { var nextHandler: HandlerType? { get set } func handleThing(thing: Thing) } extension HandlerType { func insertHandler(handler: HandlerType) { handler.lastHandler.nextHandler = self.nextHandler self.nextHandler = handler } var lastHandler: HandlerType { return nextHandler?.lastHandler ?? self } }There's nothing about nextHandler's behavior that needs be customized by any HandlerType. It should always be a stored property, be gettable by anybody but set only by the insertHandler(_:) method, should not have property observers, and should never be customized by the handler in any way. Managing nextHandler is rightly HandlerType's responsibility. But when I go to implement a c
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to protocol extensions - default implementations vs. helper methods
I think we need to realize that the people who work on Swift understand that, while inheritance and protocol implementation can't solve the model of self-as-many-things, they can't divulge that they're solving that problem, and that they're giving us band-aids via protocols in the meantime. It's not worth their time to get this right, if it's going to be disallowed in a year.If that doesn't make sense, a basic problem that Swift doesn't solve yet is that an object, to be able to model reality, must be able to call different code, with the same method signature. But when doing so, it must be clear which. Casting doesn't model the problem correctly. Delegates and other helper objects don't model the problem correctly. We're moving towards a place where segmentation of functionality will allow these methods, but we don't have syntax for it yet. Protocols, and this as-yet-unnamed concept, are stepping on each others' toes in the meantime.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
NSFetchedResults Returning Old Data After Saving the Persistent MOC
## ContextI've a simple Core Data stack: `MainQueueMOC -> PrivateBackgroundMOC -> PersistentStoreCoordinator` that is managed by my `TTPersistenceManager` that looks like this:typedef NS_ENUM(NSInteger, TTPersistenceType) { TTPersistenceTypeInMemory, TTPersistenceTypeSQLite }; @interface TTPersistenceManager : NSObject @property (strong, nonatomic, readonly) NSManagedObjectContext *managedObjectContext; // this is the MainQueueMOC - (id)initWithPersistenceType:(TTPersistenceType)persistenceType; - (void)initializeCoreData; - (void)save; - (void)persist;Currently we only use the in memory store.It is inspired by this article from Marcus Zarra. So the MainQueueMOC is the single source of truth, and the PrivateBackgroundMOC is only used to save to the store in background, and it is never publicly exposed. If you read the article you'll notice that I added a method called `persist`, the difference between `save` and `persist` is:- `save`, saves the MainQueueMOC using `performBlockAndWait`- `persist`, saves
Replies
0
Boosts
0
Views
181
Activity
Jul ’15
Reply to Cannot invoke 'self()' in beta 2
I'm seeing the same problem with your code in Xcode 7 beta 3.(You need to explictly include .init now, so you would have self.init() but that just gets you the similar error that init can't be invoked without arguments.)It seems that the version of init() inherited from NSObject isn't being recognized when using .init() on a reference to a metatype.This is probably a bug in the Swift compiler, since it seems to be applying the rules for Swift initializer inheritance to a class that has been imported from objC, when accessing it through a dynamic type object (like self in a type method, or a variable holding a metatype).It recognizes the designated initializers inherited from UIView (which could be automatically inherited due to the rules for Swift initializer inheritance), but not designated initializers from ancestors past that point (which would be hidden in a Swift class after UIView declared it's own designated initializers).As a workaround, you might be able t
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to Proper Way to Identify Bluetooth Peripheral
The correct solution now is to use the NSUUID *identifier on CBPeripheral objects.The identifier property is now moved to the CBPeer object, but as CBPeripheral is an object of type CBPeer, the NSUUID *identifier property is available to your CBPeripheral objects.What the documentation says is technically correct, albeit confusing. The property is indeed deprecated as a direct property, even though it is still available through inheritance.
Replies
Boosts
Views
Activity
Jul ’15
OS X Storyboard Window Content View Controller is nil
Can someone tell me why this is happening?I have converted an OS X app to use Storyboards. Some of my NSViewControllers have an associated NSWindowController. I created a 'window content' relationship from the Window Controller to the View Controller. I create a segue to the Window Controller. In prepareForSegue, I get the destination controller, which is the window controller, but I really want the contentViewController. However, the issue is that the contentViewController is nil. I want to do something like the following.NSWindowController *wc = [segue destinationController];MyViewController *mvc = (MyViewController *)wc.window.contentViewController;But looking at wc in the debugger, its contentViewController is nil.
Replies
3
Boosts
0
Views
2.1k
Activity
Jul ’15
CoreData on watchOS 2 from 1
In watchOS 1, I have access to my core data file and can load the database on the watch. This is great becasue it has all of the data I use in the app and I can update it from the watch and its automatically on the phone. In watchOS 2, I heard that this is not allowed now. My app is a TV Show tracker, and it seems hard to be able to make a watch app/glance/complication without access to my entire database. The main reason I would like to continue having access to my database is because of the relationships. I have to display the show data, and episode data and I need to know which episode belongs to which shows. It would seem like a pain to transfer over core data and have a separate smaller database on the watch. Also when a episode is marked as watched I need to check for the next episode to be able to make the relationship.What would be the best alternative or easiest way to provide the same functionalities on my watchOS 2 app from my watchOS 1 app? Should I just remove these functionalities and o
Replies
0
Boosts
0
Views
325
Activity
Jul ’15
Compiler Crash: Must be my Type Specification
protocol Identifies : Hashable {} // Something is Identifiable if it has an Identifier protocol Identifiable : Hashable { typealias Identifier : Identifies var identifier : Identifier { get } } extension String : Identifies {} class Person : Identifiable { var identifier : String = avoid init for now } protocol Service { typealias Object : Identifiable func lookup (id : Object.Identifier) -> Object? } class PersonService <P:Person> : Service { // crashes here... func lookup(id: P.Identifier) -> P? { return nil } }The crash is avoidable withP:Person where P:IdentifiableWhy?Also, assume I want to avoid all type inferencing of the protocol typealiases. How would I modify the code to be as explicit as possible regarding type relationships?
Replies
0
Boosts
0
Views
223
Activity
Jul ’15
Protocol extension methods not inherited?
I find this very surprising:protocol State { func enterState () func test () } extension State { func enterState () { print (State) } func test () { enterState () } } class State0: State { } class State1: State0 { func enterState () { print (State1) } } let x = State1 () x.enterState () // prints State1 x.test () // prints StateNotice that in that last line, in method 'test' an object of class State1 invokes State.enterState (), not self.enterState (). Is this intentional or a bug?The current documentation saysIf 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.To my mind, 'State1' is a conforming type, and it does provide its own implementation of 'enterState', but that implementation isn't being used.
Replies
1
Boosts
0
Views
615
Activity
Jul ’15
Creating a xib based custom control in swift
Hello, I was wondering if it was possible to create a swift based iOS control, say a UserInformation control, that would use a xib and inherit UIView or UIControl I want to use a xib to setup the constraints of the custom control, and ultimately be able to drop the control onto my main storyboard with @IBDesignable working. Every example I've seen created the custom control via code. I really didn't want to go through the pain of creating a control and constraints manually if I could do it with a xib. Let me know if this is possible in Swift.Thanks.
Replies
1
Boosts
0
Views
285
Activity
Jul ’15
Reply to Heterogeneous Constraints with Protocols
Just be aware that this kind of equality test recreates a flaw in objc equality testing, and is very fragile and problematic in one of the ways that Swift was intended to fix.It only works dependably if all types which conform to the protocol are value-types, and can give false positives if the two Drawable instances involved have types that are parent and subclass.For example (in a playground in Xcode 7 beta 3):protocol Place { var size: CGSize {get} func isEqualToPlace(place: Place) -> Bool } extension Place where Self: Equatable { func isEqualToPlace(place: Place) -> Bool { guard let other = place as? Self else { return false } return self == other } } class EmptyLot: Equatable, Place { var size: CGSize = CGSize(width: 10, height: 10) } func == (lhs: EmptyLot, rhs: EmptyLot) -> Bool {return lhs.size == rhs.size} class Minefield: EmptyLot { var hasMines: Bool = true } func == (lhs: Minefield, rhs: Minefield) -> Bool {return (lhs.size == rhs.size) && (lhs.hasMines == rhs.hasMines)} let x
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Use of Inherited Protocol as Typealias
In the following code example, I get a does not conform to protocol on MyStruct.protocol OutsideProtocol { typealias T: InsideProtocol } protocol InsideProtocol { } protocol InheritingProtocol: InsideProtocol { } struct MyStruct: OutsideProtocol { typealias T = InheritingProtocol }This would compile if InheritingProtocol were a struct or class. Is this a known limitation and is there a workaround?
Replies
1
Boosts
0
Views
433
Activity
Jul ’15
Reply to Protocol extension dispatch anomalies
I dunno, but it looks like it might be the same thing as this:https://forums.developer.apple.com/thread/11126Specifically, there's something like inheritance that's supposed to be going on here, but it isn't like any kind of inheritance that we know elsewhere in the language. It may be a bug, or it may be a limitation.My example was reported as bug #21885544, if you're inclined to report yours as a duplicate.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15