swift2

Swift 2 - Check Type of empty Array (Introspection)

只愿长相守 提交于 2019-12-24 14:04:50
问题 I'm currently working on introspection in Swift 2 and have Problems getting the specific type for an Array (in this example an Array<String> ). var prop = obj.valueForKey("strings")! if prop is Array<String> { println("true") } if prop is Array<Int> { println("true") } Output is: true true while it should be true false Is there a way to find out the type for the members of the Array? For example, if I daclared the Array as Array<String> I want to get String or at least be able to check if it

WorldNode conflicting with object spawning

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 13:46:04
问题 This question is in reference to this one: Object positioning is off so I implemented the code again: let xAxisSpawnLocations: [CGFloat] = { var spawnLocations:[CGFloat] = [] //Create 5 possible spawn locations let numberOfNodes = 5 for i in 0...numberOfNodes - 1 { /* Spacing between nodes will change if: 1) number of nodes is changed, 2) screen width is changed, 3) node's size is changed. */ var xPosition = (frame.maxX - player.size.width) / CGFloat((numberOfNodes - 1)) * CGFloat(i) //add a

Replacement for C-style loop in Swift 2.2 CGFloat

二次信任 提交于 2019-12-24 12:51:54
问题 I have tried this with CGFloat and i am getting the following error: Can not invoke stride with an argument list of type '(CGFloat by: CGFloat)' for var min:CGFloat = 0.0; min<=45.0; min = min+value { print("\(min)") } to: for min:CGFloat in 0.stride(CGFloat(55.0), by: min+value) { print("\(min)") } 回答1: Below is the latest overload for stride. You can use cast the number to CGFloat for the stride. for min in (0 as CGFloat).stride(to: 55, by: value) { print("\(min)") } However, stride returns

How to pass value from navigationController to TabBarController

大兔子大兔子 提交于 2019-12-24 12:51:28
问题 I have a Login project. The first view controller is NavController and I need to pass user data to tabBarController where I have 3 NavigationControllers. I tried this. let openNewVC = self.storyboard?.instantiateViewControllerWithIdentifier("mainNavID") as! UITabBarController //openNewVC.token = token! self.navigationController?.pushViewController(openNewVC, animated: true) 回答1: You can pass the data from your first view Controller to view controllers which are embedded like as below in

Specify type of polymorphic function to pass it as argument

那年仲夏 提交于 2019-12-24 12:34:12
问题 I have function curry that takes a function (A, B) -> C as an argument, and returns A -> B -> C . It works fine on function g(a: Int, b: Int) -> Int . Also, I have function f , that is polymorphic, so its type is ambigous. Here is the code: func g(a: Int, b: Int) -> Int { return a + b } func f(a: Int, b: Int) -> Int { return a + b } func f(a: Float, b: Float) -> Float { return a + b } func curry<A, B, C>(f: (A, B) -> C) -> A -> B -> C { return { a in { b in f(a, b) } } } let curriedG = curry

Value type error SWIFT/XCODE

人盡茶涼 提交于 2019-12-24 11:27:05
问题 I have a table view where i want the view controller to pop instead of segue when the cell is selected although I am getting this error "Value of type 'UINavigationController' has no member 'popViewController'"-- Any ideas??? Please note: I am using swift 2 and xcode7 回答1: I think in swift 2 and Xcode 7 the function is: navigationController?.popViewControllerAnimated(true) 来源: https://stackoverflow.com/questions/40319160/value-type-error-swift-xcode

Append images in array in sequence

扶醉桌前 提交于 2019-12-24 09:26:49
问题 I want to add images in array in sequence after downloading. I am appending images in array after downloading one by one but they are not in sequence. Can any one please tell me what is best way to do this. var queue: NSOperationQueue = { let _queue = NSOperationQueue() _queue.maxConcurrentOperationCount = 4 return _queue }() var imageArrayNsData : [NSData] = [] let session = NSURLSession.sharedSession() @IBAction func didClickOnStart(sender: AnyObject) { queue.cancelAllOperations() let

Downloading image on Swift 2 form Firebase Storage

蹲街弑〆低调 提交于 2019-12-24 07:17:29
问题 Whenever I download an image from Firebase Storage it download's perfectly, but once I try to change the imageview "my" to it, the imageview disappears. I don't have constraints and I navigated to the local URL and found the image perfectly there. Any help? Am I doing something wrong? func loadImages(){ let documentDirectoryURL = try! NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true) let newRef = storageRef!

Swift - pruning elements from an Array, converting integer strings to integers

纵然是瞬间 提交于 2019-12-24 06:22:07
问题 I have an array that contains numbers and empty strings, like ["", "2", "4", "", "", "1", "2", ""] . I would like to pare this down to a list of numbers, like [2,4,1,2] . My first effort split this into two steps, first strip out the empty strings, then do the string-to-integer conversion. However, my code for step one isn't working as desired. for (index,value) in tempArray.enumerate(){ if value == "" { tempArray.removeAtIndex(index) } } This fails, I believe because it is using the index

Swift - pruning elements from an Array, converting integer strings to integers

半腔热情 提交于 2019-12-24 06:21:31
问题 I have an array that contains numbers and empty strings, like ["", "2", "4", "", "", "1", "2", ""] . I would like to pare this down to a list of numbers, like [2,4,1,2] . My first effort split this into two steps, first strip out the empty strings, then do the string-to-integer conversion. However, my code for step one isn't working as desired. for (index,value) in tempArray.enumerate(){ if value == "" { tempArray.removeAtIndex(index) } } This fails, I believe because it is using the index