A late-binding, message-based, object-oriented language that is a strict superset of C and is primarily used for programming primarily on Apple's Mac OS X and iOS platforms. Objective-C can also be used on other platforms that support gcc or clang.
0
votes
0answers
8 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. ...
2
votes
1answer
23 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 ...
0
votes
1answer
68 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 ...
2
votes
1answer
61 views
using C scope syntax for code organization purposes
Would you ever use curly braces for making your code more organized and readable? for instance I could have:
- (void)methodName {
...
// action 1
{
...
}
...
}
Where ...
-2
votes
0answers
46 views
Object Oriented PHP - mysql database manipulation [closed]
Been working with this code but it won't run. Please help me find the problem with this.
THis is my class :
<?php
class mysqlcon
{
private $connection;
private $database;
public $query;
...
4
votes
1answer
58 views
Simple yet efficient integer-to-object dictionaries?
Sometimes I need an NSDictionary-like object that maps a few integers (non-negative) to objects. At first glance, NSMutableArray is great for this, provided that the indexes aren't too high so I came ...
2
votes
1answer
50 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
114 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 ...
2
votes
1answer
85 views
Logic question in a card matching game controller
I have a card matching game with a model of:
-Card
-Deck
-PlayingCard
-PlayingCardDeck
And another model that called CardMatchingGame.
Now, I had a task to add a button to the view for new game, ...
3
votes
1answer
79 views
Is there anything I can improve in this view controller implementation?
I'm using both Core Data and NSFetchedResultsController. Is there anything I can improve on? Thanks.
//
// RoutineTableViewController.m
// App
//
// Created by Me on 3/21/11.
// Copyright 2011 ...
0
votes
1answer
33 views
Creating a Playlist program (exercise)
Exercise:
Define three new classes, called Song, Playlist, and MusicCollection. A Song
object will contain information about a particular song, such as its title,
artist, album, and playing time. A ...
2
votes
1answer
82 views
Creating shapes program with multiple classes (different files) in Objective-C
I just started to learn Objective C with Programming in Objective C" of Stephen G. Kochanand and I would love to get your feedback to see if i'm getting OOP concept with Objective-C right, This is my ...
1
vote
1answer
39 views
First program in Objective c defining a 'Watch' class
This is the first program (that is not doing much basically), and I know usually you define classes in separate files, but just wanted to see if I got the syntax right, and the concept of using ...
-2
votes
1answer
60 views
iOS multiplayer pong game [closed]
Okay so I was trying to make a multiplayer Pong iOS app and ended up with this. Which 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
65 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
38 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
140 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:
...
3
votes
1answer
103 views
Code review of forward invocation
Here's the situation. I'm writing a simple game and I had two main actors: GameController and GridView.
GridView is a UIView subclass displaying a grid with which the user interacts. It defines its ...
0
votes
2answers
385 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
92 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 ...
2
votes
1answer
106 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 ...
1
vote
1answer
132 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
84 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 ...
2
votes
2answers
118 views
Objective-C Singleton Implementation
is this the right way to do a singleton in Objective-C ? (coming from Android background, with a little understanding of threading)
#import "ItemsManager.h"
#define kNumMaxSelectableItems 15
...
3
votes
1answer
82 views
Spliting string to array by number
I have two functions to split string to array of strings.
Input string is: (1Letter E|V|R) + 8 number, last component of string (1Letter + V) + 8 or less numbers.
I'v got two functions advised to ...
3
votes
2answers
91 views
Storing and iterating over multiple NSError pointers
How would you refactor this kind of code? I've unsuccessfully tried several approaches (NSArray, NSPointerArray, plain C array), but always ran into pointer type checking error.
NSError *error1;
...
4
votes
2answers
1k 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
139 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.
...
0
votes
1answer
70 views
Optimize nested enumerate blocks?
Well,
i have 3 nested NSEnumeration loops, used to get the textfields of a custom cell, in a custom table in a custom view in a controller...
How can i change this code to make more readable and more ...
5
votes
2answers
136 views
Optimize IF condition block
this is my first post here!
How can i optimize the if condition on this snippet?
The only one difference is && [self isCurrentPosition:i].
How can made it on a single if, including the ...
2
votes
2answers
95 views
Is there a better way of showing multiple NSDictionaries?
I have a method that contains a bunch of NSDictionaries (in fact, the only reason I have that method is to create those NSDictionaries). While I don't believe there are enough NSDictionaries ...
1
vote
1answer
65 views
Iterating over object properties
I'm working with lots of code that looks like this:
-(void)switchToPercent{
int tmp;
tmp = (statisticsObject.idag3_orig != 0) ? statisticsObject.idag3_orig : [self ...
1
vote
1answer
208 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 ...
2
votes
1answer
245 views
Objective-C Stack implementation
I'm a S.O. user, and this is my first question on Code Review, so please be lenient. (i actually thought about making a site like this myself at one point, but i LOVE this Code Review idea!).
I just ...
6
votes
2answers
419 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 ...
4
votes
2answers
206 views
Objective-C retain / release snippet
Here are some snippets I coded and I would like some feedback on my way of handling this:
I have a utility class, as a singleton, that provides me with a method named randomColor which returns a ...
2
votes
1answer
138 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
0answers
192 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 ...
1
vote
1answer
365 views
#define or NSString * const - Benefits and drawbacks of string literal constant syntax? [closed]
I'm interested in discussing string literals in Objective-C and would like to know 1. if there's a preferred paradigm / style and 2. what (if any) the performance implications might be.
There are ...
5
votes
2answers
149 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 ...
1
vote
0answers
79 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"
...
4
votes
2answers
188 views
how to make the code more readable
For the question asked here I got the solution, but I don't like the code how is written.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
...
1
vote
1answer
239 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
3answers
153 views
Is there a better way of showing an image based on the battery level?
I'm working on a battery indicator feature in my app, and I was wondering if there is a better way than what I am doing to check what image should be displayed when. I am currently using if ...
2
votes
1answer
189 views
Objective-C CF Random Name Generator
Based on a python name generator grammar I found here I've decided to write my own in objective-C. The idea is I can load the grammar from a plist file and generate random names from it.
I'm looking ...
1
vote
1answer
88 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 ...
0
votes
0answers
73 views
Checking for an Update version of my database
Basically I am trying to check for a newer version of the database, because it is stored in the document directory. The program does make changes to the database, but these will be incorporated into ...
3
votes
2answers
92 views
Import management
I am working on a personal iPhone ObjC project, and was recently getting frustrated with how tedious importing the same set of headers over and over was getting… So I created a header file that ...
15
votes
13answers
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
654 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 ...