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.
2
votes
0answers
15 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
42 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
136 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
107 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
103 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
138 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
45 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
35 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
24 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
212 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
55 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
52 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
196 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 ...
1
vote
1answer
75 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
45 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
278 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
706 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
135 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
82 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
153 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
179 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
116 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
1answer
42 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
266 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
187 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
299 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
639 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
155 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
1answer
251 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
183 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 ...
4
votes
1answer
94 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
95 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
1answer
314 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
397 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
89 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
202 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
2k 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 ...
2
votes
1answer
862 views
Optimize sorting of Array according to Distance (CLLocation)
Currently my below code takes an average 9.27300 every time I run it. This is an iOS application and I can't expect the user to sit there for roughly 10 seconds.
This code takes an array ...
1
vote
0answers
383 views
Core Data - Data Model Design - Bidirectional Ordered To-Many Relationships - Reduce Complexity and Reveal Intent
I have a Core Data model with two entities Video and Playlist.
A Video can be a member of many Playlists
A Playlist can have many Videos, including the same Video multiple times
A Playlist's Videos ...
2
votes
3answers
329 views
Standard delegate methods
I'm aware standard delegate method declaration should include the object that triggers the method, usually of the class that declared the protocol.
That's fine when the delegate method includes ...
5
votes
1answer
446 views
How quality is this piece of code?
I am contemplating working with a development firm, and had asked for this piece of sample code. Could you please take a look and let me know if this is a quality piece of work, or if it needs ...
1
vote
2answers
3k views
iOS4 alternatives for dismissViewControllerAnimated:completion:
My inspiration for creating this protocol came from iOS 5's "dismissViewControllerAnimated:completion:" addition to UIViewController. I wanted this functionality in iOS 4.3.
I find using the modal ...
3
votes
1answer
578 views
Display complex mathematical equations in iOS 5.0 devices
I am working on an app for iPhone and iPod Touch that has to show complex mathematical equations like algebraic, integration, summation formulas along with some text.
For that I have used Quartz2D ...
3
votes
3answers
507 views
Handle Java Process outputs without extra-threads
Usually, people would create two extra-threads in order to read the standard output and error respectively. However, the following code would allow to handle a Process outputs without those threads ...
4
votes
3answers
573 views
Am I using too many if statements?
Essentially, I am making an app that allows the user to type in chemistry formulas using a custom keyboard.
The keyboard will have several keys, for example, "Na", "H", and "O". Pressing them in ...
2
votes
1answer
217 views
Can this game function/code be better?
I'm working on a game for iOS devices and this is the function we use to create server-loaded buildings. The server loading is in another function and everything works just fine, but I was wondering ...
1
vote
1answer
951 views
Selective autorotation in a UINavigationController
In a current project I needed to enable/disable autorotation of the UI to specific UIView's. I looked around and did not find a working solution that fitted my case and returning NO in ...
1
vote
0answers
339 views
Help me improve the way I handle rotations in iOS painting app
I have an iOS app that support all orientations. I sometime notices performance issues when I rotate the device, and sometimes it crashes, badly. And it's not as smooth as other apps. This is my first ...
1
vote
1answer
107 views
I am Designing a singleton cacheManger class . Want some helps to make it as a good class
Here i am designing a FileCaching class. Can any one tell me is i am doing the right way. What i want to know is
is my CacheManager class is a singleton , or what abt the memmory management of ...