0

I am working with the ActionSheetPicker 3.0 (https://github.com/skywinder/ActionSheetPicker-3.0) picker and am having a newbie problem of working with the return values from the ActionSheetMultipleStringPicker. I've got the control running and can return values from it, but I want to be able to put the return values from the picker into separate variables or into something that I can join together. I've found numerous examples, but can't figure out how to get them to work.

What I think I've found through debugging is that ActionSheetMultipleStringPicker returns an array of Any?.

Debugging shows the following:

values Any? some payload_data_0 Builtin.RawPointer 0x60800044fdb0 0x000060800044fdb0 -> 0x000000010dacddd8 (void *)0x000000010dacdf18: __NSArrayI payload_data_1 Builtin.RawPointer 0x335392d30 0x0000000335392d30 payload_data_2 Builtin.RawPointer 0x10d28d798 0x000000010d28d798 libobjc.A.dylib`objc_retainAutoreleasedReturnValue + 35 instance_type Builtin.RawPointer 0x60800005d5c8 0x000060800005d5c8

values is the return value from the picker.

A couple things that I've tried are:

let stringText: String? = String(describing: values)
print(stringText)

This prints:

Optional("Optional(<__NSArrayI 0x60800044be20>(\nOne,\nMany,\naaa\n)\n)")

I've also tried:

print("\(values as! NSArray)")

This is the closest I've gotten to the results I'm looking for which is:

( One, Many, aaa )

Can anyone provide some assistance getting the value of 'values' into something that I can separate into three different string variables?

My code for the picker is:

    let a = ActionSheetMultipleStringPicker.init(title: "Fertilizer Setup", rows: [

        // TODO: Read values from database
        ["One", "Two", "A lot"],
        ["Many", "Many more", "Infinite"],
        ["aaa","sss","ccc","xxxx"]
        ], initialSelection: [0, 0, 0],
           doneBlock: {
               picker, indexes, values in

               let stringText: String? = String(describing: values)

               print(stringText)

               print("\(values as! NSArray)")
    },
           cancel: {ActionMultipleStringCancelBlock in return }, origin: sender)

    a?.setCancelButton(UIBarButtonItem(title: "My own title", style: UIBarButtonItemStyle.plain, target: self, action: nil))
    a?.show()
6
  • Might be a duplicate of that or of that Commented Jun 13, 2017 at 16:29
  • Option click on values, and you'll see its inferred type. What does it show? Commented Jun 13, 2017 at 16:41
  • @Yonlif, I did see those posts, but I wasn't able to get the examples to work with my solution. Commented Jun 13, 2017 at 19:34
  • @Alexander, Option + Click doesn't show the type. I get a popup that says No Quick Help. I am able to get this though. Printing description of values: ▿ Optional<Any> ▿ some : 3 elements ▿ 0 : One ▿ 1 : Many ▿ 2 : aaa Commented Jun 13, 2017 at 19:36
  • So it is an NSArray. Is it an NSArray containing only strings? Commented Jun 13, 2017 at 20:44

1 Answer 1

0

I was able to figure this out. I changed my doneBlock code to be:

doneBlock: {
            picker, indexes, values in
                 let fertilzerPicker:  NSArray = values as! NSArray               
                 self.row.value!.name = fertilzerPicker[0] as! String
                 self.row.value!.amount = fertilzerPicker[1] as! Int
                 self.row.value!.unitOfMeasurement = fertilzerPicker[2] as! String
}

The key line being:

let fertilzerPicker:  NSArray = values as! NSArray

Creating fertilzerPicker allowed me to get the individual elements of the array.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.