22

According to the iOS Device Compatibility Reference, the iPhone 3GS was the only iOS 6-capable device to lack a front camera. The same document states that your application can declare the requirement for a front-facing camera by setting the UIRequiredDeviceCapabilities key such that front-facing-camera is true. That way, you can safely strip out the ...


21

The current range of iOS devices that support 7.0+ don't include any devices that lack a front-facing camera. I also agree with you that it is unlikely that Apple will release any future devices without the front-facing camera (though not impossible). Even if they do, however, you could and should specify that your app requires this hardware in the ...


16

Your algorithm tries to find the largest factors first. This is ineffective because you have to test each possible factor whether it is a prime number or not. It is much more effective to start with the smallest factor. If you divide the number by each factor found this way then you will get only prime factors, and the prime testing function isPrime() ...


15

for(int i = 1; i <= 19; i++) { i = ( i%2 == 0 && i!=19 ) ? i+1 : i; [waitFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"lev_wait2%04d.png", i]]]; } Holy Toledo. First of all, if you must update the iterator within a for loop, let's leave the update statement empty: ...


14

In GitHub for Mac, we use a combination of AFNetworking and our own Mantle and ReactiveCocoa frameworks for API requests. AFNetworking makes it trivial to create your own "network manager" type object as a subclass of AFHTTPClient. We enqueue requests on it, ask them to hand back a certain kind of MTLModel subclass, and then subscribe to the resulting ...


13

I will update this post over the weekend as I go through your question more and come up with some examples to iterate over my points, but I thought for now, I'd answer some of the easier questions. Question 1. I'm not sure and cannot remember (I will try to find out). At the end of the day, you might consider implementing this with a GUI. If you're using ...


13

Because this question is so, so large, I won't get into all the specifics of everything I see. I will point out some things, and provide some examples from one file or another, and as you work through my answer, you should work through your project to find all the other instances of an example I point out. I will start with a simple answer to the topic ...


13

I'm just a beginner myself but I feel like I can point out a few things in this code. First, I would add some white space at the top of the file here: #import "ESFlashingErrorBar.h" #import "ESThemeManager.h" @implementation ESFlashingErrorBar #define kNumOfPoints 7 int lastFlash; Instead I would do this for increased readability: #import "...


12

Assuming the values under the id keys always match properties of currentAppswitches. If you can change currentAppswitches's class to accept an NSNumber object rather than a BOOL you have some convenient options. If currentAppswitches is KVO compliant you could write: for (NSDictionary *item in switchesArray) { id value = [item objectForKey:@"value"]; ...


11

You're right. There is a simpler way. First of all, instead of giving every interactive element its own method, let's give them all the same method. - (IBAction)buttonPressed:(id)sender; If they're not all buttons, a different method name is in line, but for this example, I'll assume them all to be buttons. Now then, whether you're creating these UI ...


11

-(id) initWithWorldSizeForCharacter:(CGSize)worldSize andStartingFloor:(int)startingFloor; It's slightly better to use instancetype as the return type here rather than id. What we're actually returning (here) is a DTEnemyMovement object, but explicitly listing this as the return type is problems when subclassing because we're returning the super type ...


11

Using a property for the boolean attribute is fine. Properties have many advantages: they encapsulate an objects value (i.e. the actual implementation is hidden from the outside, it need not be an instance variable), they are public (instance variables are by default not visible from other classes), they can be observed (via Key-Value Observing). In the ...


11

The problem of formatting an ordinal number is a general one that applies to more than just 31 days of a month. You also have repetition of much of the string @"Today is the %lu?? day of the month". Therefore, I suggest defining a separate function for handling this problem. Taking inspiration from NSNumberFormatter and 'th' 'st' 'nd' 'rd' (ordinal) ...


10

Instance Variables and Properties Understanding exactly what a @property is is absolutely crucial to being a good Objective-C programmer. Here's my crash course. An instance variable is just that. An instance variable. It's pretty straight forward. It's just a variable in that can be accessed by all the methods in your class. And if it's a public ...


9

This is the the way singletons are usually implemented in apple's code samples. + (ItemsManager *)sharedInstance { static ItemsManager *sharedInstance = nil; static dispatch_once_t once; /* Doing the allocation inside dispatch_once queue ensures the code will run only once for the lifetime of the app. */ dispatch_once(&once, ^{ ...


9

I don't like that you've implemented logic in Main. Move the logic into a FizzBuzz method and call that from Main. (Even though it seems really silly for such a simple program, it's not best practice to have it there.) I'm also not a fan of hard coding 15 as the "FizzBuzz" case. What if we decide that Fizz should be 2 and Buzz should be 5? Now 15 as your ...


9

@property You declare properties in the header file, but you don't actually use them as anything more than instance variables, which suggests you may not quite understand their full power. An Objective-C property is three things. An instance variable A setter A getter When you write @property int numerator;, you have created all three of these things. ...


9

The correct way to check for success or failure of Cocoa (Touch) methods is documented in "Handling Error Objects Returned From Methods" in the "Error Handling Programming Guide": Important: Success or failure is indicated by the return value of the method. Although Cocoa methods that indirectly return error objects in the Cocoa error domain are ...


8

Winston's answer points out some improvements to your algorithm. There are other ways in which we can slightly improve the speed of this. In Objective-C, for loops (and while and do...while) loops are handled one iteration at a time and the exit condition is checked on each iteration of the loop. Meanwhile, a forin loop is handled in batches. When we're ...


8

When you have something like this in your code: - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } You can simply delete all 5 of these lines. The only reason to include the the stub for - (void)didReceiveMemoryWarning is if you're actually going to add code to the method. int ...


8

Now, given that basically all Objective-C is written to make use of Cocoa frameworks, and we're talking about programs to run on OSX or iOS, we have to discuss Apple. Apple is pretty consistent when their method naming conventions, and their way of doing things. So any conversation about Objective-C standard practice would be incomplete without a very ...


8

A slightly better option that takes a little more effort up front but saves a lot of time in the long run, and makes the code more readable (and the obfuscated word harder to crack) would be to follow this pattern... First, create an NSString class category and fill that category with a readonly property for every character. @interface NSString (Obfuscater)...


8

@property (retain) id chessdelegate; There are several things wrong with this line. retain - While this technically still is a property attribute, it has been replaced by strong. It does the exact same thing as strong, but strong is the vastly preferred term here. retain or strong are both wrong here anyway. Any delegate property should ALWAYS be weak or ...


8

+ (instancetype)screenshot; While it is good to use the instancetype as your return type to allow for subclass, there are two problems using it here. First, this is a class category, not a class, and the only way for a category to be included in a subclass by default is kind of hacky. You just import the file the category is in in the subclass's header. ...


8

In both cases, this is exactly the most efficient way for removing a substring from a string. In practice, I'm not sure how practical or how frequently you'll truly need to be using the second example, and for most of us, simply doing this: string1 = [[string1 stringByReplacingOccurrencesOfString:@"aaa" withString:@""] mutableCopy]; is a bit easier to ...


8

You have no curly braces! You should be sure to include curly braces. For one, it prevents mistakes when you want to go back and add some logic into one of these if statements in the future, and for two, since we're talking about Objective-C and you're almost certainly using Xcode, it makes the code collapsable. I know, for some reason, that main drops ...


8

Before I comment on performance, I want to comment on style and naming and such. First and foremost, let's not use single letters for variables. They're meaningless. It's hard to follow what's happening in your code when it's just a handful of letters. Longer variable names has ZERO impact on the runtime performance of your code, but makes a massive ...


8

A few notes: I feel like some of your properties should have the readonly attribute applied to them. Do we really want the API users to have the ability to change the username, password, or server variables after initialization? @property (nonatomic, strong, readonly) NSString *server; If you do really want them to have that ability, I would add a method ...


8

Feedback on the algorithm //Check if even or ends in a five if ((n % 2 == 0 && n > 2) || (n > 5 && n % 10 == 5)) { return 0; } The part which checks if your number is divided by 5 makes very little optimization, since it's checked on the second iteration of the loop which follow. for (long i = 3; i <= u; i+=2) if (n % i ==...


8

Given that this answer is marked with the c tag, and the user quite appropriately points out that the code is 99% c, I decided that it might be worthwhile to demonstrate how simple the C solution to this problem is. There are only two aspects of Objective-C the user uses. NSMutableArray. This is convenient and it handles the resizing of the array for us. ...


Only top voted, non community-wiki answers of a minimum length are eligible