Welcome, Guest. Please login or register.
Did you miss your activation email?
June 25, 2016, 08:47:32 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Recent Posts
Pages: 1 2 [3] 4 5 ... 10

 21 
 on: April 03, 2016, 03:27:46 AM 
Started by Miul - Last post by Miul
Here is my solution.
Code: (Objective-C)
#import "XYPoint.h"

@interface Rectangle : NSObject

@property CGFloat width, height;
@property XYPoint *origin;

- (void)setWidth:(CGFloat)w height:(CGFloat)h;

- (BOOL)containsPoint:(XYPoint *)aPoint;
- (Rectangle *)intersect:(Rectangle *)rect;

@end

Code: (Objective-C)
#import "Rectangle.h"

@implementation Rectangle

@synthesize width, height, origin;

- (void)setWidth:(CGFloat)w height:(CGFloat)h
{
    width = w;
    height = h;
}

- (BOOL)containsPoint:(XYPoint *)aPoint
{
    if ( (aPoint.x >= origin.x && aPoint.x <= origin.x + width) &&
        (aPoint.y >= origin.y && aPoint.y <= origin.y + height) )
        return YES;
    else
        return NO;
}

- (Rectangle *)intersect:(Rectangle *)rect
{
    Rectangle *result = [[Rectangle alloc] init];
    [result setWidth:0.0 height:0.0];
    XYPoint *pt = [[XYPoint alloc] init];
    pt.x = 0.0;
    pt.y = 0.0;
    result.origin = pt;
   
    if ( (rect.origin.x + rect.width >= origin.x && rect.origin.x <= origin.x + width) &&
         (rect.origin.y + rect.height >= origin.y && rect.origin.y <= origin.y + height) )
    {
        if (rect.origin.x <= origin.x)
            result.origin.x = origin.x;
        else
            result.origin.x = rect.origin.x;
       
        if (rect.origin.y <= origin.y)
            result.origin.y = origin.y;
        else
            result.origin.y = rect.origin.y;
       
        if (rect.origin.x + rect.width <= origin.x + width)
            result.width = rect.origin.x + rect.width - result.origin.x;
        else
            result.width = origin.x + width - result.origin.x;
       
        if (rect.origin.y + rect.height <= origin.y + height)
            result.height = rect.origin.y + rect.height - result.origin.y;
        else
            result.height = origin.y + height - result.origin.y;
    }
   
    return result;
}

@end

Code: (Objective-C)
#import <Foundation/Foundation.h>

@interface XYPoint : NSObject

@property CGFloat x, y;

@end

Code: (Objective-C)
#import "XYPoint.h"

@implementation XYPoint

@synthesize x, y;

@end

Code: (Objective-C)
#import "Rectangle.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Rectangle *aRect = [[Rectangle alloc] init];
        [aRect setWidth:250 height:75];
        XYPoint *aPt = [[XYPoint alloc] init];
        aPt.x = 200.0;
        aPt.y = 420.0;
        aRect.origin = aPt;
       
        Rectangle *bRect = [[Rectangle alloc] init];
        [bRect setWidth:700.0 height:880.0];
        XYPoint *bPt = [[XYPoint alloc] init];
        bPt.x = 100.0;
        bPt.y = 200.0;
        bRect.origin = bPt;
       
        Rectangle *result = [aRect intersect:bRect];
        NSLog(@"Origin is (%g, %g), width  = %g, height = %g", result.origin.x, result.origin.y, result.width, result.height);
       
    }
    return 0;
}

 22 
 on: March 25, 2016, 04:24:30 AM 
Started by azrael2000 - Last post by azrael2000
Hi All.

I hope this is the correct place to put this question. If not, please advise me and I will move it to another location.

I have a cocoa program that simply has a window and when you click a button, it opens an alertSheet.

Everything works, to that point, but I don't know how to handle the button presses.

I try to use this to see at least what buttons are being pressed, but in xcode 7.2 it is deprecated and I can't seem to figure the new syntax out.

#import "AppDelegate.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

- (IBAction)createAlertSheet:(id)sender
{
    NSAlert *alert = [[NSAlert alloc] init];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert setMessageText:@"This is a sheet"];
    [alert setInformativeText:@"Hello SHEET Alert."];
   
    [alert setAlertStyle:NSCriticalAlertStyle];
   
    [alert beginSheetModalForWindow:_window
                  completionHandler:Nil];
   
    }

@end

This was how the buttons were handled previously:


- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
    NSLog(@"The return code was %li", returnCode);


Help is REALLY appreciated.  Even after going through xcode's documentation I am having an issue.

Regards

 23 
 on: March 09, 2016, 12:53:32 AM 
Started by jeegee - Last post by blur

http://www.amazon.com/Core-Developers-Cookbook-Edition-Library/dp/0321948106

Is a great book as is Steve's book. After you finish I highly recommend the book.

http://youtu.be/kEB4oHJ__0s link to a video of my app I'm working on.
 

 24 
 on: March 08, 2016, 02:52:38 AM 
Started by Uzair Lakhani - Last post by Uzair Lakhani
Dear Members,

Is it possible for two apps to simultaneously access microphone under iPhone. We want to develop a Skype recorder for iPhone but need to determine the possibility.

In Android we were getting problem in shared access of microphone but on Windows 7 desktop shared mode for microphone worked.

Thanks,

 25 
 on: March 04, 2016, 04:31:39 PM 
Started by skochan - Last post by rugvedj
I am unable to start the quiz. Is there anyway I can find a FAQ or Help manual. Thanks

 26 
 on: February 08, 2016, 09:56:12 AM 
Started by 星如雨 - Last post by mederafael
Code: (Objective-C)
//
//  MyDraw.m
//  Capitulo08
//
//  Created by Rafael Medeiros on 2/8/16.
//  Copyright 2016 Rafael Medeiros. All rights reserved.
//

#import "MyDraw.h"

@implementation MyDraw

@synthesize width,height;

- (void) printBlankLine
{
    printf(" ");
}

- (void) printTraceLine:(NSString *) typeChar
{
    if(typeChar == nil){
        printf("-");
    }else{
        printf("%s",[typeChar UTF8String]);
    }

}

- (long) printWidthLine:(long) w :(NSString *) typeChar
{
    if(w == 0){
        return 0;
    }

    if(w == width ){
        [self printTraceLine:typeChar];
    }else {
        [self printTraceLine:typeChar];
    }

    return [self printWidthLine:--w: typeChar];
}

- (long) printHeihtLine:(long) h
{
    if(h == 0 || h == height){
        [self printBlankLine];
        [self printWidthLine:width:nil];
        printf("\n");
        if( h == 0 ){
            return 0;
        }
    }
    [self printTraceLine:@"|"];
    [self printWidthLine:width:@" "];
    [self printTraceLine:@"|\n"];

    return [self printHeihtLine:--h];
}

- (void) draw
{
    [self printHeihtLine:height];
}

@end



Code: (Objective-C)
//
//  main.m
//  Capitulo08
//
//  Created by Rafael Medeiros on 2/8/16.
//  Copyright 2016 Rafael Medeiros. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MyDraw.h"

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

        MyDraw *myDraw = [MyDraw new];
        [myDraw setWidth:10];
        [myDraw setHeight:2];
        [myDraw draw];

    }
    return 0;
}


 ----------
|            |
|            |
 ----------
Program ended with exit code: 0

 27 
 on: February 06, 2016, 02:48:43 PM 
Started by jonr - Last post by jonr
I have a question on the expression
Code: (Objective-C)
self = [super init];
which is presented in chapter 10 being used in a method to override init and also in creating a designated initializer on the next page. Does
Code: (Objective-C)
self = [super init];
as presented here really mean
Code: (Objective-C)
self = [super <designated initializer>];
?

I'm just wondering if the book used init in this example because in this case, it just so happens that init being the initializer from NSObject is the designated initializer.  So, I'm not sure whether the book used init here as a 'hardwired' choice' or meant it to represent <designated initializer>.
-------------
Related question:
In the last part of this section the book then goes on to show a modified init method in order to adhere to the concept of designated initializer, and states that this is important if your class might be subclassed:
Code: (Objective-C)
-(instancetype) init
{
return [self initWith: 0 over: 0];
}

Essentially, this is simply returning self calling the designated initializer.  This does sort of suggest that in my first question, 'init' really means 'designated initializer' (functionally speaking), but I'm not 100% sure.  If I'm correct on this, why bother redefining init as shown here.  Why not use 
Code: (Objective-C)
self = [super <designated initializer>];
in any init methods you might want to write for the subclass?

 28 
 on: February 04, 2016, 05:21:25 AM 
Started by Jian Zhou - Last post by mederafael
Recursiva !!! Grin

File Fatorial.h
Code: (Objective-C)
#import <Foundation/Foundation.h>

@interface Fatorial : NSObject

- (int) fatorial: (int) fator;

@end

File Factorial.m

Code: (Objective-C)

#import "Fatorial.h"

@implementation Fatorial

- (int) fatorial: (int) fator
{

    if (fator == 0 || fator == -1 ) {
        return 1;
    }

    return fator * [self fatorial: (abs(fator) - 1)];
}

@end

File Main

Code: (Objective-C)
#import <Foundation/Foundation.h>
#import "Fatorial.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Fatorial *fatorial = [Fatorial new];
        NSLog(@"Fatorial de %i = %i", 5, [fatorial fatorial: 5 ]);
        NSLog(@"Fatorial de %i = %i", -5, [fatorial fatorial: -5 ]);
    }
    return 0;
}

Pages: 1 2 [3] 4 5 ... 10


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.