Xcode Objective-C equivalent of visual studio's [DebuggerHidden] attribute - objective-c

In visual studio, when programming with C# (or other .NET languages), one can apply an attribute to a method which causes the debugger to ignore it. [DebuggerHidden] or [DebuggerStepThrough] both allow this in C#.
Is there an equivalent when working with Objective-C code using Xcode 5?
Example to illustrate the behaviour
void Main() {
Print("GetNumber returns: ", GetNumber());
}
[DebuggerHidden]
int GetNumber() {
return 42;
}
void Print(string s, int n) {
Console.WriteLine(s + n.ToString());
}
Without the [DebuggerHidden] attribute, when stepping through the code using "Step Into...", control flow goes like this:
Main
GetNumber
Print
With the attribute, the debugger skips GetNumber, and goes straight from Main to Print.
This is very useful for ignoring trivial method calls such as property getters, etc.
I have some various such trivial methods that I'd like to make the debugger skip past in Xcode if possible.

Related

Is IntelliJ showing wrong code completion?

I encountered some weird behaviour with latest version of IntelliJ IDEA. I have small private java library, and when I try to use it in other project, IntelliJ shows wrong method parameter names. More here on the picture:
wrong IntelliJ code completion
Notice that when I do it like this it works as it should:
good intellij code completion
Can I configure the IDE so it would display it like on the second picture, or is it a bug/intended behaviour?
Edit:
Combinatorics is an interface. CombinatoricsImpl is class implementing that interface and have method getCombinatorics, that return new instance of CombinatoricsImpl.
public static Combinatorics getCombinatorics() {
return new CombinatoricsImpl();
}
Interface (without javadoc):
public interface Combinatorics {
double combinationsNonRepeating(int n, int k);
double variationsNonRepeating(int n, int k);
double permutationsNonRepeating(int n);
double combinationsRepeating(int n, int k);
double variationsRepeating(int n, int k);
double permutationsRepeating(List<Integer> frequencies);
}
The method getCombinatorics() is not return an object of type Combinatorics. That is why it is not working in the first image.
In the second image, you are casting it into an Combinatorics object type. So it is working in the second image.
I don't think there is anything wrong with the ide here.

In Managed C++, what is the proper way to define a static singleton instance in a class?

Jumping to Visual Studio 2015 from Visual Studio 2013, I've noticed some differences in how static self-instances in managed C++ classes are accepted by the compiler. Consider these two examples:
Method 1:
public ref class CResourceManager
{
public:
static property CResourceManager^ Instance
{
CResourceManager^ get() { return %m_Instance; }
}
private:
static CResourceManager m_Instance;
};
Method 2:
public ref class CResourceManager
{
public:
static property CResourceManager^ Instance
{
CResourceManager^ get() { return m_Instance; }
}
private:
static CResourceManager^ m_Instance = gcnew CResourceManager;
};
Method 1 used to work on 2013, but it's failing to compile on 2015. I unfortunately do not have the exact compiler error handy, but it was one of those "Missing semicolon before variable name" errors, basically saying it couldn't find the type CResourceManager (pointing to the static variable declaration).
So on to my questions:
Is method 1 supposed to work or be valid in managed C++?
Why would the second method work in 2015, but not the first (i.e. what are the differences)?
Which method is the proper way to accomplish the end goal?
Method 2 is the proper way to do it. The code you have listed is the equivalent of the C# idiom.
Method 1 is a bit unusual.
The lack of a ^ on a declaration would normally mean that the variable is not allocated on the managed heap. However, since it's a static class member, I'm not sure where it actually gets created.
% is normally used for declaring tracking references, the equivalent of passing a variable by ref or out in C#. To be honest, I didn't think that applying % to a variable without either ^ or % and taking the result as a ^ was even valid. (Though considering the 2015 compiler rejects it, it may not be.)
Even if Method 1 is valid, I'd still go with Method 2: The storage location of m_Instance and how it's returned are both plain, common, and easy to understand. This beats having to think about how the code works any day.

Cannot assign to an element of an initonly array?

It seems commonly thought that C++/CLI's initonly is the equivalent of C#'s readonly keyword. However, the following:
ref class C {
C();
void Method();
initonly array<int>^ m_array;
};
C::C() {
m_array = gcnew array<int>(10);
}
void C::Method() {
m_array[0] = 5; // Fails with C3893
}
The full error is "'C::m_array': l-value use of initonly data member is only allowed in an instance constructor of class 'C'".
The error message seems strange as I'm not using m_array as the target of an assignment, this is the equivalent of writing
m_array->SetValue(5, 0);
which incidentally compiles fine and does the same thing.
Is this bugged in C++/CLI or by design? By the way, is there any performance penalty to using Array::SetValue vs using the accessor?
A similar (but not identical) case was reported and apparently filed as a bug for VS2008: http://bytes.com/topic/net/answers/847520-initonly-but-not-bug-vc-2008-clr . I'm using Visual Studio 2012.
Yes, that's a bug. It's enforcing something which is not implied by the .NET type system, and the enforcement is ineffective.
But don't use Array::SetValue, which involves boxing and is not type safe. You can just do:
auto array = m_array; // another handle to same array
array[0] = 5;

MouseButtons::Left in c++/cli

I would like to check the left button is the pressed one.
I red on Msdna:
if(e->Button == MouseButtons.Left) {...}
//or
if(e->Button == ::MouseButtons.Left) {...}
But no one of them compiles.
This is an annoyance of the C++ language, inherited by C++/CLI. It puts the names of types and the names of class members in the same symbol table. This is something you'll battle often when you write Winforms code in C++/CLI instead of C# or VB.NET, languages that keep type identifiers separate.
There's an ambiguity between the MouseButtons enum type and the Form class' MouseButtons property, they are both in scope here. IntelliSense stops helping you to get the syntax right which is probably how you ended up with . instead of :: Leaving no odds anymore to get a decent compiler error message. You resolve the ambiguity by writing the enum type name in full:
if (e->Button == System::Windows::Forms::MouseButtons::Left) {
// etc...
}
Problems like these are probably one reason that C++/CLI never got very popular. Then again, C# is rather a class act. Recommended.
You need to hook the event on control you want:
this->control->MouseDown += new System::Windows::Forms::MouseEventHandler(this, &Form1::control_MouseDown);
and handle it like this:
void control_MouseDown(Object* sender, System::Windows::Forms::MouseEventArgs* e) {
if(e->Button == MouseButtons::Left) {
//code here
}
}

Can method parameters be dynamic in C#

In c# 4.0, are dynamic method parameters possible, like in the following code?
public string MakeItQuack(dynamic duck)
{
string quack = duck.Quack();
return quack;
}
I've many cool examples of the dynamic keyword in C# 4.0, but not like above. This question is of course inspired by how python works.
Yes, you can absolutely do that. For the purposes of static overload resolution, it's treated as an object parameter (and called statically). What you do within the method will then be dynamic. For example:
using System;
class Program
{
static void Foo(dynamic duck)
{
duck.Quack(); // Called dynamically
}
static void Foo(Guid ignored)
{
}
static void Main()
{
// Calls Foo(dynamic) statically
Foo("hello");
}
}
The "dynamic is like object" nature means you can't have one overload with just an object parameter and one with just a dynamic parameter.
See documentation http://msdn.microsoft.com/en-us/library/dd264741(VS.100).aspx
Yes, you can do that. As stated in C# 4.0 specification, the grammar is extended to support dynamic wherever a type is expected:
type:
...
dynamic
This includes parameter definitions, of course.
Yes; see e.g.
http://blogs.msdn.com/cburrows/archive/2008/11/14/c-dynamic-part-vi.aspx
or Chris' other blogs. Or grab VS2010 Beta2 and try it out.