iOS is an operating system for mobile devices developed by Apple Inc. that is currently used in their iPhone, iPod touch, iPad, and Apple TV (2nd generation) devices. It shares a lot with Mac OS X, but is optimized for touch-based interfaces.
1
vote
0answers
20 views
Canonical Implementation of a Subclass of NSOperation
I would like to develop a kind of template or canonical implementation for a concurrent subclass of NSOperation.
Requirements:
Thread safe API.
start shall only start the task once, otherwise it ...
3
votes
2answers
30 views
Multiple serial URL requests in Objective-C / iOS
I want to check the existence of various API endpoints by doing serial URL request. If the first one fails, I want to try the second one, if the second fails I want to try the third one, etc.
Here is ...
2
votes
1answer
48 views
iOS / Objective-C Basics
Coming from Java & Android development and Objective-C still is a bit strange to me, but I just went in head first and started writing code. Before I started getting really far into it, I just ...
2
votes
0answers
49 views
applicationDidBecomeActive: Am I causing a memory leak?
in an ios app I´m calling this function everytime the app gets opened in the applicationDidBecomeActive: function. I´m using ARC. My concern is it could create a memory leak because it´s creating new ...
1
vote
0answers
42 views
Sample design Oauth2.0 flow
I have the following code that I hope developers will use.
[LKOauth showLogin: self data: data
success: ^(NSString * code) {
NSLog(@"%@", code);
}
...
1
vote
1answer
80 views
A better way to handle web services in an iOS app?
I'm building an iOS app that uses web services extensively. I've built classes that handle the requests. However since there are a lot of web service request - I need to find out how to detect which ...
1
vote
1answer
176 views
I subclassed AFNetworking to handle POST / GET requested - doing it wrong?
So I am pretty new to iOS development - I'm writing an app the uses web services, pretty extensively. With that in mind, I decided to use AFNetworking 2.0 and subclass AFHTTPSessionManager.
I ...
1
vote
0answers
65 views
I need code review on using singleton to access local database
As I get to some performance issues in my app and find that I use database access in a bad way.
So I decided to move to singleton pattern.
I need someone to review this code and confirm me that I made ...
4
votes
2answers
375 views
iOS: Code review of MasterViewController
I plan on including this work in a portfolio.
Question: Will this code get me hired or laughed at?
More Specifically:
How would you rate the general complexity of the code?
How bad does the code ...
1
vote
1answer
116 views
iOS App ViewController Refactoring Guidance
My question is: How can I most effectively refactor the code in these 2 ViewControllers. I'm familiar with subclassing in objective-c and have used it extensively else where with NSObjects and ...
1
vote
1answer
131 views
Asynchronous networking IOS API calls
+ (void) makeRequestToEndPoint:(NSString *) endpoint values:(NSMutableDictionary *) params onCompletion:(SDKCompletionBlock) responseHandler
{
NSString * urlString = [self ...
3
votes
1answer
43 views
Is there a better way to make sure a variable is initialized when using blocks?
I have a method to provide an NSManagedObjectContext using UIManagedDocument. I need to ensure that the context did initialize before I return, so I added an infinite while loop at the end of the ...
1
vote
1answer
84 views
AutoreleasePool NSString Automatic Reference Counting
I have some doubt about how NSString is released in ARC Mode.
I would like to know if have something i can do to release a nsstring when i want in arc mode.
Take a look at this code:
__block ...
2
votes
1answer
167 views
Refactoring to avoid if-else in numberOfRowsInSection and cellForRowAtIndexPath
Below is the code that I would like to refactor in order to avoid if-else statements in cellForRowAtIndexPath and numberOfRowsInSection.
Depending upon what user selects, section order and ...
2
votes
1answer
150 views
Pulling Objects & Values From Arbitrarily Nested JSON
I got tired of stringing together objectAtIndex: and objectForKey: and hoping nothing fails along the way. I parse a lot of JSON from sources like the Google Directions API and it was cluttering my ...
0
votes
3answers
143 views
Objective-C class for placing UI elements based on screen size
I'm always programmatically creating and laying out UI elements in multiple ViewControllers and I've wanted an easy way to get relevant Screen information (sizes/points) globally using a helper class. ...
0
votes
0answers
203 views
SDWebImage - Fetch more images
What I am looking to do is, apart from setImageWithURL method of SDWebImage, load other images from the array of URL's.
So, in the completion block of setImageWithURL, I call a method ...
0
votes
0answers
67 views
Select first or last object from id<NSFastEnumeration>
So I found this code in our project and it just feels like the wrong way to do what its seems to be doing
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
...
1
vote
0answers
43 views
Is this proper code for removing a CCSprite under certain conditions?
This is a "answer" to my own question over at stackoverflow, head over there to see what I am trying to accomplish. ...
3
votes
1answer
25 views
Creating an expanding CCSprite cluster
I am creating an "explosion" of circle sprites from the character with this code, and I was wondering if there is a more effective way to do such things, because this just seems too stupid.
(This is ...
1
vote
1answer
324 views
How can I improve below Objective-C code to tint an image?
I have an image which is a black ring:
In my view, I need to display it as a white ring. So, to tint the image, I have written the below method:
- (UIImage *)getRingImage
{
UIImage *ringImage ...
0
votes
0answers
83 views
Class Designin patterns: how to design reusable classes
I want your opinion if this is decent design and how I can improve it if need be. I got the two classes DigBackground and DigParallaxBackgroundLayer (A parallax background is a image consisting of ...
2
votes
1answer
55 views
A structure and helper functions for working with polar coordinates
Cross posting from Stack Overflow (not sure how to more correctly cross-post).
This started simple, as most things do...
I just wanted a little structure to hold polar coordinates for a totally minor ...
2
votes
2answers
244 views
iOS/Objective-C “if” best practice
I've got this code that I found in a project and I'm wondering how can it be done better:
- (void) setAlpha:(float)alpha {
if (self.superview.tag == noDisableVerticalScrollTag) {
if ...
-3
votes
1answer
174 views
iOS multiplayer pong game [closed]
I was trying to make a multiplayer Pong iOS app and ended up with this. It is almost good, except for one big bug. The 2nd player's paddle is moving the same way with yours. Basically, you're ...
1
vote
1answer
76 views
Is there a more optimal way to write the following encoding and then assign the result to a label?
Is there a more optimal (or concise) way to write the following:
I have to do some encoding and then assign the result to a label.
// encoding fix
NSString *correctStringTitle = [NSString ...
2
votes
1answer
55 views
A better approach to coding the a string value test for a NSDictionary object
My conditional code here seems repetitive and long. Is there a better approach? I want to test for a string value in a NSDictionary object and then depending upon the value prefix a UILabel with $, £, ...
1
vote
2answers
335 views
Optimizing iOS method in objective-c
I have such method and have a hard time optimizing it to run better. It takes roughly 1 sec with 100 units to get between NSLog(@"Debug2") and NSLog(@"Debug3"). And 2 sec on iPhone.
Method idea:
...
0
votes
2answers
893 views
iOS View Controllers - Default Lazy Loaded Properties (Tab Bar Item & Navigation Item)
It is a little thing about UIViewController, but it has always bothered me - the boilerplate code needed to setup some of a view controller's default properties (e.g. the tab bar item and navigation ...
2
votes
2answers
154 views
Need an Obj-c code review for core data implementation
I'm just beginning my foray into iOS development and need a code review. I have a custom NSManagedObject that needs some smart setters. New to obj-c, iOS, and core-data development, I don't trust ...
1
vote
1answer
110 views
Optimization of percent match code xcode
I have the following method that will take the car parts I searched for and match them to my car object in array. Then it tells me the percent match.
Example
Car.h has NSSet toCarParts. toCarParts ...
2
votes
1answer
170 views
Initialize a bunch of NSDateComponents objects at once (in a loop)?
I'm developing an iPhone app that is heavily Calendar-based, and it requires a good amount of (what I'm calling) "date boundaries."
I use these "date boundaries" to fetch EKEvents from specific ...
2
votes
1answer
199 views
Testing the same code with different input data
I would like to get an advice regarding how to test the same code with different input data.
I would like to test that method operationSucceeded will be invoked for all successful status codes. Here ...
2
votes
1answer
129 views
Rot47 an NSString Category
As a JAVA native, i am always a litle worried when doing objective-c... memory leaks and pointers flying at my head...
All comments are welcome on the Category below, the Category functions are ...
1
vote
2answers
48 views
NSArray and NSNumber-int conversions
I have a textView which is displaying a string. I also have an array which keeps track of where every line begins, it stores the "start index" or NSRange.location for every line.
However, when text ...
1
vote
1answer
328 views
is my date difference calculation correct?
-(NSString *)calculateTimeDifference:(NSString *)timeStamp{
// get the current date
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat ...
4
votes
2answers
2k views
Dependency Inversion / Injection? - Networking code in model classes
@implementation User
- (void)refreshProperties
{
assert(!self.isSyncing);
NetworkOperation *op = [[NetworkOperation alloc] initWithEndPoint:GetUserDetails parameters:nil];
[self ...
1
vote
1answer
260 views
iOS UITableView; saving cell checkmarks to disk
As per suggestion on SO, I am posting my code here to be reviewed. It was said I should not be saving and reading from disk so many times when a user selects and deselects a cell in my tableView.
...
1
vote
1answer
334 views
How to optimize loading of images? (especially cocos2d)
So i recently started game development (which is freaking awesome), but one of the things that i never put much thought to was the loading of images. i'm curious as to advice for improving my current ...
6
votes
2answers
716 views
Custom numberpad on an iPad
I'm an active user on SO, however I just found this site and this is my first question here. I am a self-taught programmer who has been programming for a long time, but mainly just for personal ...
3
votes
1answer
163 views
Improving calculation code
I'm making a converter app, and after realising I would have to type about 200 lines of code to get it working with more than 5 units converted, I should have a better conversion calculation.
What I ...
4
votes
2answers
284 views
Age verification in Objective-C
I'm creating some age-verification functionality for an iOS app. The user is presented with a UIDatePicker object, and the latest selectable date should be today minus 18 years. How vulnerable to ...
5
votes
2answers
188 views
Am I reconstructing the buffers correctly
I am writing a networked audio application that sends the audio in 320 byte chunks, later I need to provide the player a bigger amount of bytes to play so I try to merge 2 or more chunks into one ...
5
votes
1answer
100 views
iOS: Upgrade this animation code
I understand that this animation code is outdated:
[UIView beginAnimations:@"Move" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelay:0.08];
...
1
vote
0answers
129 views
Core Data code for manually creating a lot of entries from old ones
Does this looks ok to everyone?
NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *oldEntryEntity = [NSEntityDescription entityForName:@"Entry"
...
2
votes
2answers
369 views
Data model code review for iOS app
I'm new to iOS development and I'm having trouble figuring out how to efficiently load my app's data at launch time. My app consists of a UITableView that is populated with a list of songs. Each cell ...
2
votes
0answers
465 views
iOS: Parsing NSDictionary from NSJSONSerialization
playerObject is an NSDictionary from JSONObjectWithData:options:error:
I'm trying to update a CoreData entity. My code looks like this:
if ([results count] > 0)
{
newPlayer = (Player ...
1
vote
1answer
91 views
Efficiency of grid generated by for-in loop
I've spend the last several hours working on a loop designed to take items in an array and arrange them as a so to speak "gird" of UIButtons. As far as I've been able to see through testing this code ...
2
votes
1answer
216 views
Tips on good practice in my bash script that logs in to a website, downloads a PDF, adds it to iBooks and uploads it to dropbox
I am running a scheduled script on my iPhone that logs in to a website, downloads a PDF, adds it to iBooks and uploads it to dropbox. All of this happens only when it has WiFi access.
I want to make ...
15
votes
14answers
3k views
Bad Practice to have Long If-Else statements?
EDIT: One of the bigger questions I have is that, is using switch-case more efficient then using this?
Right now in my application (a weather app), I have one section of code in my View Controllers ...