Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

NSFetchedResultsController SUBQUERY no such column
I am having issues with subqueries in the predicate for the fetch request of an NSFetchResultsController. Basically the object I'm fetching on has a to-One relationship that has a to-Many relationship that I am performing the subquery on, so it looks like this Target <<--> Person <<-->> ExtendedProperty. I am fetching all targets that have a specific name/value in the extendedProperty of the target's person.Here is what my predicate looks likerequest.predicate = NSPredicate(format: SUBQUERY(person.extendedProperties, $extProp, $extProp.name == %@ && $extProp.value == %@).@count > 0, favorite color, red)When I try to use this I don't get any results and the console outputs2015-09-08 17:33:26.206 CoreDataBug[2019:313174] CoreData: error: (1) I/O error for database at /var/mobile/Containers/Data/Application/EAFFE09B-D259-4917-A13F-2D46D0D81816/Documents/CoreDataBug.sqlite. SQLite error code:1, 'no such column: t2.ZNAME'I'm trying to figure out if I'm doing someth
4
0
899
Sep ’15
Reply to Get substring from String / string slicing?
>> Why would the standard library not include something simpler like this?Of course, I don't know, but I have a possible explanation that I replay to myself whenever I start cursing at String's awkward syntax.The explanation is historical. The class NSString is jam-packed with useful functionality, but it's always been weird that the cananical underlying data representation is UTF-16. UTF-16 is fine, but there's plenty of stuff stored as UTF-8, and even now plenty of sources of pure 8-bit character arrays. This means that there are are lots of actual data conversions to and from UTF-16. (At the time NSString adopted UTF-16, around 1990, the text world was quite different. At that time, it looked like 16-bit units for text would obviously win over 8-bit units — wchar clobbers char, photos at 11!. UTF-16 seemed like the forward-looking option, and UTF-8 looked like a compatibibility footnote. Obviously, that's not what happened.)In practice, concrete subclasses of NSString may actually store data in forms
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’15
Multiple PersistentStoreCoordinator
Hi folks, here is my problem:App DetailI have a sample app where a store create & pack some boxes and then send it to the warehouseCoreData ModelLet's say my core data model has only 2 entities, Box and BoxItem with a relationship between the 2 (one to many)App viewsLet's say there is only 2 views, a view for displaying all the boxes and a view for displaying the box itself (it's items)Views:Boxes View (UITableViewController with a pull to refresh)Box Items (UITableViewController, insert, change, delete article with 2 operations save the box or cancel to go back to boxes view)Business RequirementThe business requirement is to be able to work offline, there come the complexityI have created a third entity, OfflineRequest, everytime the user save a box and we are offline, I will prepare a request and add it to this entityI used the reachability API to know when the WIFI is on / off, as soon as I get the notification I will fetch this entity and if it's not empty I will send the request to the serve
2
0
379
Sep ’15
Changes to Equatable in Swift 2 for NSObject-derived subclasses
Prior to Swift 2, a Swift class inheriting from NSObject could extend Equatable and provide its own == implementation. Swift 2, however, gives a compiler error on the Equatable conformance, since NSObject seems to provide its own implementation.However, my == implementations for NSObject-derived classes no longer work because of this change - they're simply ignored in favor of the isEqual: method in NSObject.Here's an example:class TestObject: NSObject { let a: Int init(a: Int) { self.a = a super.init() } } func ==(lhs: TestObject, rhs: TestObject) -> Bool { print(calling equatable) return lhs.a == rhs.a }class EquatableTestTests: XCTestCase { func testExample() { let a = TestObject(a: 4) let b = TestObject(a: 4) let isEqual = a == b XCTAssert(isEqual) XCTAssertEqual(a, b) } }The first assert works, because I'm directly calling the == operator, but the second one fails, because the == operator that TestObject inherits from NSObject calls NSObject#isEqual:Swift classes that don't inherit
1
0
1.2k
Sep ’15
How to implement and use a search-tokens object in Core Data?
In WWDC 2013 Session 211 Core Data Performance Optimization and Debuggingpages 128-131 discuss using a canonicalized search in Core Data. So I am attempting to configure my Core Data model to support this method of searching. I've created a Tokens object with a token attribute of type String (?? Considering whether changing this to type transformable to support saving a string as an Array would be better ??). I also create a relationship between the Tokens object and the base entity on my data model. From the talk, it's not precisely clear how one would use this setup. So for example, I know that I probably want to use an inexpensive query against the Tokens entity with an operator like BEGINSWITH but would ANY and other operators be too costly to use?Also I can't find any sample projects showing how to implement the search-token algorithm. So, it's a bit unclear if I should have one word in each token or if I have a string in each token attribute then it's not entirely clear how to parse that effici
2
0
912
Sep ’15
Reply to Protocols, abstraction, and types
Sure, but this avoids the problem by further specializing the protocol. On the most basic level, I just want the protocol to define the relationships. Ideally, I could create any number of variations on TypeB that add different kind of specialization, without breaking the relationship between TypeA and TypeB.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’15
Reply to Protocols, abstraction, and types
I'm not sure what you mean. Protocols are not superclasses. Protocols dictate a set of things that can be guaranteed about any type that conforms to them.So if your protocol is empty, then it doesn't require anything from types that conform to it. And the only thing the compiler can know about all the types that conforms to it is that they conform to it, nothing more. So It can't know of any methods or properties or typealiases of that type, unless it is looking at the concrete type and not the protocol, of course.The only thing it means for a (concrete) type to conform to a protocol is that it has to conform to it, it has to provide implementations for the methods, properties and typealiases that the protocol demands, or it will fail to conform.There's no inheritance or anything like that going on, a protocol and the types conforming to it cannot reach each other in any way. The protocol specifies an interface that the conforming types must have and thus are guaranteed to have, that's it.And a type
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’15
Reply to Protocols, abstraction, and types
Well, one of the proposals of the Protocol-Oriented Programming talk seemed to be suggesting that we could treat them (somewhat) synonymously to superclasses. Besides, I don't want these relationships to be limited to classes - I'd like the freedom to use structs, for example (as in my sample problem). (By the way, the fact that TypeB was empty wasn't intended to be significant.)
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’15
Reply to Protocols, abstraction, and types
I saw the Protocol-Oriented talk and I thought it was one of the best talks. I think protocols are great and I use them and value types for most things, sometimes a class is needed for the indirection / identity, but I almost never use class inheritance, so in that way I guess that you can say that using protocols can do away with super classes.However, I can't really understand how you see protocols, what they are and what expectations you have on them, and this makes it hard to explain what they are and what they are not. (I did try in my previous reply.)I would suggest that you read more about protocols and generics in the Swift book.One of the most important differences between Objective-C and Swift is that in Objective-C almost everything you do is done dynamically, while in Swift and especially when using protocols, you tend to not do dynamically what can be done statically, which means you will want to make the compiler know as much as possible about your types and your code, which is totally
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’15
Reply to Protocols, abstraction, and types
Well, I'm starting to think that I probably see protocols exactly as they are, but just hoped for some unforeseen magic!What I'd hoped to do was not necessarily to create superclasses, per se, but to create a set of relationships between objects (types, really). Specifically, I'm working on a VIPER variant for our new project, and I wanted to use protocols to specify the relationships between components in each module. This would be pure abstraction, in the sense that there would be no implementations at all, just relationships (so, perfect for protocols). For example, a Presenter might know that it has a FlowController, without knowing anything else about it. This would be implemented at the protocol level. The components would adopt these basic protocols, which would enforce a certain connectivity between components, but the objects conforming to the protocols (the actual implementations) would define their own functionality, given the particular module (use-case). I can't do this
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’15
Reply to Protocols, abstraction, and types
The point was to separate the architecture from its implementation. As far as compilation goes, I do explicitly pass sTypeA an instance of structTypeB, so I don't see it as being particularly ambiguous at compile time.As far as the empty TypeB goes, as I said before, this is just a mock example; it would likely have some more specific requirements (but that's beside the point).In the actual implementation I'm trying to figure out, TypeA might be an Interactor (i.e., in VIPER), and TypeB might be a Presenter. If I have two use-cases, like UserCreation and TaskCreation, say, then I would create a UserCreationInteractor: Interactor, and a UserCreationPresenter: Presenter. Thus the protocol would (at minimum) specify the relationship between UserCreationInteractor and UserCreationPresenter (i.e., fundamentally the same as Interactor to Presenter). Crucially, the actual implementation of UserCreationInteractor and TaskCreationInteractor would likely be quite different.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’15
Default viewDidLoad in protocol extension
I used to have a base class that inherited from UITableViewController and defined some defaults for the delegates, as well as a viewDidLoad default. I'm now trying to change that to be a protocol extension instead, so I did the following:protocol HeaderSectionRenderer { func coloredHeaderViewWithText(title: String, uppercase: Bool) -> UITableViewHeaderFooterView func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat } extension HeaderSectionRenderer where Self: UITableViewController { func coloredHeaderViewWithText(title: String, uppercase: Bool = false) -> UITableViewHeaderFooterView { ... } func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 25.0 } }That covers those two methods with a default implementation, but now I need to have a viewDidLoad. I tried the obvious: override func viewDidLoad() { super.viewDidLoad() tableView.registerClass(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier:
1
0
3.6k
Sep ’15
Tons of Problems w/ OS X GM Release 10.11
All:I'm experiencing a complete disaster for the first time ever with a GM release of OS X. 10.11 is a continuning nightmare. I don't know why the GM is so bad when all the prior betas seem to be just fine.1) The inital installation caused me to be unable to launch any applications. None. I've recovered from that using the usual profile recovery methods and inheriting the home folder, etc. However....2) I'm now unable to log in to *ANY* iCloud services. I thought this was due to the poorly implemented 2-factor authentication Apple is using (it's highly unreliable when dealing with app specific passwords) so I turned it off. I'm still unable to access iCloud services including messages, facetime, etc. Right now I'm thinking that my entire keychain has been hosed. The problems are so surreal I may never really be sure. Welcome to Windows 10 by Apple for the Mac!DM
3
0
347
Sep ’15
NSFetchedResultsController SUBQUERY no such column
I am having issues with subqueries in the predicate for the fetch request of an NSFetchResultsController. Basically the object I'm fetching on has a to-One relationship that has a to-Many relationship that I am performing the subquery on, so it looks like this Target <<--> Person <<-->> ExtendedProperty. I am fetching all targets that have a specific name/value in the extendedProperty of the target's person.Here is what my predicate looks likerequest.predicate = NSPredicate(format: SUBQUERY(person.extendedProperties, $extProp, $extProp.name == %@ && $extProp.value == %@).@count > 0, favorite color, red)When I try to use this I don't get any results and the console outputs2015-09-08 17:33:26.206 CoreDataBug[2019:313174] CoreData: error: (1) I/O error for database at /var/mobile/Containers/Data/Application/EAFFE09B-D259-4917-A13F-2D46D0D81816/Documents/CoreDataBug.sqlite. SQLite error code:1, 'no such column: t2.ZNAME'I'm trying to figure out if I'm doing someth
Replies
4
Boosts
0
Views
899
Activity
Sep ’15
Reply to Get substring from String / string slicing?
>> Why would the standard library not include something simpler like this?Of course, I don't know, but I have a possible explanation that I replay to myself whenever I start cursing at String's awkward syntax.The explanation is historical. The class NSString is jam-packed with useful functionality, but it's always been weird that the cananical underlying data representation is UTF-16. UTF-16 is fine, but there's plenty of stuff stored as UTF-8, and even now plenty of sources of pure 8-bit character arrays. This means that there are are lots of actual data conversions to and from UTF-16. (At the time NSString adopted UTF-16, around 1990, the text world was quite different. At that time, it looked like 16-bit units for text would obviously win over 8-bit units — wchar clobbers char, photos at 11!. UTF-16 seemed like the forward-looking option, and UTF-8 looked like a compatibibility footnote. Obviously, that's not what happened.)In practice, concrete subclasses of NSString may actually store data in forms
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’15
Reply to getting error with the client server walkthrough on the development guide
Thank you, I was wondering if it was an inherited property of something that I wasn't inheriting or what.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Sep ’15
No Metal support on AppleTV?
I see TVOS inherits from IOS OpenGL ES but see no word on Metal framework,,it's supported?
Replies
9
Boosts
0
Views
2.3k
Activity
Sep ’15
Multiple PersistentStoreCoordinator
Hi folks, here is my problem:App DetailI have a sample app where a store create & pack some boxes and then send it to the warehouseCoreData ModelLet's say my core data model has only 2 entities, Box and BoxItem with a relationship between the 2 (one to many)App viewsLet's say there is only 2 views, a view for displaying all the boxes and a view for displaying the box itself (it's items)Views:Boxes View (UITableViewController with a pull to refresh)Box Items (UITableViewController, insert, change, delete article with 2 operations save the box or cancel to go back to boxes view)Business RequirementThe business requirement is to be able to work offline, there come the complexityI have created a third entity, OfflineRequest, everytime the user save a box and we are offline, I will prepare a request and add it to this entityI used the reachability API to know when the WIFI is on / off, as soon as I get the notification I will fetch this entity and if it's not empty I will send the request to the serve
Replies
2
Boosts
0
Views
379
Activity
Sep ’15
Changes to Equatable in Swift 2 for NSObject-derived subclasses
Prior to Swift 2, a Swift class inheriting from NSObject could extend Equatable and provide its own == implementation. Swift 2, however, gives a compiler error on the Equatable conformance, since NSObject seems to provide its own implementation.However, my == implementations for NSObject-derived classes no longer work because of this change - they're simply ignored in favor of the isEqual: method in NSObject.Here's an example:class TestObject: NSObject { let a: Int init(a: Int) { self.a = a super.init() } } func ==(lhs: TestObject, rhs: TestObject) -> Bool { print(calling equatable) return lhs.a == rhs.a }class EquatableTestTests: XCTestCase { func testExample() { let a = TestObject(a: 4) let b = TestObject(a: 4) let isEqual = a == b XCTAssert(isEqual) XCTAssertEqual(a, b) } }The first assert works, because I'm directly calling the == operator, but the second one fails, because the == operator that TestObject inherits from NSObject calls NSObject#isEqual:Swift classes that don't inherit
Replies
1
Boosts
0
Views
1.2k
Activity
Sep ’15
How to implement and use a search-tokens object in Core Data?
In WWDC 2013 Session 211 Core Data Performance Optimization and Debuggingpages 128-131 discuss using a canonicalized search in Core Data. So I am attempting to configure my Core Data model to support this method of searching. I've created a Tokens object with a token attribute of type String (?? Considering whether changing this to type transformable to support saving a string as an Array would be better ??). I also create a relationship between the Tokens object and the base entity on my data model. From the talk, it's not precisely clear how one would use this setup. So for example, I know that I probably want to use an inexpensive query against the Tokens entity with an operator like BEGINSWITH but would ANY and other operators be too costly to use?Also I can't find any sample projects showing how to implement the search-token algorithm. So, it's a bit unclear if I should have one word in each token or if I have a string in each token attribute then it's not entirely clear how to parse that effici
Replies
2
Boosts
0
Views
912
Activity
Sep ’15
Reply to Protocols, abstraction, and types
Sure, but this avoids the problem by further specializing the protocol. On the most basic level, I just want the protocol to define the relationships. Ideally, I could create any number of variations on TypeB that add different kind of specialization, without breaking the relationship between TypeA and TypeB.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’15
Reply to Protocols, abstraction, and types
I'm not sure what you mean. Protocols are not superclasses. Protocols dictate a set of things that can be guaranteed about any type that conforms to them.So if your protocol is empty, then it doesn't require anything from types that conform to it. And the only thing the compiler can know about all the types that conforms to it is that they conform to it, nothing more. So It can't know of any methods or properties or typealiases of that type, unless it is looking at the concrete type and not the protocol, of course.The only thing it means for a (concrete) type to conform to a protocol is that it has to conform to it, it has to provide implementations for the methods, properties and typealiases that the protocol demands, or it will fail to conform.There's no inheritance or anything like that going on, a protocol and the types conforming to it cannot reach each other in any way. The protocol specifies an interface that the conforming types must have and thus are guaranteed to have, that's it.And a type
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’15
Reply to Protocols, abstraction, and types
Well, one of the proposals of the Protocol-Oriented Programming talk seemed to be suggesting that we could treat them (somewhat) synonymously to superclasses. Besides, I don't want these relationships to be limited to classes - I'd like the freedom to use structs, for example (as in my sample problem). (By the way, the fact that TypeB was empty wasn't intended to be significant.)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’15
Reply to Protocols, abstraction, and types
I saw the Protocol-Oriented talk and I thought it was one of the best talks. I think protocols are great and I use them and value types for most things, sometimes a class is needed for the indirection / identity, but I almost never use class inheritance, so in that way I guess that you can say that using protocols can do away with super classes.However, I can't really understand how you see protocols, what they are and what expectations you have on them, and this makes it hard to explain what they are and what they are not. (I did try in my previous reply.)I would suggest that you read more about protocols and generics in the Swift book.One of the most important differences between Objective-C and Swift is that in Objective-C almost everything you do is done dynamically, while in Swift and especially when using protocols, you tend to not do dynamically what can be done statically, which means you will want to make the compiler know as much as possible about your types and your code, which is totally
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’15
Reply to Protocols, abstraction, and types
Well, I'm starting to think that I probably see protocols exactly as they are, but just hoped for some unforeseen magic!What I'd hoped to do was not necessarily to create superclasses, per se, but to create a set of relationships between objects (types, really). Specifically, I'm working on a VIPER variant for our new project, and I wanted to use protocols to specify the relationships between components in each module. This would be pure abstraction, in the sense that there would be no implementations at all, just relationships (so, perfect for protocols). For example, a Presenter might know that it has a FlowController, without knowing anything else about it. This would be implemented at the protocol level. The components would adopt these basic protocols, which would enforce a certain connectivity between components, but the objects conforming to the protocols (the actual implementations) would define their own functionality, given the particular module (use-case). I can't do this
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’15
Reply to Protocols, abstraction, and types
The point was to separate the architecture from its implementation. As far as compilation goes, I do explicitly pass sTypeA an instance of structTypeB, so I don't see it as being particularly ambiguous at compile time.As far as the empty TypeB goes, as I said before, this is just a mock example; it would likely have some more specific requirements (but that's beside the point).In the actual implementation I'm trying to figure out, TypeA might be an Interactor (i.e., in VIPER), and TypeB might be a Presenter. If I have two use-cases, like UserCreation and TaskCreation, say, then I would create a UserCreationInteractor: Interactor, and a UserCreationPresenter: Presenter. Thus the protocol would (at minimum) specify the relationship between UserCreationInteractor and UserCreationPresenter (i.e., fundamentally the same as Interactor to Presenter). Crucially, the actual implementation of UserCreationInteractor and TaskCreationInteractor would likely be quite different.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’15
Default viewDidLoad in protocol extension
I used to have a base class that inherited from UITableViewController and defined some defaults for the delegates, as well as a viewDidLoad default. I'm now trying to change that to be a protocol extension instead, so I did the following:protocol HeaderSectionRenderer { func coloredHeaderViewWithText(title: String, uppercase: Bool) -> UITableViewHeaderFooterView func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat } extension HeaderSectionRenderer where Self: UITableViewController { func coloredHeaderViewWithText(title: String, uppercase: Bool = false) -> UITableViewHeaderFooterView { ... } func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 25.0 } }That covers those two methods with a default implementation, but now I need to have a viewDidLoad. I tried the obvious: override func viewDidLoad() { super.viewDidLoad() tableView.registerClass(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier:
Replies
1
Boosts
0
Views
3.6k
Activity
Sep ’15
Tons of Problems w/ OS X GM Release 10.11
All:I'm experiencing a complete disaster for the first time ever with a GM release of OS X. 10.11 is a continuning nightmare. I don't know why the GM is so bad when all the prior betas seem to be just fine.1) The inital installation caused me to be unable to launch any applications. None. I've recovered from that using the usual profile recovery methods and inheriting the home folder, etc. However....2) I'm now unable to log in to *ANY* iCloud services. I thought this was due to the poorly implemented 2-factor authentication Apple is using (it's highly unreliable when dealing with app specific passwords) so I turned it off. I'm still unable to access iCloud services including messages, facetime, etc. Right now I'm thinking that my entire keychain has been hosed. The problems are so surreal I may never really be sure. Welcome to Windows 10 by Apple for the Mac!DM
Replies
3
Boosts
0
Views
347
Activity
Sep ’15