Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Use Handoff in Complication
Hello,I have a complication for my app correctly working and I'd like to tell my app, once it launched, which data it should show. Let's say I have a calendar application with the time travel feature and the user taps on a future event. What I would like to do here is when the user taps the complication to open, the id of the event is passed to the main app upon launching (via Handoff presumably like it's possible in Glance) so I can show the correct information to the user.I have read the documentation and I couldn't find a way to do this. The ComplicationController inherits from NSObject and so there is no way to do that via Handoff and the updateUserActivity method. Any idea how to solve this problem?Thanks a lot.
0
0
260
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
Thanks OOPer 🙂 that was it!So a convenience initialiser defined on the superclass can call the designated initialiser of a subclass because it is inherited? I didn't know that but it works 😊I looked at Apple's docs on initialisation https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.htmlparticularly Initializer Delegation for Class Types and this is not obvious to me.Anyway, thanks again. Much appreciated!
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
Initialization is one of the toughest parts in Swift. Frankly, many aspects of initialization are not crystal clear for me, even now.But, in this case, avaiability of convenience initializer is OK. It's a guranteed feature, not a works-as-for-now thing.Automatic Initializer Inheritance part of the Class Inheritance and Initialization section can be some help.
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’15
NSPredicate parse error
I'm trying to create a predicate with the below line, but it keeps telling me it's unable to parse the format string.var request = NSFetchRequest(entityName: Player) request.predicate = NSPredicate(format: ANY matches.bracket == %@, self)On Player's entity 'matches' is an optional to-many relationship to a Match entity. The Match entity has a to-one required attribute 'bracket' that points to a Bracket entity. I'm inside of the Bracket class with the above code, so thus the 'self' property.I want to get all Player entities where at least one of the matches pointed to belongs to the current bracket.What am I doing wrong here?
2
0
2.0k
Aug ’15
using history.back() in UIWebView but loaded pre page contains very old data
IOS 8.0+My app use UIWebview to visit a forum site. The forum front page contains two tag: default one is 'Recommend', another one is 'Newest'. Using ajax to load post data When user switch to 'Newest' tag, at the same time the page runs the follow codes to save state:window.history.pushState(null, title, url);After that if user is interesting with some post, he/she would click link and jump to a new page to view detail of the post. In this page, I use follow code to let user have a way to go back to 'Newest':history.back(-1);Now interesting thing happened, go back to 'Newest' tag but post data is very very old.After some tests, I found the data is always be the first time loaded after installed the app.This bug will not happen in Safari or Android app.I believe it should have some relationship with webView cache.But why UIWebview does't use newest cache? And how to solve this problem?
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
1.6k
Aug ’15
Reply to How to create multiple table views in a view controller?
UICollectionViewCell inherits from UIView so you can add your subviews directly in cell. You can add them from Interface Builder or from the code. I would suggest you search for collection view tutorials to get a better understanding.You can also use UITableView if vertical list is all you need. With UICollectionView, you can use different layouts for example horizontal or circular.
Aug ’15
Reply to How do you do these Extensions with static methods?
The reason why your class didn't conform to the protocol without the typealias being defined is because the protocol extension where the default methods are implemented is constrained to a particular case (types where the FetchableType typealias is defined as Self).Without your type having a subtype FetchableType typealiased to Self, your type doesn't inherit those methods and so doesn't meet the requirements for the protocol.You could actually set a default typealias in the protocol definition too, like this:protocol Fetchable { typealias FetchableType: NSManagedObject = Self /* ... */ }if it's valid for all types which conform to Fetchable to use those default implementations, and then you wouldn't need to add the typealias to all the individual types which conform to it.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’15
protocol extension inheriting from Obj-C optional protocol
I have a couple of view controllers that can send email and was hoping to cleanup the code using a protocol extension. Something like this:protocol MailSender: class, MFMailComposeViewControllerDelegate { func composeMail(config: MFMailComposeViewController -> ()) func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?) func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) } extension MailSender { func composeMail(config: MFMailComposeViewController -> ()) { let mailer = MFMailComposeViewController() mailer.mailComposeDelegate = self config(mailer) presentViewController(mailer, animated: true, completion: .None) } // This method will never be called :( func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) { /* handle result */ dismissViewControllerAnimated(true, completion: .None) } }In use it looks like:class MyViewController: UIViewContr
6
0
1.2k
Aug ’15
Mutually Recursive Protocols / Compiler Crash
protocol Person : Hashable { var fullname : String { get set } typealias R : Relationship var relationships : Array<R> { get } } protocol Relationship : Hashable { typealias P : Person var source : P { get } var target : P { get } }The above causes a compiler crash; surely it is a known issue? Is there a work-around? Is the above a coding-style that is to be avoided (in a language like Swift)?[Apple Swift version 2.0 (swiftlang-700.0.52.2 clang-700.0.65)Target: x86_64-apple-darwin14.4.0]
6
0
1.9k
Aug ’15
Reply to Mutually Recursive Protocols / Compiler Crash
Don't know if there's a syntactically valid way to do it, but does it work if source and target are weak or unowned?Edit: I thought maybe the compiler was trying to save you from a reference cycle, but I tried it with both weak and unowned, and no difference. Splitting <Person> into two protocols compiles, though.protocol Person : Hashable { var fullname : String { get set } } protocol PersonInRelationship : Person { typealias R : Relationship var relationships : Array<R> { get } } protocol Relationship : Hashable { typealias P : Person var source : P { get } var target : P { get } }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’15
Reply to Mutually Recursive Protocols / Compiler Crash
Compiler should not crash and I don't know if this case matches any of the known issues. You should send a Bug Report.Is the above a coding-style that is to be avoided (in a language like Swift)?I'm afraid the answer for this question is Yes.When Swift applies a protocol as a type constraint, it needs to infer the actual types of the associated types.So, when you use Person protocol, Person.R needs to be inferred.And, any arbitrary type conforming to Relationship can be Person.R, Swift needs to infer Person.R.P,two types conforming to Person and Person.R.P may be different, so this makes an inifinite recursion, not mutual recursion:Person.R.P, Person.R.P.R, Person.R.P.R.P, ...You may already know, if you remove Hashable, you can write something like this:protocol Relationship { var source : Person { get } var target : Person { get } } protocol Person { var fullname : String { get set } var relationships: [Relationship] {get} }If you want to make all actual implementation of
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’15
Why are to-many Core Data relationships represented as optionals?
As of Xcode 7b6, generating NSManagedObject subclasses for Swift in Xcode for an entity with a to-many relationship will generate a property of the optional type NSSet?. From what I can tell the underlying NSManagedObject data will always contain an empty (or not empty) set for that key. Is there a good reason to keep relationships optional and having to deal with unwrapping the values every time?
Topic: UI Frameworks SubTopic: AppKit Tags:
1
0
1.2k
Aug ’15
Xcode 7 beta (5 & 6) cannot see IBOutlets of some VCs
Sometime in the past week or two, the Storyboard editor in Xcode 7 beta (then beta 5, now also still in beta 6) stopped recognizing the IBOutlets in _some_ (not all) of my UIViewController subclasses. (NOTE: my app is a pure Swift 2, iOS 9-targeting project.)Specifically, it cannot see the IBOutlets in VCs whose source files reside within my project's (app-specific) main folder, but it _can_ see them in (generic, non-app-specific) VCs that I keep in an Externals folder. What's more, if I move those app-specific VCs out of the main folder, the Storyboard editor sees their IBOutlets just fine:(I can't seem to post any screenshots here, so here's a diagram:)<Project Folder> IIAM.xcodeproj <-- Project Externals <-- Where I keep non-app-specific code and resources Classes Views <-- The Storyboard Editor sees the IBOutlets of all these files just fine IIAM <-- All app-specific code and resources Classes Views <-- The Storyboard Editor doesn't recognize any IBOutlets of these filesBut if I move
5
0
759
Aug ’15
Use Handoff in Complication
Hello,I have a complication for my app correctly working and I'd like to tell my app, once it launched, which data it should show. Let's say I have a calendar application with the time travel feature and the user taps on a future event. What I would like to do here is when the user taps the complication to open, the id of the event is passed to the main app upon launching (via Handoff presumably like it's possible in Glance) so I can show the correct information to the user.I have read the documentation and I couldn't find a way to do this. The ComplicationController inherits from NSObject and so there is no way to do that via Handoff and the updateUserActivity method. Any idea how to solve this problem?Thanks a lot.
Replies
0
Boosts
0
Views
260
Activity
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
Thanks OOPer 🙂 that was it!So a convenience initialiser defined on the superclass can call the designated initialiser of a subclass because it is inherited? I didn't know that but it works 😊I looked at Apple's docs on initialisation https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.htmlparticularly Initializer Delegation for Class Types and this is not obvious to me.Anyway, thanks again. Much appreciated!
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
Initialization is one of the toughest parts in Swift. Frankly, many aspects of initialization are not crystal clear for me, even now.But, in this case, avaiability of convenience initializer is OK. It's a guranteed feature, not a works-as-for-now thing.Automatic Initializer Inheritance part of the Class Inheritance and Initialization section can be some help.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’15
NSPredicate parse error
I'm trying to create a predicate with the below line, but it keeps telling me it's unable to parse the format string.var request = NSFetchRequest(entityName: Player) request.predicate = NSPredicate(format: ANY matches.bracket == %@, self)On Player's entity 'matches' is an optional to-many relationship to a Match entity. The Match entity has a to-one required attribute 'bracket' that points to a Bracket entity. I'm inside of the Bracket class with the above code, so thus the 'self' property.I want to get all Player entities where at least one of the matches pointed to belongs to the current bracket.What am I doing wrong here?
Replies
2
Boosts
0
Views
2.0k
Activity
Aug ’15
Reply to Inherit GKGoal or GKBehavior
As far as I know, you can't really inherit from either. I mean, you can, but the internal circuitry by which the behavior gets each goal's direction/speed/etc. and weights them is undocumented.
Topic: Graphics & Games SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’15
using history.back() in UIWebView but loaded pre page contains very old data
IOS 8.0+My app use UIWebview to visit a forum site. The forum front page contains two tag: default one is 'Recommend', another one is 'Newest'. Using ajax to load post data When user switch to 'Newest' tag, at the same time the page runs the follow codes to save state:window.history.pushState(null, title, url);After that if user is interesting with some post, he/she would click link and jump to a new page to view detail of the post. In this page, I use follow code to let user have a way to go back to 'Newest':history.back(-1);Now interesting thing happened, go back to 'Newest' tag but post data is very very old.After some tests, I found the data is always be the first time loaded after installed the app.This bug will not happen in Safari or Android app.I believe it should have some relationship with webView cache.But why UIWebview does't use newest cache? And how to solve this problem?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
0
Boosts
0
Views
1.6k
Activity
Aug ’15
Reply to How to create multiple table views in a view controller?
UICollectionViewCell inherits from UIView so you can add your subviews directly in cell. You can add them from Interface Builder or from the code. I would suggest you search for collection view tutorials to get a better understanding.You can also use UITableView if vertical list is all you need. With UICollectionView, you can use different layouts for example horizontal or circular.
Replies
Boosts
Views
Activity
Aug ’15
Reply to How do you do these Extensions with static methods?
The reason why your class didn't conform to the protocol without the typealias being defined is because the protocol extension where the default methods are implemented is constrained to a particular case (types where the FetchableType typealias is defined as Self).Without your type having a subtype FetchableType typealiased to Self, your type doesn't inherit those methods and so doesn't meet the requirements for the protocol.You could actually set a default typealias in the protocol definition too, like this:protocol Fetchable { typealias FetchableType: NSManagedObject = Self /* ... */ }if it's valid for all types which conform to Fetchable to use those default implementations, and then you wouldn't need to add the typealias to all the individual types which conform to it.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’15
protocol extension inheriting from Obj-C optional protocol
I have a couple of view controllers that can send email and was hoping to cleanup the code using a protocol extension. Something like this:protocol MailSender: class, MFMailComposeViewControllerDelegate { func composeMail(config: MFMailComposeViewController -> ()) func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?) func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) } extension MailSender { func composeMail(config: MFMailComposeViewController -> ()) { let mailer = MFMailComposeViewController() mailer.mailComposeDelegate = self config(mailer) presentViewController(mailer, animated: true, completion: .None) } // This method will never be called :( func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) { /* handle result */ dismissViewControllerAnimated(true, completion: .None) } }In use it looks like:class MyViewController: UIViewContr
Replies
6
Boosts
0
Views
1.2k
Activity
Aug ’15
Mutually Recursive Protocols / Compiler Crash
protocol Person : Hashable { var fullname : String { get set } typealias R : Relationship var relationships : Array<R> { get } } protocol Relationship : Hashable { typealias P : Person var source : P { get } var target : P { get } }The above causes a compiler crash; surely it is a known issue? Is there a work-around? Is the above a coding-style that is to be avoided (in a language like Swift)?[Apple Swift version 2.0 (swiftlang-700.0.52.2 clang-700.0.65)Target: x86_64-apple-darwin14.4.0]
Replies
6
Boosts
0
Views
1.9k
Activity
Aug ’15
Reply to Mutually Recursive Protocols / Compiler Crash
Don't know if there's a syntactically valid way to do it, but does it work if source and target are weak or unowned?Edit: I thought maybe the compiler was trying to save you from a reference cycle, but I tried it with both weak and unowned, and no difference. Splitting <Person> into two protocols compiles, though.protocol Person : Hashable { var fullname : String { get set } } protocol PersonInRelationship : Person { typealias R : Relationship var relationships : Array<R> { get } } protocol Relationship : Hashable { typealias P : Person var source : P { get } var target : P { get } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’15
Reply to Mutually Recursive Protocols / Compiler Crash
Compiler should not crash and I don't know if this case matches any of the known issues. You should send a Bug Report.Is the above a coding-style that is to be avoided (in a language like Swift)?I'm afraid the answer for this question is Yes.When Swift applies a protocol as a type constraint, it needs to infer the actual types of the associated types.So, when you use Person protocol, Person.R needs to be inferred.And, any arbitrary type conforming to Relationship can be Person.R, Swift needs to infer Person.R.P,two types conforming to Person and Person.R.P may be different, so this makes an inifinite recursion, not mutual recursion:Person.R.P, Person.R.P.R, Person.R.P.R.P, ...You may already know, if you remove Hashable, you can write something like this:protocol Relationship { var source : Person { get } var target : Person { get } } protocol Person { var fullname : String { get set } var relationships: [Relationship] {get} }If you want to make all actual implementation of
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’15
Why are to-many Core Data relationships represented as optionals?
As of Xcode 7b6, generating NSManagedObject subclasses for Swift in Xcode for an entity with a to-many relationship will generate a property of the optional type NSSet?. From what I can tell the underlying NSManagedObject data will always contain an empty (or not empty) set for that key. Is there a good reason to keep relationships optional and having to deal with unwrapping the values every time?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
1
Boosts
0
Views
1.2k
Activity
Aug ’15
Xcode 7 beta (5 & 6) cannot see IBOutlets of some VCs
Sometime in the past week or two, the Storyboard editor in Xcode 7 beta (then beta 5, now also still in beta 6) stopped recognizing the IBOutlets in _some_ (not all) of my UIViewController subclasses. (NOTE: my app is a pure Swift 2, iOS 9-targeting project.)Specifically, it cannot see the IBOutlets in VCs whose source files reside within my project's (app-specific) main folder, but it _can_ see them in (generic, non-app-specific) VCs that I keep in an Externals folder. What's more, if I move those app-specific VCs out of the main folder, the Storyboard editor sees their IBOutlets just fine:(I can't seem to post any screenshots here, so here's a diagram:)<Project Folder> IIAM.xcodeproj <-- Project Externals <-- Where I keep non-app-specific code and resources Classes Views <-- The Storyboard Editor sees the IBOutlets of all these files just fine IIAM <-- All app-specific code and resources Classes Views <-- The Storyboard Editor doesn't recognize any IBOutlets of these filesBut if I move
Replies
5
Boosts
0
Views
759
Activity
Aug ’15
Reply to Xcode 7 beta (5 & 6) cannot see IBOutlets of some VCs
Could you please clarify how this relates to the problem of unrecognized IBOutlets and VC modules? I don't see the relationship.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Aug ’15