Drag and Drop for iOS

Let me premiss this by saying I have not written any iOS apps yet. I am just thinking about the design at this point.
I just watched a couple of videos from last year’s Apple Developers Conference about Drag & Drop for iOS. Drag & Drop would be an essential part of the app that I have in mind. Is there a way to implement it in the current (2018r1) release?

Thank you for your replies.

It is certainly possible to implement with some declares.

Thanks for the reply. I’ve never used a declare in Xojo. I’ve used lots of Windows API functions in VB. I actually wrote an article for Visual Studio Magazine about using drag and drop in VB back in 2000. This would be my first iOS app. With VB, Daniel Appleman literally wrote the book. Where does one go to learn how to implement Apple Declares in Xojo?

Thanks

What are you planning on "dragging “FROM” and what are you planning on “dropping” “TO”

Just spit-balling at the moment but the app would be used by stage managers to create a stage-plot. There would be a list of instruments along one side. (Guitar, Fiddle, Mandolin, etc. They would drag them from the side onto a representation of the stage. The app would then assign channel numbers and send them to the computer attached to the mixer. The mixer operator could then load them as a scene.

It’s all about saving time. In a festival situation, they may only have a few minutes to move one band off and another band on.

Ok… THAT should be fairly easy… its just too bad that “Xojo for iOS” is so terribly dependant on declares

I guess it’s time to look at some sample declarations.

Check your Xojo>Example Projects>IOS>Declares folder. There’s also something in the docs on declares somewhere.

On github search for “ioskit” it’s full of declares, made by json king and others on this forum. There is also more if you search “xojo ios” on github. Lot’s of examples there

Thanks Everyone.
I watched a video by Paul Lefebere and it is very similar to Windows Declares in VB. I have worked a lot with them over the years.
One thing I was wondering about, not a big deal, just curious. Why are the return types mostly defined as type ptr and not as a class that they create or return?

Technically, the ptr you see as the return type of many API methods is the object. When you are assigning objects, like

Dim aDate as Xojo.core.Date aDate = anotherDate // also Xojo.Core.Date
what you are doing is you make the class instance aDate point to the same memory space that anotherDate occupies. You usually don’t move an object in RAM but manipulate its handle.

Let’s say you are declaring into macOS where most of the classes inherit from the base object class NSObject. NSObject is known to macOS, but not to Xojo. So if you want to use properties and methods as a custom-built Xojo class, you have to build a wrapper class that uses declares to make the features accessible or the properties visible in debugger.

In Swift for example, you would be doing the same, only the object type declaration is sometimes a bit more implicit:

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in: self) // do something } }
(as a part of an iOS app) It is made clear to the compiler that the pointer array touches should be interpreted as an array of the UITouch class.
If Swift would not know the class UITouch, like when the programmer forgot to import UIKit, he would have to do exactly the same like in Xojo: Define a class that makes the features accessible (or use the ptr of the instance, the handle, as the input variable for system methods that are built for this class).

In short: The APIs do return ptrs and other basic data types only. The compiler needs to be told as which class to interpret the ptr.

One of the next features announced for Xojo are Interops that should do the conversion of system API values to Xojo datatypes automatically and make Declares easier.

Ulrich,
Thank you for taking the time to post. I really appreciate it. And Derk, thank you for the tip. I will search for that.

Regarding my last question, I realize that the pointer returned is a pointer to an object. I was just curious why it isn’t declared as a strongly typed object.
In other words instead of
Declare Function CreateAThingy Lib “Foundation” () As Ptr
Dim MyThingy as Pointer = CreateAThingy()

it would be
Declare Function CreateAThingy Lib “Foundation” () As Thingy
Dim MyThingy as Thingy = CreateAThingy()

It’s probably because the compiler doesn’t know what a “Thingy” is. It would have to be defined or imported somewhere within the Xojo scope.

While I have your attention, I do have one more small question.

In the examples I have seen so far, the declares have been included within the function (usually the action method) . In VB, we always put them outside of the function at the top of the module declared as private or in a separate module declared as public. I’m just wondering if it is something that would be used in multiple places if it should be declared at a higher level.

Thanks again guys!

[quote=384053:@Martin America]Ulrich,
Thank you for taking the time to post. I really appreciate it. And Derk, thank you for the tip. I will search for that.

Regarding my last question, I realize that the pointer returned is a pointer to an object. I was just curious why it isn’t declared as a strongly typed object.
In other words instead of
Declare Function CreateAThingy Lib “Foundation” () As Ptr
Dim MyThingy as Pointer = CreateAThingy()

it would be
Declare Function CreateAThingy Lib “Foundation” () As Thingy
Dim MyThingy as Thingy = CreateAThingy()

It’s probably because the compiler doesn’t know what a “Thingy” is. It would have to be defined or imported somewhere within the Xojo scope.

While I have your attention, I do have one more small question.

In the examples I have seen so far, the declares have been included within the function (usually the action method) . In VB, we always put them outside of the function at the top of the module declared as private or in a separate module declared as public. I’m just wondering if it is something that would be used in multiple places if it should be declared at a higher level.

Thanks again guys![/quote]
You can’t make a declare return a Thingy because the declare doesn’t return a Xojo object, it is returning a pointer to an NSObject from Apple, which would still be distinct from a Xojo object called NSObject.

If you take a look at iOSKit (easily found through google or the link on my profile) you’ll see a couple of declares are declared globally, specifically those which are most frequently used. It is entirely up to you where you put them, but I try to hide my declares behind functions since they often have the same name and I want people to call the Xojo function instead of being confused, calling the declare, and having nothing work.