Go Down

Topic: Apple swift (Read 2 times) previous topic - next topic

mistergreen

I'm reading up on apple's new C language, Swift. It can return from a function multiple values with any combination of data types.

That is all. I'm sold!

leo72

The Swift programming language is the successor of Objective-C, I think it's not a C-family member but a C++-family member.
It has been developed to update the old-fashioned Obj-C and to result more easy and clear in use than it.
I didn't try it yet but voices on its performances are constrasting: someone says that it's faster than Obj-C, someone else says it's slower...
The only thing that it's clear is that it's an Apple-only language, due to the fact that it will run only on MAC/iOS.

mistergreen

yeah, it's iOS, OS X only which is a shame. It should be platform independent.

leo72

It's very friendly, it has a syntax that remembers me that one of Ruby.

mistergreen

I'm skimming through the use manual now. It's simple and powerful. It takes a little getting use to even for me since I know objective C.

mistergreen

I see a lot of rookie mistakes here on the forum like
Code: [Select]
if (x = 1)
C allows for this without throwing any errors. In swift this is illegal and will error. Neat change.

leo72

IMHO that should not be considered an error at all (I mean in the "C world"). I mean, it's legal even it's not logic. Who would have to know if an assignement has been done or not? In the other hand, who would have to do an assignement in an equality testing?
Why did they use two different symbols? I understand that there are historic considerations behinds, but I do not know them  ;)
Personally, I began programming with BASIC, and used the "=" sign both the operations, and I disagreed the way C interpretes those operands.

mistergreen

#7
Jul 06, 2014, 07:48 pm Last Edit: Jul 06, 2014, 07:52 pm by mistergreen Reason: 1
In swift you can do
Code: [Select]

if var x = 1


or

Code: [Select]

if let x = 1 //let is const in C

and that would be legal. I'm not sure how declaring the variable in the if condition works but that's legal.

I guess declaring a variable in the condition would be an automatic true?

mistergreen

#8
Jul 06, 2014, 09:08 pm Last Edit: Jul 06, 2014, 09:12 pm by mistergreen Reason: 1
Oh btw, the datatype on variables are assumed like

Code: [Select]
var x = 1
The compiler assumes x is an int since you assigned it an integer but you can you can manually do it too.

Code: [Select]
var x: Int = 1

pYro_65


In swift you can do
Code: [Select]

if var x = 1

I guess declaring a variable in the condition would be an automatic true?


Its no different to C++:

Code: [Select]
if( int x = 1 )

Dunno about swift, however, C++ will return false if 0 was assigned.

Quote
Oh btw, the datatype on variables are assumed


C++11 has the 'auto' data type.

I'll stick with my platform independent stuff for now.

mistergreen



Code: [Select]
if( int x = 1 )

Dunno about swift, however, C++ will return false if 0 was assigned.



In swift an int 1 and 0 can't  represent true and false respectively. Only Boolean values.

Go Up