Skip to content

Posts from the ‘Cocoa’ Category

10
Aug

Fix SDL2 Crash When Compiling using Xcode on Mac OSX

If you want your SDL2 app to compile without crashing you must sign it. In order to do that let’s go to SDL2.framework directory:

cd /Applications/Xcode.app/Contents/Developer/Platforms/ MacOSX.platform/
Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/SDL2.framework

To check if SDL2 is code signed run:

codesign -vvvv SDL2

To signe SDL2 run:

codesign -f -s - SDL2

Note: If you are using an older version of OSX then the path where SDL2.framework is located might be different. For example on OSX 10.7 we can have an Xcode that has SDK for OSX 10.8 located in: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/
Developer /SDKs/MacOSX10.8.sdk/System/Library/Frameworks/SDL2.framework/
.

25
Jul

Find out details about an image with ImageMagick utility

We can find out details about an image using identify tool from ImageMagick package, available on multiple OSes:

identify -verbose img1.bmp
21
Feb

Capture Image, Video and Crop

In this tutorial we will access the device’s default camera application, the photo library and we will record a video with PhoneGap. Also at the end we will do a basic crop on a selected image from our gallery using HTML5 Canvas and JavaScript.

End Result:



Read more »

8
Feb

Display your iPhone Application in Landscape

A short tutorial about how to Display your iPhone Application in Landscape is presented here.

Let’s say you want to run your iPhone application in Landscape mode. How you do that? Well, it’s really simple you must do the following two steps. Let’s say your iPhone app name is MyApp First, from Xcode, go to your Resources section and find file MyApp-info.plist. Right click on MyApp-Info.plist file from Resources and choose Open As -> Source Code File, then add the following XML tags right before closing tag:

[xml]
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeLeft</string>
[/xml]

Go to Classes -> MyAppViewController.m file and uncomment:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

then make that function to return YES, instead of returning:

18
Dec

Multi view iPhone application – tab views and navigation bar

The basic of iPhone application development starts with multi view, so in this tutorial we will learn to create a multi view iPhone app.
We will create a simple app which will contain 2 tabs. The first tab will also use a navigation bar.

Creating the project and tab views

Create a new project for iPhone using the template Empty Application and name it MultiView.
We will add one view controller for each tab screen: add to the project one new file for each tab using the UIViewController subclass, name them FirstViewController and SecondViewController and select the checkbox With XIB for user interface.
Draw using the Interface Builder some interface on each of the 2 screens of our multi view iPhone app.

Multi view iPhone app - first view
First tab view of our multi view iPhone app
Read more »

16
Dec

iPhone navigation bar plus table view application howto

We’re going to create a simple application for the iPhone using a navigation bar and a table view. This application will be able to move between 2 screens using a navigation bar. The first view will use a table view, and the text on the second screen will change depending on the selection from the table.

iPhone navigation bar plus table view - Final look

iPhone navigation bar plus table view app final look

Creating the XCode project

First, go ahead and create a new project. Choose the Empty Application template, name your project SimpleNavbarApp and choose as Device Family “iPhone”. This template will generate just the app delegate files: AppDelegate.h and AppDelegate.m. We will add more files to the project later.

Read more »

11
Dec

Defining a Class in Objective C

To define a class in Objective C you place the @interface part in .h file and the @implementation part in .m file.

Example 1. Class definition in Objective C

To define class MyNotes use the following code for definition file (.h):

// MyNotes.h
@interface MyNotes : NSObject
@end

And the implementation file (.m):

// MyNotes.m
@implementation MyNotes
@end

Read more »

9
Dec

Compare objects in Cocoa

Next example shows you how to compare objects in Cocoa. Do not use == for objects comparison, use isEqual method, or method variation.

Next example shows how to compare two strings in Objective C:

#import <Foundation/Foundation.h>
 
int main (int argc, const char * argv[])
{
 
    @autoreleasepool {
 
        NSString *string1 = @"justAString";
        NSString *string2 = @"justAString";
 
        if ( [string2 isEqualToString:string1] )
            NSLog(@"Strings are equal");
        else
            NSLog(@"Strings are not equal");
    }
    return 0;
}
8
Dec

Search for a substring in a string in Cocoa

To search for a substring in a string in Cocoa, use the following code:

 
#import <Foundation/Foundation.h>
 
int main (int argc, const char * argv[])
{
 
    @autoreleasepool {
 
        NSString *string1 = @"This is just a string";
        NSString *string2 = @"This is another string";
 
        NSRange range1 = [string1 rangeOfString:@"just"];
        NSRange range2 = [string2 rangeOfString:@"test"];
 
        if (range1.location != NSNotFound )
            NSLog(@"String string1 contains word 'just'");
        else
            NSLog(@"String string1 does not contain word 'just'");
 
        if (range2.location != NSNotFound )
            NSLog(@"String string2 contains word 'test'");
        else
            NSLog(@"String string2 does not contain word 'test'");
    }
    return 0;
}