Objective C - Difference Between VARType* vt and VARType *vt [duplicate] - iphone

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Placement of the asterisk in Objective-C
What is the differenct between the following:
(Assume we have a class calculator)
Calculator* calc;
Calculator *calc;
Also what is the need for pointers? Is it not possible to omit the star?

There is no difference between those two declarations, you could also do Calculator * calc if you're feeling adventurous.
As far as if you can omit the star, no, you cannot. It is a carry over from C and shows that calc is a pointer to a Calculator, and not a Calculator itself.

There is no difference between the 2 declaration is just an preference for typing.
Every thing on computers uses pointers. You need pointers java, c#, etc use pointers.
No is not posible to omit the star.

Related

Repeatable random data generation in Swift 4 [duplicate]

This question already has answers here:
Swift - Seeding arc4random_uniform? Or alternative?
(2 answers)
ios Swift: looking for a cross compatible method to Java's Random() PRNG that has identical output
(3 answers)
Closed 4 years ago.
I'm writing tests in Swift 4. I want to generate thousands of rows of test input data. I want the test input data to be random.
But I want my tests to be repeatable: the same data needs to be generated for each run of all tests.
How is this achieved in Swift? In Java I've always relied on the Apache commons RandomDataGenerator. I've explored arc4random and drand48, but these don't seem to provide the repeatability I require.
Swift has no native random number generation capabilities. You can call C library functions from Swift, though. Any page on C random number library functions will describe them to you.
For example, you could just seed srand48 with the same constant every time and call drand48 to get your numbers.
(1...3).forEach {_ in
srand48(100)
(1...3).forEach {_ in print(drand48())}
}
/*
// spot the repetition:
0.25105890266514
0.208948404851498
0.940927909958315
0.25105890266514
0.208948404851498
0.940927909958315
0.25105890266514
0.208948404851498
0.940927909958315
*/
Some other C library functions are unavailable from Swift so you'd have to write that part of the code in C. No big deal.

what is meant by the objects starting with ^ in objective c [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Caret in objective C
I recently came across some line of code and found out that it has ^ sign in front of an object like this one:
typedef void (^AnimatedViewBlock)(CGContextRef context, CGRect rect, CFTimeInterval totalTime, CFTimeInterval deltaTime);
#interface AnimatedView : UIView
Can anyone explain it with simple example about the same.
It denotes a block object.
Read Apple's documentation here.
It is so called block.
Objective-C kind of closure.
Docs here
The symbol you are referring to denotes the start of a block in objective-c. They are primarily used in Grand Central Dispatch in ios but you can use them elsewhere as well.
As John Muchow writes:
A block is really nothing more than a chunk of code. What makes them
unique is that a block can be executed inline as well as passed as an
argument into a method/function. Blocks can also be assigned to a
variable and called as you would a C function.

What's the point of #syntheisze abc = _abc;? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What does #synthesize window=_window do?
Question about #synthesize
Some developers tend to use this convention:
#syntheisze abc = _abc;
What is the true benefit of this? Why do they do it this way? The first thing I notice is that it makes the code a lot harder to read.
This is a common code convention:
See this Google Objective-C coding directives:
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml?showone=Properties#Properties

Why does objective C does not support overloading? [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Why Objective-C doesn't support method overloading?
I was going through this link which has the answer to my question. But I was not able to understand what the right guy is trying to say. It will be really great if someone can simplify and provide an explanation.
In C++ the compiler has type information and can choose between several methods based on the types. To do the same in Objective C it would have to be done at run-time, because the compiler knows little about object types due to the dynamic nature of the language (i.e. all objects are of type id). While this seems possible, it would be very inefficient in practice.
I think it's a historical artifact. Objective-C is derived from C and Smalltalk, and neither of them support overloading.
If you want overloading, you can use Objective-C++ instead. Just name your sources with the ".mm" extension instead of just ".m".
Just be careful to be sure you know what you are doing if you mix C++ and Objective-C idioms. For example Objective-C exceptions and C++ exceptions are two completely different animals and cannot be used interchangeable.
What he is trying to say is that method overloading is not possible with dynamic typed languages since in dynamic typed languages the information about each of the object is not known until run time. In a statically typed during compile time the overloading can be resolved. You will just create the same functions with same names but the compiler would have enough information to resolve the ambiguity between various calls which it gets. But in dynamic typed languages since the objects are resolved only during run time it is not possible to resolve between the various calls.

function vs property? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is Method, Property and Function ?
Can anyone tell me what is function and what is property?
Just a basic explanation.
Property denotes the object's state, Method denotes the object's behavior. Function is like method except for that it's not dependent upon an object (I'm guessing you don't really mean that).
For example, if you have a Car class, a property may be it's model, it's year, it's current speed etc., a method may be Stop, Drive etc.
see msdn: Properties, Methods
Additionally, pragmatically, properties will 'interact' with some tools. For instance, they will show up in the Properties window of VS.