Rectangle 27 3

I made this community wiki... Please edit it. I don't agree with the a...

Yes, i agree with Richard. You should never use 'int' as the counting variable in a loop like those. The following is how you might want to do various loops using indices (althought there is little reason to, occasionally this can be useful).

You can do this, which is perfectly defined behaivor:

for(std::vector<int>::size_type i = someVector.size() - 1; 
    i != (std::vector<int>::size_type) -1; i--) {
    /* ... */
}

Soon, with c++1x (next C++ version) coming along nicely, you can do it like this:

for(auto i = someVector.size() - 1; i != (decltype(i)) -1; i--) {
    /* ... */
}
'int'

The C++ Standard defines in 23.1 p5 Container Requirements, that T::size_type , for T being some Container, that this type is some implementation defined unsigned integral type. Now, using std::size_t for i above will let bugs slurp in silently. If T::size_type is less or greater than std::size_t, then it will overflow i, or not even get up to (std::size_t)-1 if someVector.size() == 0. Likewise, the condition of the loop would have been broken completely.

The appropriate type to use would be std::vector<T>::size_type, not std::size_t.

You are right. I confused it with string::size_type , which is always std::size_t. I will change it accordingly

Although I personally am not convinced about the advantages of using unsigned in C++ (i.e. the std::vector<int>::size_type solution does not prevent expressions based on the loop index to be promoted to unsigned quietly) I am accepting this answer as it gives a good overview of what one can do for others IMHO.

c++ - acceptable fix for majority of signed/unsigned warnings? - Stack...

c++ stl coding-style unsigned
Rectangle 27 37

KeychainItemWrapper was mostly working for me, worked on many email addresses (stored as username in kSecAttrAccount), but one email in particular did not work. I then added the above line for kSecAttrService and all is now perfect! -Thank you @user229688

Note that you have to set that before you set kSecAttrAccount and kSecValueData. Otherwise it will still crash.

How do retrieve this when next run of application?

I added that line of code before my line where I set kSecAttrAccount, and now it crashes on your line of code instead. Anyone else experiencing this?

objective c - Storing email in keychain impossible (KeychainItemWrappe...

objective-c ios automatic-ref-counting keychain
Rectangle 27 5

*edit: This advice applies to iOS <= 5 (even there you should be adding in viewWillAppear and removing in viewWillDisappear - however the advice applies if for some reason you've added the observer in viewDidLoad)

If you've added the observer in viewDidLoad you should remove it in both dealloc and viewDidUnload. Otherwise you'll end up adding it twice when viewDidLoad is called after viewDidUnload (this will happen after a memory warning). This isn't necessary in iOS 6 where viewDidUnload is deprecated and won't be called (because views are no longer automatically unloaded).

Welcome to StackOverflow. Please checkout the MarkDown FAQ (question-mark icon next to the question/answer edit box). Using Markdwon will improve the usability of your answer.

ios - Objective C: Where to remove observer for NSNotification? - Stac...

objective-c ios nsnotifications
Rectangle 27 4

Same thing here! You have to first Archive (Product menu->Archive) the app before attempting to distribute it. It's been quite a while since I pushed out a new version, so I forgot this step....

ios - bundle is invalid -- CFBundleVersion and CFBundleShortVersionStr...

ios xcode
Rectangle 27 4

Same thing here! You have to first Archive (Product menu->Archive) the app before attempting to distribute it. It's been quite a while since I pushed out a new version, so I forgot this step....

ios - bundle is invalid -- CFBundleVersion and CFBundleShortVersionStr...

ios xcode
Rectangle 27 55

Seeing as he has 229k reputation as of this writing, I would take his advice :-)

+1 Agree - not only is Jon Skeet a SO living legend, he's polite & funny.

discussion reputation article strategy
Rectangle 27 51

The other advice here didn't help me, but I fixed this error by going to Product > Scheme > Edit Scheme. Then I clicked Build on the left hand side and deselected any checkboxes next to AppNameTests. I'm using XCode 6.3

I did that, and had everything unchecked except Test. It turned out I had to remove a .plist file to get it to stop trying to code sign the test. My project builds a static library, so none of it needs to be codesigned.

Ahh okay. Well it sure seems like there are a lot of reasons this problem can be caused and just as many ways to fix it. If nobody else mentioned your solution, you might consider posting it as another possible answer.

objective c - Code signing is required for product type Unit Test Bund...

ios objective-c xcode
Rectangle 27 2

While I agree with you for larger projects, mine is very simple and easy to maintain and I do not want my users to have to install new software (such as Python, for SCons) just to run my utility.

Please show some evidence of that. (The equivalent of) Makefiles are the de fact industry standard. make may be relative basic but its still an integral part of the C++ tool chain and a good choice.

C++ Compile on different platforms - Stack Overflow

c++ cross-platform
Rectangle 27 19

Edit: Since the asker clarified he's not using garbage collection (iPhone currently does not support it), my advice is to avoid cycles by having only one of the objects retain the other, just as you would do with a delegate. When using properties, use "assign" instead of "retain" to achieve this. For example:

@property (nonatomic,assign) Row *yCoord;

When you're working with garbage collection (10.5+), a weak reference is created by prefixing a variable declaration with __weak. When you assign to that variable, the GC (if enabled) keeps track of the reference and will zero it out for you automatically if all strong references to the referenced object disappear. (If GC is not enabled, the __weak attribute is ignored.)

Thus, you can safely modify the above answer to play nicer with garbage collection (currently on 10.5+, and perhaps someday on iPhone) as follows: (See the related Apple docs.)

@property (nonatomic,assign) __weak Row *yCoord;

To quote Chris Hanson (where you can find more detailed information):

"By prefixing an instance variable declaration with __weak, you tell the garbage collector that if it's the only reference to an object that the object should be considered collectable."

I'd clarify that by saying "if there are no non-weak references to an object". As soon as the last strong reference is removed, the object may be collected, and all weak references will be zeroed automatically.

Note: This isn't directly related to creating weak references, but there is also a __strong attribute, but since Objective-C object variables are strong references by default, it is generally used only for raw C pointers to things like structs or primitives that the Garbage Collector will not treat as roots, and will be collected from under you if you don't declare them as strong. (Whereas the lack of __weak can cause retain cycles and memory leaks, the lack of __strong can result in memory stomping and really strange and insidious bugs that occur non-deterministically and can be quite difficult to track down.)

Let me clarify that this is for an iPhone application. I don't believe the iPhone uses a GC.

so instead of declaring Row *yCoord; with @property(nonatomic,retain) Row *yCoord; Do I do: __weak Row *yCoord; But then how do I declare the property?

You can mix @property and __weak: @property(nonatomic,retain) __weak Row *yCoord;

I appreciate the information but I don't think my problem has been addressed. I would like to implement a similar structure to delegates and subviews, but I have no idea how to declare the Row in the Block class as a weak reference so that the retain count is not incremented.

Thanks, I believe this is what I was looking for.

iphone - I have a circular reference. How can I create a weak referenc...

objective-c iphone weak-references circular-reference
Rectangle 27 1

The following code should do the work. the get_template_part is where it does the trick. Or you can edit the function from the wp code, but wouldn't advice on that.

<?php if ( have_posts() ) : ?>
      <ul class="articles clearfix">
        <?php
        /* Start the Loop */
        while ( have_posts() ) : the_post();
          printf('<li id="post-%2$s" class="article %1$s"> ',implode(' ', get_post_class()), get_the_ID() );
          get_template_part( 'template/content', 'brief' );
          echo '</li>';
          wp_reset_postdata();
        endwhile;
        ?>
      </ul>
      <?php else : ?>
        <?php get_template_part( 'template/content', 'none' ); ?>
      <?php endif; ?>

What can I do to don't show the author name and the date into this Wor...

php wordpress content-management-system wordpress-theming
Rectangle 27 1

The undefined comes up as in mate': undefined method allele' for nil:NilClass (NoMethodError), not from the delete call. The mate call is whats throwing it off, I think.

this is the sort of undefined behavior you can encounter by changing a list under the iterator.

Somehow not assigning a class with Ruby - Stack Overflow

ruby class typechecking genetics
Rectangle 27 1

Bootstrap popover not working Rails - Stack Overflow

ruby-on-rails twitter-bootstrap popover twitter-bootstrap-rails
Rectangle 27 1

Bootstrap popover not working Rails - Stack Overflow

ruby-on-rails twitter-bootstrap popover twitter-bootstrap-rails
Rectangle 27 1

You should probably be using the delegate pattern here (giving the child view controller a reference to an object that it can call on). If you edit your post to explain why you think you need a reference to the top view controller, we can give you advice about how to use the delegate pattern in your situation.

UIViewController *topVC = [UIApplication sharedApplication].keyWindow.rootViewController;

Get reference to top viewcontroller in iOS - Stack Overflow

ios