How to generate an guid on swift (xcode6)

Dear All,
I am just leaning the new language of Swift,
in Object C " clientID=[ROGuid guid];" that I can get an guid .
but in swift when use “clientID=ROGuid()” the clientID will be empty as :"{00000000-0000-0000-0000-000000000000}"
and I tried to use "clientID = ROGuid().guid() " but it can’t be compile .
how should we work with swift to generate the guid?
Thanks!
Jason

As answered per email, you’ll want

 clientID = ROGuid.guid();

adding () after ROGuid would create a new ROGuid instance, as that’s Swift’s constructor syntax. You want to call the static guid() method.

Dear mh,
I try the code” clientID = ROGuid.guid();”

But it has error for :’guid’ is unavailable:use object construction
‘ROGuid()’
Thanks!
Jason
Jasonli@go2cap.com

发件人: mh talk@remobjects.com
答复: RemObjects Talk
08a3c05f2755f14e73ca9b8c1ce00dda@talk.remobjects.com
日期: 2014年6月23日 星期一 上午6:00
至: li jason jasonli@go2cap.com
主题: [RemObjects Talk] How to generate an guid on swift (xcode6)

hmm, that is odd. That is the proper syntax. Looks like Swift trying to be too smart and mapping a class method to a convenience constructor. We’ll need to investigate and possibly change the API, if that is the case :(.

now I am using oc to create an object to call that method
And in my swift to call the oc object, it works but want to know if there is a better way to make it happen

Thanks!
Jason

fwiw, the new release, coming out later today, has this fixed, with a new method called createGuid() that’s callable from Swift directly and easily.

Hi mh,
many thanks for your help.

1 Like