1
votes

i have a fixed size array as

var fieldNameArray = [String?](count: 4, repeatedValue: nil)

i am doing this to search if there is the element in array or not

  if let temp = find(fieldNameArray,"profile_picture"){//i get a compile error here
            //remove the data
           ....




        }else{

            println(" //append the value")
           .....

        }

But i get a compile time error as

Cannot invoke 'find' with an argument list of type '([(String?)], String)'

I think i should unwrap it? How can i do it

UPDATED

 SRWebClient.POST(registerURl)

            .data(registerImagesArray, fieldName: fieldNameArray, data: parametersToPost)

            .send({(response:AnyObject!, status:Int) -> Void in//here compile time error


                println("response object: \(response)")

Again after i changed my array to fixed size array i got this error

Cannot invoke 'send' with an argument list of type '((AnyObject!, Int) -> Void, failure: (NSError!) -> Void)

2

2 Answers

0
votes

Try using this instead (Swift 2.0):

if let index = fieldNameArray.indexOf("profile_picture") {
        //remove the data using the index
       ....

} else {
       print("// append the value")
       .....
}

In swift 1.2 (a little inefficient but it works) :

if let temp = find(fieldNameArray.filter { $0 != nil}.map { $0! },"profile_picture") { 
    // Then same code as question... 
0
votes

For efficiency you should not do what Manav Gabhawala suggests but write a find function yourself:

func myFind(array: [String?], value: String) -> Int? {
    for (i, av) in enumerate(array) {
        if av != nil && av! == value {
            return i
        }
    }
    return nil;
}

As Swift compiles to machine code, you will have nearly the same performance as with the standard library’s find.