Objective-C Programming

180

Solutions

207

Contributors

Objective-C is an object-oriented programming language that is a strict superset of C (any valid C code is equally valid Objective-C code), and it inherits its object-oriented capabilities from Smalltalk. All procedural syntax is identical to that of C, and all object-oriented syntax is an implementation of Smalltalk messaging. It is the main programming language used by Apple for OS-X and iOS and their respective APIs/ Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods.

Share tech news, updates, or what's on your mind.

Sign up to Post

I wonder why the leading underscore and double underscore values represent.

@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;

Cold someone please explain?

Thanks.
0
I am following a tutorial which instructs me to add a new UIViewController subclass, but when I say File > New and select Cocoa Touch, I see no such file type.

What am I missing?

Thanks.
0
I m a new iPhone developer using Objective-C and Xcode to write my first iPhone app. I have not yet persisted the data to SQL Lite. And since I hear that Core Data would provide me with the ability to save numerous objects to the database, I may not waste the time learning SQLLite.

Is this a bad strategy? Do I need to understand coding with SQL ite before I can work with Core Data?

What's a good starting point for Core Data?

Is there a way I can view the contents of the SQLLite database while I am learning how to work with it?

Thanks.
0
Hi,
I'm running through some exercises in a book.
The problem is to read in a file of names/words. Determine which words in the file (one word per line) is a proper name as well as a 'regular' word.  This is more of an exercise in using Objective C though, because the only 'hint' is that in the file, proper names comes right before the 'regular' word and they start with a Cap.
Anyway, code is below. I'm using indexes to check current line with next line. If there is a match, I report back out.  The problem comes at the end of the word list though because I'm checking one past the end of the array. So I get an 'Array out of Bounds' message. It makes sense that I would get that, so I put in a check
if (y+1 > namescount){
NSLog (@" Hey!  %i,y).
The thing is that I never get into this 'if' statement.  If I put in a constant value for namescount, then I get into the 'if' statement.
Since  namescount is defined as  NSUInteger, does something need to be done to 'y' to make it match correctly with namescount?
Here is the code:

    // Read in file
    
    NSString *nameString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" encoding:NSUTF8StringEncoding error:NULL];
    
    // Array of strings
    NSArray *names = [nameString componentsSeparatedByString:@"\n"];

    
    // Iterate
    NSUInteger namescount = [names count];
   // NSLog(@"Count: %i", namescount);

        for (int y=0; y<= namescount; y++){
            
            if(y+1 > namescount){
    

Open in new window

0
I am trying to weigh the benefits of using Dreamweaver and PhoneGap to create a single dual platform application versus a pure native app using Objective-C and Xcode.

I see risks using any website compiled to native app method, because I hear horror stories about memory bugs which render the apps useless. So I wonder how big the sales difference might be (at the moment) between iPhone apps and Android apps. If an iPhone typically  outsells the Aneroid by a large enough margin, I may seriously consider knocking out the iPhone only app for starters.

Any help in estimating this would be appreciated.

Thanks!
0
I'm new to Xcode and objective C so this question is pretty basic. What I'm trying to do is change the image on a button when a person touches the button and then swap the image back when the user touches it again.

Since I'm only swapping between two images I would imagine that the easiest way to do this is, when the user touches the button, check to see what the current image is and have it display the other image. Here is the psudo-code

Sub ButtonIsPressed
    myString = myButton.imageName
    if myString == "image1.png" then
          myButton.image = "image2.png"
    else
          myButton.image = "image1.png"
    end if
end Sub

The only problem with this is that I can't seem to find any attribute for the button that displays the image name for the button.

Any ideas on how to track which image is currently on the button?
0
I have this code I found that is a template for iOS and Objective-C.  I know how singletons are created, but I want this class to return a NSMutableArray.  How can I do this?

#import "listOfSites.h"

@implementation listOfSites

#pragma mark -
#pragma mark Singleton Methods

+ (listOfSites*)sharedInstance {

	static listOfSites *_sharedInstance;
	if(!_sharedInstance) {
		static dispatch_once_t oncePredicate;
		dispatch_once(&oncePredicate, ^{
			_sharedInstance = [[super allocWithZone:nil] init];
			});
		}

		return _sharedInstance;
}

+ (id)allocWithZone:(NSZone *)zone {	

	return [self sharedInstance];
}


- (id)copyWithZone:(NSZone *)zone {
	return self;	
}

#if (!__has_feature(objc_arc))

- (id)retain {	

	return self;	
}

- (unsigned)retainCount {
	return UINT_MAX;  //denotes an object that cannot be released
}

- (void)release {
	//do nothing
}

- (id)autorelease {

	return self;	
}
#endif

#pragma mark -
#pragma mark Custom Methods

// Add your custom methods here

@end

Open in new window

0
I was planning on using Xcode and Objective C to write my first iPhone app, since I did not want to risk a rejection from the App Store by not fully complying with the Human Interface Guidelines. But then I discovered a video on Lynda.com which says Flash Professional can write apps for iPhone, Android and BlackBerry.

- How true is this?
- Is it the same app that I would deploy for each platform, or is there customization needed for each?

My app will require no graphics, just various menus and tables, and storing data.

I heard Android supports SQL Lite as does iPhone. Would the Flash Professional database code be universal?

My biggest worry is that the iPhone app will not look like a native app.

- How native would the iPhone app look?
- Are there any compatibility or memory problems writing for the iPhone using Flash Professional?
- Are there any memory problems on the cell phones, which plague other web-to-mobile IDE's?
- Will I be able to code with Siri, once Apple releases that technology?


Thanks.
0
I am new to all the technologies sited [in the subject] and now need to start persisting values to the database. But I do not know where to start.

I read I scan use SQL Lite directly and persist entire object trees to the database. I wold like to experiment with both methods.

Please give me a hint where to begin.


Thanks,
newbieweb
0
@interface Test : NSObject {

@private
    -(int)testInt;
}

@end

What am I missing? The compiler generates 4 errors over it?
0
I am new to Objective-C but I think I would like to create:

1) An Abstract class which performs certain functions needed by child classes, but should not be instantiated directly.
2) A Protocol that forces child object to conform to a standard interface
3) Child classes which inherit from this Abstract class and conform to the Protocol.

I understand that Objective-C will not let me enforce that a class is Abstract, but that's okay. I will name it with "Abstract" in the object name. I would like the child classes to be the highest level which conforms to the Protocol, otherwise I would need to make the Abstract class do so, then have empty methods to be overridden, and I am not even sure how to do this.

So please explain a different way to accomplish this or provide me the syntax to make this compile.

Thanks.

P.S. Is the "C" Topic Area the correct place to post questions for Objective-C?
0
I am searching for code in Objective C to convert the Mac Address book to a CSV file.   I wrote code in Applescript but I would like to convert this code to objective c so I can compile it.
0
I have been trying to install mtr on osx lion without any success, it combines both ping and tracerout into one nice command.  I have tried following the instructions here:
http://sdkit.com/
but when executing the ./configure cmd I get the following error:
configure: error: no acceptable C compiler found in $PATH
I have downloaded the Xcode Developers kit from Apple but still the same error even after that was installed.

Just need some direction in how to install this if anyone is familiar with it.

Thanks
0
Which Mac and hardware configuration would be best for developing a C/C++ desktop application with context level help, audio, tutorials, database queries, multiple reports, sub-reports... in other words, not a simple iphone app?

Also, I have read online that Xcode 4 is buggy and Xcode 3 is no longer available. It appears that the Mac now comes with OS X Lion. Has anyone had any experience with OS X Lion and Xcode 4? Is it a stable development environment?

Thanks you,
SilverJade
0
I'm trying to base64 encrypt an image for upload on iOS, but the stupid thing doesn't have built in support, so I downloaded two libraries and tried them both out, but I think they are returning the wrong values (unless I understand base64 even less than I think I do).  This website returns a long string that starts with this:  

/9j/4Q+zRXhpZgAASUkqAAgAAAAKAA4BAgAgAAAAhgAAAA8BAgAFAAAApgAAABABAgAKAA

Open in new window


When I encrypt using the library I downloaded, it starts with this:

iVBORw0KGgoAAAANSUhEUgAAAI0AAABnCAIAAACy41YWAABAAElEQVR4AbzdeaylyXUY9nf3

Open in new window


I am 100% sure the first one is correct, because when I use a test program that was written to test the server, that's the same code that it uploads to the server and the server happily decodes the file and saves the image. Here is the test image.

Basically, what I'm thinking is that I need to get a different library for the iPhone / iPad. Another odd thing I noticed is that for some images, the = will be at the end of the string, and for others it won't be. There are three reasons I can think of for this.

1) the iPhone is running out of memory and doesn't want to tell me so it just uploads what it has.

2) the library is broken

3) I'm confused and don't understand base64

Any suggestions?

EDIT: The iPhone is actually the simulator, so I don't know if it will run out of memory before the computer does. I know the android emulator doesn't, but I'm not sure about the iOS simulator.
0
I have experience with programming Mac when ThinkC was the only option for C++. Recently I have been asked to convert a Windows C++ program to later Macs running OS X. I know that Xcode will compile C++ code, but I wonder how easy and effective that will be.

If I am using Xcode with C++, will I have the advantage of Cocoa and its developer GUI? Or will I be unable to take advantage of the new tools that come with Xcode for programming since Cocoa is written in Object-C? Will I have to develop the user GUI in Object-C which will then (somehow?) call up C++ function code for execution?

In sum, will I be able to integrate C++ code with the Xcode user GUI objects (windows, menus, dialogs, etc.) without having to jump through hoops. And, last but not least, will I have the advantage of using the developer's GUI if I'm programming in C++ with Xcode?

By the way, the Windows code is written in Visual C++ MFC with a lot of old code that's not object oriented.  I'm aware that I will need to strip out all of the MFC and Windows API code and port over just the code governing the underlying functions.

Last, but not least, is software developed for the Mac still tied to the event loop for its overall operation.

Thank you.
0
Hi,
I'm working my way through a book on Obj C. Please look at the code below and my explanation and tell me why my results are not the same with using the Class and Instance methods.
---
If I use the class method of systemTimeZone it's telling me (I think) that I am on Daylight savings time.
However, If I use an instance method for isDaylightSavingTime I am getting a 0 returned.
Help?

Thanks

nacht

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];





NSTimeZone *zone = [[NSTimeZone alloc] init]; // Create an instance

NSTimeZone *c = [NSTimeZone systemTimeZone]; // Class method so don't need to create an instance

NSLog(@"Time zone is %@\n", c);

BOOL z =[zone isDaylightSavingTime];


NSLog(@"Is it set to Daylight Savings time: %d\n", z);


[pool drain];
return 0;
}


OUTPUT:
2012-03-20 11:05:02.525 TimeZone[1259:903] Time zone is US/Eastern (EDT) offset -14400 (Daylight)
2012-03-20 11:05:02.526 TimeZone[1259:903] Is it set to Daylight Savings time: 0
0
The app: I need to make an iPad app for cashiers at a small school uniform business to ring up customers.  Using the master detail view template, The schools are listed in the master view.  Depending on which school is selected, the available uniforms in detail view should change to the one's for that specific school.  Also, these uniforms should have a cost associated with them and a way to select quantity so they can be totaled up after being added to the cart.

Quick description of what I have so far:  So far, I have it so the app has different school in the master view.  I am having a hard time making it populate with different uniforms when one of the schools is selected.
0
I've been following the "Build your second iOS app" tutorial step for step and I have run into this error after the tutorial promised that all the errors would go away, but the error didn't show up until after the other errors were all corrected and I tried to compile it.

The error:

The document "MainStoryboard_iPhone.storyboard" could not be opened. Failed to unarchive element named "UITableViewController".
Here is a link to the tutorial.

Here is my storyboard in XML format

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.1" toolsVersion="2182" systemVersion="11D50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="3">
<dependencies>
    <deployment defaultVersion="1296" identifier="iOS"/>
    <development defaultVersion="4200" identifier="xcode"/>
    <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1179"/>
</dependencies>
<scenes>
    <!--Navigation Controller-->
    <scene sceneID="11">
        <objects>
            <placeholder placeholderIdentifier="IBFirstResponder" id="10" sceneMemberID="firstResponder"/>
            <navigationController id="3" sceneMemberID="viewController">
                <navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" 

Open in new window

0
I've got this sample JSON string
{"Product":[
      {
            "productCategoryID":"1111",
            "products":[
                              {"productID":"1234a","productName":"Sample Name"},
                              {"productID":"1234b","productName":"Sample Name"},
                              {"productID":"1234c","productName":"Sample Name"},
                              {"productID":"1234d","productName":"Sample Name"}
                           ]
      },
      {
            "productCategoryID":"2222",
            "products":[
                              {"productID":"5678a","productName":"Sample Name"},
                              {"productID":"5678b","productName":"Sample Name"},
                              {"productID":"5678c","productName":"Sample Name"},
                              {"productID":"5678d","productName":"Sample Name"}
                           ]
      }
]}

Open in new window


I would like to parse it with Objective-C.

I've included the JSON header files and I can store the response string into an array.

Ideas on where to go from here?

I would like to have a Dictionary where I can say
"get all the products with categoryID of ????"

Ultimately I will be putting the product data from the chosen categoryID into a tableView.
0
(( Please look for more questions under iPad App Programming .... ))

I downloaded XCODE, purchased an iPad, upgraded to Lion (OS x 10.7) bought XCODE tutorial app.  Also finding good tutorials.

Getting ready to order Head-First App Programming and Beginning iOS 5 development; Exploring the iOS SDK - hope those are the best.  Looks like I should buy a book on objective-C too.

Just in the sample pages on Amazon, I discover I need SDK which comes in
FREE
STANDARD
ENTERPRISE

## Question ###
I've been asked to program an iPad application which has a Patent Pending.  Doesn't that mean I need to purchase the $299/year enterprise version?

$300/year isn't out of my budget - but I have yet to make a penny programming apps.  

Still - I firmly believe MOBILE is the way of the future; and I'd be a fool to sit pretty, only knowing HTML, PHP, MySQL, AJax and jQuery.  (And of course Photoshop, Illustrator, some Flash, etc.)

With Facebook, Blogs - the pool of people able to publish to the web has grown enormously.  I started web development company in 1992.

My background and expertise is Marketing; but if programming lets me differentiae my services and allows me to create products to hit customer niches - I'm all for it.

What do you Experts think?  

Good choice of books?
 and $299 Enterprise version?

Thanks, April
0
ok so i have this code so far.

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person 
                                property:(ABPropertyID)property 
                              identifier:(ABMultiValueIdentifier)identifier
{
    NSString *phbook= [[NSUserDefaults standardUserDefaults] stringForKey:@"phbooks"];
    if (property == kABPersonPhoneProperty) { // if tapped is equal to a phone property
        CFStringRef cfnumber;
        ABMultiValueRef numbers = ABRecordCopyValue(person, kABPersonPhoneProperty); 
        for(CFIndex i = 0; i < ABMultiValueGetCount(numbers); i++) {
            if(identifier == ABMultiValueGetIdentifierAtIndex (numbers, i)) { //if tapped number identifier is the same as identifier number tapped
                cfnumber = ABMultiValueCopyValueAtIndex(numbers, i); // copy the number to CFSTRING number
            }
        } ]

Open in new window


what i want to do is when someone taps on  the number in the lastview ... to then copy the text from that number and store it in a variable, and then move to a different view controller, and retrieve the text from that variable..

recap:

person selects last number from ABPeoplePicker ,

then saves that number in a variable, goes to a different viewcontroller(automatically), grabs text from the variable saved on the ABPeoplePickerViewcontroller


i know this is not too hard... but im having problems doing it..

Thanks!
0
Hello experts,

I'm new with Xcode and MacOS.

I would like to get screen shot with Objective-C on MacOS.
I found GetQDGlobalsScreenBits() on Google, but it can be linked
only on 32 bit.

Does anyone know API that can get screen shot on 32/64 bit ?
I would like to save a file (PNG or JPG).

Regards,
Nobuo Miwa
0
I was wondering what is the best approach for creating a view such as the ones attached with many clickable icons. I have seen an open source launcher code for creating such a view but I rather learn on what is the best practice for creating one ? Is it a big image with different sections running different target actions ? are the buttons put dynamically ?& etc ...

Thanks,
Ross
Screen-Shot-2012-02-17-at-2.23.2.png
Screen-Shot-2012-02-17-at-2.24.1.png
Screen-Shot-2012-02-17-at-2.24.2.png
0
Hi,
  I have created an Ultralite db sample Iphone App using Xcode 4.2, Apple IOS SDK 5.0, Objective C and SQL Anywhere 12 version. I am trying to connect the ultralite db in my app. I created 'libulrt.a' file for the simulator and armV6 and armV7 processors. The app connects to the db and retrieves the data when I run it in the simulator.

If I run the same app in the Iphone device, it does not work. It throws the error sqlcode = -954.
–954  The database '%1' was not found

I copied the ultralite dub file into 'Resources' folder of my app. I have written the code to copy this db from the App path to the Documents directory. The database gets copied to Documents directory but unable to connect to this db.

FYI: The Ultralite db has been created using Sybase SQL Anywhere 12 version with Ultralite 12.0.1.3152

The below 2 links will give more information of what we are trying it out.

¿      http://sqlanywhere-forum.sybase.com/questions/8696/need-a-working-example-for-iphone
¿      http://dcx.sybase.com/1200/en/ulc/ulc-iphone-tutorial.html


Is there any solution to come out of this problem? It is blocking my project research and development.
0

Objective-C Programming

180

Solutions

207

Contributors

Objective-C is an object-oriented programming language that is a strict superset of C (any valid C code is equally valid Objective-C code), and it inherits its object-oriented capabilities from Smalltalk. All procedural syntax is identical to that of C, and all object-oriented syntax is an implementation of Smalltalk messaging. It is the main programming language used by Apple for OS-X and iOS and their respective APIs/ Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods.

Top Experts In
Objective-C Programming
<
Monthly
>

No Top Experts for this time period. Answer questions to earn the title!