Questions tagged [swift-array]

An array in swift programming stores multiple values of the same type in an ordered list. The same value can appear in an array multiple times at different positions.

Swift arrays are specific about the kinds of values they can store. They differ from Objective-C’s NSArray and NSMutableArray classes, which can store any kind of object and do not provide any information about the nature of the objects they return.

In Swift, the type of values that a particular array can store is always made clear, either through an explicit type annotation, or through type inference, and does not have to be a class type. If you create an array of Int values, for example, you can’t insert any value other than Int values into that array. Swift arrays are type safe, and are always clear about what they may contain.

link: https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html#//apple_ref/doc/uid/TP40014097-CH8-XID_172

22 questions
0
votes
2 answers

NSObject class conforms to protocol contained in NSArray with Swift

I would like to create a method in Swift that returns an array of NSObject objects that conform to a protocol. I've tried something like this: func createManagers() -> [Manager] { let result = NSMutableArray(capacity: self.classes.count) …
Infinite Possibilities
  • 7,415
  • 13
  • 55
  • 118
0
votes
1 answer

Remove objects from NsMutableArray with removeObjectsInArray(someArray) in swift

I have two NSMutableArray's I am trying to remove the MutableArray from other Array with removeObjectsInArray() method Here is my code: arrayImage.removeObjectsInArray(arrayDeleteImage) But it requires a filter (NSPredicate), I don't understand…
ios developer
  • 198
  • 19
0
votes
1 answer

Array / Stack contains function

I would like to give my STACK struct the function contains(element: Element) that returns a bool as to whether var contents contains the element provided. struct Stack: SequenceType, Equatable, Printable, DebugPrintable { typealias Element =…
Sean
  • 377
  • 3
  • 12
0
votes
3 answers

Swift: array of dictionaries has count of 1 after initialization but should have 0

var persons = [Dictionary()] println(persons.count) prints 1. I see that there is an empty dictionary inside the array when it is initialized but is there a way to avoid that and having 0 elements instead of 1? Later I need to be…
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
0
votes
2 answers

How do I access an Array stored in a Dictionary in Swift?

This is how I created my Dictionary with the Array: @IBAction func didTapSaveButton(sender: UIButton) { var hooObject = Dictionary() hooObject["\(dayLabel.text)"] = ["\(fromTimeLabel.text) - \(toTimeLabel.text)",…
LondonGuy
  • 10,778
  • 11
  • 79
  • 151
-2
votes
1 answer

How to separate each string in a table view array into its own cell?

I am building an app using swift and have created an array with over 700 rows displayed in the table view. The issue is that I need each row to occupy its own individual cell, but all 700 text strings are grouped to one table view cell. How do I go…
user4938361
  • 149
  • 1
  • 10
-2
votes
1 answer

Why does ("0"+"1").toInt()! return 1 as an Int, rather than 0

Was playing around with the reduce function on collections in Swift. //Reduce method should return an Int with the value 3141. let digits = ["3", "1", "4", "1"] .reduce(0) { (total:Int, digit:String) in return ("\(total)" +…
DanielRak
  • 239
  • 1
  • 2
  • 11
1
2