Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Reply to Question regard disabling button in Swift
@IBAction methods usually have a sender argument:@IBAction func myAction(sender: AnyObject){...} //or @IBAction func myAction(sender: UIButton) {...}The sender argument defaults to a type of AnyObject, but it's possible to set the sender's type to UIButton when you create the action. Even if you don't, you can either downcast it from AnyObject to UIButton in the action, or edit your source code to change AnyObject to UIButton. The later works if you know the action will only be called by UIButton instances.Once you have the sender as a UIButton, you can set the sender's enabled state to false:sender.enabled = falseWith this approach, you're sure to set the enabled state on the button that initiated the action.Alternatively, if you also make an IBOutlet for the button, you can refer to the button by the IBOutlet (a property) as opposed to using the sender argument, which lets you change the state from other places in your code, such as after the processing has completed.@IBOutlet weak var myButton: UIButton! /
Aug ’15
Reply to Will we ever be able to use generic protocols as types?
Doesn't seem to really work very well. I added another parameter which depends on the first. Crashes the compiler (6.4/7.0)protocol MyCollection {typealias T} struct Struct<MC: MyCollection where MC.T == Int, C:CollectionType where C.Element == MC> { init(_ mc: MC) {self.mc = mc} let mc: MC } struct MyCollection_Int: MyCollection {typealias T = Int; typealias C = Array<Int> } let struct_int = Struct(MyCollection_Int())And, of course, there is no covariant typing, so it's not actually possible to say C.Element : MC and build a dependency between those generic type parameters (it'll crash the compiler again, in a different way). You can use the : relationship between two definitely-specified types, but not between generic ones.So even if you do this, your generic type MC may still be broader than it needs to be. There will be type relationships you cannot express and so you'll need to downcast later on.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’15
how to change appleid on my Xcode
I have just inherited a macbook from a coworker who is no longer with us. The xcode on the macbook is registered to his name. How can I change this to my appleid so that I can install updates and do some development? I am very new to Mac environment (coming from *nix). Thanks.
1
0
5.9k
Aug ’15
El Capitan Beta 6 + Photos app killed my machine
I have been using El Capitan Beta 2,3,4,5 somewhat smoothly (maybe a crash or two) on my new Macbook Pro (mid 2015), but ever since I installed Beta 6 yesterday, I have experienced about 10 crashes, and now ultimately cannot use my mac at all.The only thing differently I did yesterday was mess with the Photos app. I bought space in iCloud, imported my old iPhoto library, experienced the **** which goes along with trying to combine two different iPhotos/Photos libraries, and set up my Photos app to sync my 60 GB of photos (fortunately they're backed up on an external HD) to the cloud. While the Photos app was open and syncing I got several crashes. I noticed that if I let the Photos app run in the foreground without switching apps, then it would be okay, no crash, so I let it do its business overnight, with the iCloud syncing turned off.Today I was stupid enough to re-enable the iCloud syncing. Things were going well for a while and then randomly it crashed on me, but the difference here is that when I reboot
7
0
1k
Aug ’15
Reply to Open files in a Sandboxed command-line app
I don't think there's a straightforward solution to this problem. The issue is that:Mac App Store requires that every piece of code within your app be code signed and sandboxed, including your helper tool.The App Sandbox is, as the name suggests, an app sandbox. So there's no affordance for sandboxing a tool independently of its parent app. Specifically, while you can sandbox a tool, there's no magic that gives the tool access to the paths that are passed to it via command line arguments.Sandbox inheritance (com.apple.security.inherit), which is the way I generally recommend that folks sandbox their tools, does not work for this because Terminal is not sandboxed so, when you run the tool from the command line, there's nothing to inherit from.You may be able to resolve the problem by converting your tool to some sort of script (a shell script, Python, whatever). That's almost certainly feasible from a technical perspective, I just don't know how it interacts with the Mac App Store rules. If n
Topic: Code Signing SubTopic: General Tags:
Aug ’15
Protocol extension triggers segfault
I haven't seen this specific pattern of protocol extension elsewhere, but it works in a playground and does what I need it to do — extending one protocol to provide an implementation of another protocol it inherits with typealias requirements. Simple example:protocol TreeNode: SequenceType { var children: Array<Self> { get set } } extension SequenceType where Self: TreeNode, Generator == AnyGenerator<Self> { func generate() -> Generator { return anyGenerator(children.generate()) } }Issue comes when it's dropped into a project. If it's the only thing in the project, it'll compile fine. However, I can drop seemingly innocuous code (not in any way interacting with the above) into another file and the project segfaults on compile.Example of innocuous code for another file:struct IntWrapper { let anInt: Int = 0 }This compiles fine without the presence of the above.Better way to accomplish the same? Suggestions for troubleshooting the segfault?
3
0
476
Aug ’15
Apple is handling core data optionals wrong
OK, so this is my opinion, but I'm curious what everyone else thinks. If you mark your references as *not* optional and then generate the subclasses, the types written to the file are marked as optionals in Swift. According to Apple,Swift optional is different to Core Data optional. Core Data optional is enforced at the data store level, whereas NSManagedObjects in the Obj-C/Swift runtime may have null object values until they are persisted.To me, if the relationship isn't optional, then the variable shouldn't be optional either so that I don't try and use it as an optional. I don't want to have to constantly unwrap the values, or check with an if let/guard type statement. It would make more sense to mark them as explicitly unwrapped optionals than as normal optionals. Thoughts?
0
0
209
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
Oh, sorry for missing your intension.So, back to the original issue.UICollectionViewLayout is an abstract class, so its Methods-to-Override (described in the Subclassing Notes in the UICollectionViewLayout Class Reference) are just placeholders, have no useful implementation and return meaningless results.UICollectionViewFlowLayout is a concrete subclass of UICollectionViewLayout, so all Methods-to-Override work and return results for implementing flow layout, those might be useful when implementing similar layout.So, calling superclass methods like super.prepareLayout() or super.layoutAttributesForItemAtIndexPath(indexPath) are useless when inheriting from UICollectionViewLayout.These may be some help.CircleLayout class in the sample code CircleLayout.APLStackLayout class in the sample code Collection View Transition.And the Creating Custom Layouts section and the Custom Layouts: A Worked Example section in the Collection View Programming Guide for iOS.
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’15
same font different device
hi all I need some font equivalence in ios and android (at least that's what is customer's requirement) I use following code to decide a font size for ios. UIFontDescriptor *bigDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline]; UIFont *aFont = [UIFont fontWithDescriptor:bigDescriptor size:0]; CGFloat pointSize = fminf(fmaxf((aFont.pointSize * 1.1), 11), 56); // 12 returnFont = [UIFont fontWithName:@Avenir-roman size:pointSize]; I also use same font in android the list item label font is Avenir-roman 20dp now how is iphones pointwidth and androids dpi compared, is there any comparision available ? To give an example, in the above code I dont nderstand what the calculation line is intended for, as i inherited the code from somebody who is not traceable. But i figured out that pointSize comes as 17 in iphone or ipad and it is multiplied by 1.1 and a value of 18.7 is passed. the problem is, this looks bolder and wider than 20dp in android. pfa screen hsot for th
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
420
Aug ’15
OSX segue within one window
After using storyboards on iOS for some time, I'm attempting to make use of them on a Mac project.The first oddity that I'm encountering is that show segues create new windows, even though there is only one window defined in my storyboard.This seems to happen whether the segue is performed automatically through a button connection or done in code.The documentation language is rather vague as it talks about transition relationships and scenes without defining their visual result or which objects are involved.Is it really intended that every scene creates an extra window?I guess the real question is: How do I achieve the expected behaviour of having a segue cause the replacement of one view controller with another while using the same window?
Topic: UI Frameworks SubTopic: AppKit Tags:
3
0
4.3k
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
These are class factory functions in Objective-C which (AFAIK) means you can't use them to create instances of subclasses.I may be missing something, but all three convenience initalizers are available for subclasses such as your CustomLayoutAttributes which inherits all designated initializers.In fact, even if I replace the layoutAttributesForItemAtIndexPath(_:) method in the sample code CircleLayout as follows, it works: override func layoutAttributesForItemAtIndexPath(path: NSIndexPath) -> UICollectionViewLayoutAttributes? { let attributes = CustomLayoutAttributes(forCellWithIndexPath: path) attributes.size = CGSizeMake(ITEM_SIZE, ITEM_SIZE) attributes.center = CGPointMake(center.x + radius * cos(2 * CGFloat(path.item) * CGFloat(M_PI) / CGFloat(cellCount)), center.y + radius * sin(2 * CGFloat(path.item) * CGFloat(M_PI) / CGFloat(cellCount))) return attributes }Or, you can do something like this, if you want to make your code compliant with subclassing notes. let attributesClass = self.dynamicTy
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’15
Inherit GKGoal or GKBehavior
Hello there,I've been playing with Agents, Goals & Behaviors ecosystem and I must admit it's great so far (really time saving).I'd like to add a behavior to some of my entities: make them go in one direction, and once an obstacle has been hit, bounce in the other direction (like in the old 80's games). I know how to do this the classical way - using physics or not - but I was wondering if trying to implement it using the Agents and/or Pathfinding system is a good or bad choice here? Any advice?Thanks!
1
0
383
Aug ’15
How to set Equatable in protocols
Hello I am using Term protocol as a Type for my structs so I can have a Statement struct with terms collection where I could store the rest of my structs. What I would like to do is, I would like to check for equality for the term in the array and the argument I pass in the function in the bottom. I know the WWDC session Building Better Apps with Value Types talking about Equatable protocol being implementing on a struct however in this instance I do have Term which is already a protocol. How would it work in this case?Thanks in advance.import Foundation protocol Term { var value: String { get } } extension Term {} struct Statement { var terms: [Term] = [] mutating func addItem(term: Term) { terms.append(term) } } struct Fraction: Term { let numerator: Statement let denominator: Statement let value: String } struct Exponent: Term { let base: String let power: Statement let value: String } struct Variable: Term { let value: String } struct Operator: Term { let value: String } struct Number: Term { let value: S
13
0
8k
Aug ’15
Why is Xcode creating an optional attr?
In my core data model on my entity I've created a non-optional relationship to another entity. When I have Xcode (Xcode 7 Beta 5) generate the NSManagedObject subclass, it's creating an attribute of type NSSet?. Why is it making this attribute optional?
Replies
3
Boosts
0
Views
5.2k
Activity
Aug ’15
Reply to Question regard disabling button in Swift
@IBAction methods usually have a sender argument:@IBAction func myAction(sender: AnyObject){...} //or @IBAction func myAction(sender: UIButton) {...}The sender argument defaults to a type of AnyObject, but it's possible to set the sender's type to UIButton when you create the action. Even if you don't, you can either downcast it from AnyObject to UIButton in the action, or edit your source code to change AnyObject to UIButton. The later works if you know the action will only be called by UIButton instances.Once you have the sender as a UIButton, you can set the sender's enabled state to false:sender.enabled = falseWith this approach, you're sure to set the enabled state on the button that initiated the action.Alternatively, if you also make an IBOutlet for the button, you can refer to the button by the IBOutlet (a property) as opposed to using the sender argument, which lets you change the state from other places in your code, such as after the processing has completed.@IBOutlet weak var myButton: UIButton! /
Replies
Boosts
Views
Activity
Aug ’15
Reply to Will we ever be able to use generic protocols as types?
Doesn't seem to really work very well. I added another parameter which depends on the first. Crashes the compiler (6.4/7.0)protocol MyCollection {typealias T} struct Struct<MC: MyCollection where MC.T == Int, C:CollectionType where C.Element == MC> { init(_ mc: MC) {self.mc = mc} let mc: MC } struct MyCollection_Int: MyCollection {typealias T = Int; typealias C = Array<Int> } let struct_int = Struct(MyCollection_Int())And, of course, there is no covariant typing, so it's not actually possible to say C.Element : MC and build a dependency between those generic type parameters (it'll crash the compiler again, in a different way). You can use the : relationship between two definitely-specified types, but not between generic ones.So even if you do this, your generic type MC may still be broader than it needs to be. There will be type relationships you cannot express and so you'll need to downcast later on.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’15
Update APP with new provisioning cert
Hello-Is there a way to update an existing app while also providing new distribution credentials?We have inherited a project created by another publisher...but they are planning on revoking the client certificates.Any help would be greatly appreciated...Thanks!pt3
Replies
2
Boosts
0
Views
333
Activity
Aug ’15
how to change appleid on my Xcode
I have just inherited a macbook from a coworker who is no longer with us. The xcode on the macbook is registered to his name. How can I change this to my appleid so that I can install updates and do some development? I am very new to Mac environment (coming from *nix). Thanks.
Replies
1
Boosts
0
Views
5.9k
Activity
Aug ’15
El Capitan Beta 6 + Photos app killed my machine
I have been using El Capitan Beta 2,3,4,5 somewhat smoothly (maybe a crash or two) on my new Macbook Pro (mid 2015), but ever since I installed Beta 6 yesterday, I have experienced about 10 crashes, and now ultimately cannot use my mac at all.The only thing differently I did yesterday was mess with the Photos app. I bought space in iCloud, imported my old iPhoto library, experienced the **** which goes along with trying to combine two different iPhotos/Photos libraries, and set up my Photos app to sync my 60 GB of photos (fortunately they're backed up on an external HD) to the cloud. While the Photos app was open and syncing I got several crashes. I noticed that if I let the Photos app run in the foreground without switching apps, then it would be okay, no crash, so I let it do its business overnight, with the iCloud syncing turned off.Today I was stupid enough to re-enable the iCloud syncing. Things were going well for a while and then randomly it crashed on me, but the difference here is that when I reboot
Replies
7
Boosts
0
Views
1k
Activity
Aug ’15
Reply to Open files in a Sandboxed command-line app
I don't think there's a straightforward solution to this problem. The issue is that:Mac App Store requires that every piece of code within your app be code signed and sandboxed, including your helper tool.The App Sandbox is, as the name suggests, an app sandbox. So there's no affordance for sandboxing a tool independently of its parent app. Specifically, while you can sandbox a tool, there's no magic that gives the tool access to the paths that are passed to it via command line arguments.Sandbox inheritance (com.apple.security.inherit), which is the way I generally recommend that folks sandbox their tools, does not work for this because Terminal is not sandboxed so, when you run the tool from the command line, there's nothing to inherit from.You may be able to resolve the problem by converting your tool to some sort of script (a shell script, Python, whatever). That's almost certainly feasible from a technical perspective, I just don't know how it interacts with the Mac App Store rules. If n
Topic: Code Signing SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’15
Protocol extension triggers segfault
I haven't seen this specific pattern of protocol extension elsewhere, but it works in a playground and does what I need it to do — extending one protocol to provide an implementation of another protocol it inherits with typealias requirements. Simple example:protocol TreeNode: SequenceType { var children: Array<Self> { get set } } extension SequenceType where Self: TreeNode, Generator == AnyGenerator<Self> { func generate() -> Generator { return anyGenerator(children.generate()) } }Issue comes when it's dropped into a project. If it's the only thing in the project, it'll compile fine. However, I can drop seemingly innocuous code (not in any way interacting with the above) into another file and the project segfaults on compile.Example of innocuous code for another file:struct IntWrapper { let anInt: Int = 0 }This compiles fine without the presence of the above.Better way to accomplish the same? Suggestions for troubleshooting the segfault?
Replies
3
Boosts
0
Views
476
Activity
Aug ’15
Apple is handling core data optionals wrong
OK, so this is my opinion, but I'm curious what everyone else thinks. If you mark your references as *not* optional and then generate the subclasses, the types written to the file are marked as optionals in Swift. According to Apple,Swift optional is different to Core Data optional. Core Data optional is enforced at the data store level, whereas NSManagedObjects in the Obj-C/Swift runtime may have null object values until they are persisted.To me, if the relationship isn't optional, then the variable shouldn't be optional either so that I don't try and use it as an optional. I don't want to have to constantly unwrap the values, or check with an if let/guard type statement. It would make more sense to mark them as explicitly unwrapped optionals than as normal optionals. Thoughts?
Replies
0
Boosts
0
Views
209
Activity
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
Oh, sorry for missing your intension.So, back to the original issue.UICollectionViewLayout is an abstract class, so its Methods-to-Override (described in the Subclassing Notes in the UICollectionViewLayout Class Reference) are just placeholders, have no useful implementation and return meaningless results.UICollectionViewFlowLayout is a concrete subclass of UICollectionViewLayout, so all Methods-to-Override work and return results for implementing flow layout, those might be useful when implementing similar layout.So, calling superclass methods like super.prepareLayout() or super.layoutAttributesForItemAtIndexPath(indexPath) are useless when inheriting from UICollectionViewLayout.These may be some help.CircleLayout class in the sample code CircleLayout.APLStackLayout class in the sample code Collection View Transition.And the Creating Custom Layouts section and the Custom Layouts: A Worked Example section in the Collection View Programming Guide for iOS.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’15
same font different device
hi all I need some font equivalence in ios and android (at least that's what is customer's requirement) I use following code to decide a font size for ios. UIFontDescriptor *bigDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline]; UIFont *aFont = [UIFont fontWithDescriptor:bigDescriptor size:0]; CGFloat pointSize = fminf(fmaxf((aFont.pointSize * 1.1), 11), 56); // 12 returnFont = [UIFont fontWithName:@Avenir-roman size:pointSize]; I also use same font in android the list item label font is Avenir-roman 20dp now how is iphones pointwidth and androids dpi compared, is there any comparision available ? To give an example, in the above code I dont nderstand what the calculation line is intended for, as i inherited the code from somebody who is not traceable. But i figured out that pointSize comes as 17 in iphone or ipad and it is multiplied by 1.1 and a value of 18.7 is passed. the problem is, this looks bolder and wider than 20dp in android. pfa screen hsot for th
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
0
Boosts
0
Views
420
Activity
Aug ’15
OSX segue within one window
After using storyboards on iOS for some time, I'm attempting to make use of them on a Mac project.The first oddity that I'm encountering is that show segues create new windows, even though there is only one window defined in my storyboard.This seems to happen whether the segue is performed automatically through a button connection or done in code.The documentation language is rather vague as it talks about transition relationships and scenes without defining their visual result or which objects are involved.Is it really intended that every scene creates an extra window?I guess the real question is: How do I achieve the expected behaviour of having a segue cause the replacement of one view controller with another while using the same window?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
3
Boosts
0
Views
4.3k
Activity
Aug ’15
Reply to Problems with subclassing UICollectionViewLayoutAttributes
These are class factory functions in Objective-C which (AFAIK) means you can't use them to create instances of subclasses.I may be missing something, but all three convenience initalizers are available for subclasses such as your CustomLayoutAttributes which inherits all designated initializers.In fact, even if I replace the layoutAttributesForItemAtIndexPath(_:) method in the sample code CircleLayout as follows, it works: override func layoutAttributesForItemAtIndexPath(path: NSIndexPath) -> UICollectionViewLayoutAttributes? { let attributes = CustomLayoutAttributes(forCellWithIndexPath: path) attributes.size = CGSizeMake(ITEM_SIZE, ITEM_SIZE) attributes.center = CGPointMake(center.x + radius * cos(2 * CGFloat(path.item) * CGFloat(M_PI) / CGFloat(cellCount)), center.y + radius * sin(2 * CGFloat(path.item) * CGFloat(M_PI) / CGFloat(cellCount))) return attributes }Or, you can do something like this, if you want to make your code compliant with subclassing notes. let attributesClass = self.dynamicTy
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’15
Inherit GKGoal or GKBehavior
Hello there,I've been playing with Agents, Goals & Behaviors ecosystem and I must admit it's great so far (really time saving).I'd like to add a behavior to some of my entities: make them go in one direction, and once an obstacle has been hit, bounce in the other direction (like in the old 80's games). I know how to do this the classical way - using physics or not - but I was wondering if trying to implement it using the Agents and/or Pathfinding system is a good or bad choice here? Any advice?Thanks!
Replies
1
Boosts
0
Views
383
Activity
Aug ’15
How to set Equatable in protocols
Hello I am using Term protocol as a Type for my structs so I can have a Statement struct with terms collection where I could store the rest of my structs. What I would like to do is, I would like to check for equality for the term in the array and the argument I pass in the function in the bottom. I know the WWDC session Building Better Apps with Value Types talking about Equatable protocol being implementing on a struct however in this instance I do have Term which is already a protocol. How would it work in this case?Thanks in advance.import Foundation protocol Term { var value: String { get } } extension Term {} struct Statement { var terms: [Term] = [] mutating func addItem(term: Term) { terms.append(term) } } struct Fraction: Term { let numerator: Statement let denominator: Statement let value: String } struct Exponent: Term { let base: String let power: Statement let value: String } struct Variable: Term { let value: String } struct Operator: Term { let value: String } struct Number: Term { let value: S
Replies
13
Boosts
0
Views
8k
Activity
Aug ’15