Amazon.com Widgets Recent Posts
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 02, 2015, 01:31:20 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: August 14, 2015, 12:53:26 AM 
Started by Latias - Last post by Latias
Code: (Objective-C)
#import <Foundation/Foundation.h>
@interface Rectangle: NSObject
-(void) setWidth: (int) w;
-(void) setHeight: (int) h;
-(int) width;
-(int) height;
-(int) area;
-(int) preimeter;
@end

@implementation Rectangle
{
int width;
int height;
int area;
int preimeter;
}

-(void) setWidth:(int)w
{
width = w;
}

-(void) setHeight:(int)h
{
height = h;
}

-(int) area {
return width * height;
}

-(int) preimeter {
return (width + height) * 2;
}
@end

int main(int argc, char *argv[]) {
@autoreleasepool {
Rectangle *myRectangle = [[Rectangle alloc]init];
[myRectangle setWidth: 2];
[myRectangle setHeight: 3];
NSLog(@"area = %d, preimeter = %d",[myRectangle area] ,[myRectangle preimeter]);
}
return 0;
}
Result:
2 warnings generated.
i don't know what is wrong in the code, help!

 22 
 on: August 13, 2015, 12:57:21 AM 
Started by jonr - Last post by Horrenad
I believe this is a very good forum. And we will study carefully.

 23 
 on: August 13, 2015, 12:56:59 AM 
Started by jonr - Last post by Horrenad
I think the forum is the best forum one. And we will continue to publish.

 24 
 on: August 11, 2015, 07:30:32 AM 
Started by Phil-HK - Last post by Phil-HK
ok I got it.
Thanks Brian Cheesy

 25 
 on: August 11, 2015, 07:10:10 AM 
Started by Phil-HK - Last post by BrianLawson
Because isPrime can be set to NO while inside the loop, the test for isPrime == YES is used to end the loop once the prime number has been found. Another option would have been to use the break statement to get out of the loop.
Code: (Objective-C)
for (d=3; d<p; d+=2) {
    if (p%d == 0) {
        isPrime == NO;
        break;
    }
}

 26 
 on: August 10, 2015, 10:00:07 AM 
Started by Phil-HK - Last post by Phil-HK
#import <Foundation/Foundation.h>

int main( int argc, char * argv[])
{
    @autoreleasepool{
        int p, d;
        bool isPrime;
       
        printf ("2\n");
       
        for ( p=3; p<=50; p+=2){
            isPrime = YES;
           
            for ( d=3; d<p && isPrime == YES; d+=2){
                if (p%d == 0)
                isPrime = NO;
            }
           
            if (isPrime != NO)
                printf("%i\n", p);
        }   
    }
    return 0
}

why should add the isPrimm == YES inside the inner loop?
because I think the first isPrime == YES represent all p value to be isPrime, so the isPrime == YES in the inner loop is not meaningful.

I am quite confused in that. Can somebody please explain to me?

PS. I am not good in english so use the colour to highlight the problem. thanks

 27 
 on: August 10, 2015, 01:18:30 AM 
Started by Jane S. - Last post by Jane S.
Hello everyone!! I am an iOS client and trying to connect to the remote server with my self signed certificate. I add it to the keychain and start socket connection. When I try my code with localhost, I see some encrypted messages, but when I try to connect to the remote server I get the error "no cipher suites in common". Could you please help me on that? Thanks in advance..

The code I work on is as follows

"
    

    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
    NSData *iosTrustedCertDerData = [NSData dataWithContentsOfFile:[bundle pathForResource:@"keytool_crt"
                                                    ofType:@"der"]];
    CFDataRef myCertData = (__bridge_retained CFDataRef)iosTrustedCertDerData; //1
    
    
    assert(myCertData);
    
    SecCertificateRef myCert;
    myCert = SecCertificateCreateWithData(NULL, myCertData);
    
    
    
    SecPolicyRef myPolicy = SecPolicyCreateBasicX509();
    SecCertificateRef certArray[1] = { myCert };
    CFArrayRef myCerts = CFArrayCreate(
                                       NULL, (void *)certArray,
                                       1, NULL);

  
    NSMutableDictionary *SSLOptions = [NSMutableDictionary dictionaryWithCapacity:3];
    [SSLOptions setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsExpiredRoots];
    [SSLOptions setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsExpiredCertificates];
    [SSLOptions setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
    [SSLOptions setObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCFStreamSSLValidatesCertificateChain];
    [SSLOptions setObject:@"localhost:4444" forKey:(NSString *)kCFStreamSSLPeerName];
    [SSLOptions setObject:(NSString *)kCFStreamSocketSecurityLevelNegotiatedSSL forKey:(NSString*)kCFStreamSSLLevel];
    [SSLOptions setObject:(NSString *)kCFStreamSocketSecurityLevelNegotiatedSSL forKey:(NSString*)kCFStreamPropertySocketSecurityLevel];
    [SSLOptions setObject:(__bridge id)(myCerts) forKey:(NSString *)kCFStreamSSLCertificates];
    [SSLOptions setObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCFStreamSSLIsServer];
    
    
    
    
    
    SecTrustRef myTrust;
    OSStatus status = SecTrustCreateWithCertificates(
                                                     myCerts,
                                                     myPolicy,
                                                     &myTrust);
    SecTrustResultType trustResult;
    if (status == noErr) {
        status = SecTrustEvaluate(myTrust, &trustResult); //5 }
        
        NSLog(@"Status: %d", status);
        
        if (myPolicy){
        CFRelease(myPolicy);
        }


            CFReadStreamRef readStream;
            CFWriteStreamRef writeStream;
    NSLog(@"Trying to connect to server");
            CFStreamCreatePairWithSocketToHost(NULL,
                                               (CFStringRef)@"localhost", //REMOTE SERVER IP ADDRESS ,
                                               4444,
                                               &readStream,
                                               &writeStream);
    
    NSLog(@"Connection established");
            CFReadStreamSetProperty(readStream,
                                    kCFStreamPropertySocketSecurityLevel,
                                    kCFStreamSocketSecurityLevelTLSv1);
//            CFReadStreamOpen(readStream);
//            CFWriteStreamOpen(writeStream);
    
            
            NSInputStream *inputStream = (__bridge NSInputStream *)readStream;
            NSOutputStream *outputStream = (__bridge NSOutputStream *)writeStream;
           [inputStream setDelegate:self];
            [outputStream setDelegate:self];
            //
            [inputStream scheduleInRunLoop:[NSRunLoop mainRunLoop]
                                           forMode:NSDefaultRunLoopMode];
                    [outputStream scheduleInRunLoop:[NSRunLoop mainRunLoop]
                                            forMode:NSDefaultRunLoopMode];
    NSLog(@"Open input and output streams");
    

    [inputStream open];
                 [outputStream open];

    
          
    NSLog(@"Input and output streams opened");
  
    }



"

 28 
 on: August 05, 2015, 04:56:52 PM 
Started by Haley Ritz - Last post by Haley Ritz
I am new to xcode, I use xcode 6 and like to know how that occasions I use NSTimer, how to use?

Thanks guys for helping!

 29 
 on: August 03, 2015, 04:18:27 AM 
Started by Phil-HK - Last post by Phil-HK
I didn't set the loop_condition in if statement, but set the break statement in the 'E' operator.
Can I do this?
Is it work in my programming overall?




int main(int argc, char*argv[])
{
    @autoreleasepool {
        
        double number;
        char operator;
        Calculator *deskcal = [Calculator new];
        
        NSLog (@"type a number and operator");
        
        for (int i=1; ; i++) {
            scanf (" %lf %c", &number, &operator);
            if (operator == '+')
                [deskcal add: number];
            else if (operator == '-')
                [deskcal subtract:number];
            else if (operator == '*'||operator== 'x')
                [deskcal mutiply:number];
            else if (operator == '/')
                [deskcal divide:number];
            else if (operator == 'S'||operator =='s')
                [deskcal setAccumulator:number];
            else if (operator == 'E'||operator == 'e'){
                [deskcal accumulator];
                NSLog(@" end of calculation");
               break;}
            else {
                NSLog(@"invail Calculation");
                [deskcal setAccumulator:NAN];
            }
            
            
        NSLog(@" = %.2f", [deskcal accumulator]);
        }
    }
    return 0;
}

 30 
 on: August 02, 2015, 08:55:48 AM 
Started by irishetcher - Last post by pif
I'm totally confused about this one myself, but your post helped me make it work. Still, I really can't say I fully understand what's happening here.

Anyway, here's what I have:

main.m
Code: (Objective-C)
//
//  main.m
//  prog8.4
//

#import "Rectangle.h"
#import "XYPoint.h"

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

        Rectangle *myRect = [[Rectangle alloc] init];
        XYPoint *myPoint = [[XYPoint alloc] init];
        XYPoint *newPoint = [[XYPoint alloc] init]; // XYPoint object with stored coordinates
        
        [myPoint setX:100 andY:200];
        
        [myRect setWidth:5 andHeight:8];
        myRect.origin = myPoint;
        
        NSLog(@"\nRectangle w=%i, h=%i", myRect.width, myRect.height);

        NSLog(@"\nOrigin at %i, %i", myRect.origin.x, myRect.origin.y);
        
        NSLog(@"\nArea = %i, Perimeter = %i", [myRect area], [myRect perimeter]);
        
        // new method here twice:
        
        [newPoint setX:50 andY:60];

        [myRect translate: newPoint];
        
        NSLog(@"\nOrigin at %i, %i", myRect.origin.x, myRect.origin.y);
        
        [newPoint setX:120 andY:180];
        [myRect translate: newPoint];
        
        NSLog(@"\nOrigin at %i, %i", myRect.origin.x, myRect.origin.y);

    }
    return 0;
}

Rectangle.h
Code: (Objective-C)
//
//  Rectangle.h
//  prog8.4
//

#import <Foundation/Foundation.h>

@class XYPoint; // directive to set XYPoint as a class - not really sure why I have to do this
@interface Rectangle : NSObject

@property int width, height;

-(XYPoint *) origin;
-(void) setOrigin: (XYPoint *) pt;
-(void) setWidth: (int) w andHeight: (int) h;
-(int) area;
-(int) perimeter;

-(void) translate: (XYPoint *) tr;
@end

Rectangle.m
Code: (Objective-C)
//
//  Rectangle.m
//  prog8.4
//

#import "Rectangle.h"

@implementation Rectangle

{
    XYPoint *origin;
}

@synthesize width, height;

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

-(void) setOrigin:(XYPoint *)pt
{
    origin = pt;
}

-(XYPoint *) origin
{
    return origin;
}

-(int) area
{
    return width * height;
}

-(int) perimeter
{
    return (width+height)*2;
}

-(void) translate:(XYPoint *)tr
{
    origin = tr;
}
@end

XYPoint.h
Code: (Objective-C)
//
//  XYPoint.h
//  prog8.4
//

#import <Foundation/Foundation.h>

@interface XYPoint : NSObject

@property int x,y;

-(void) setX: (int) xVal andY: (int) yVal;
@end

XYPoint.m
Code: (Objective-C)
//
//  XYPoint.m
//  prog8.4
//

#import "XYPoint.h"

@implementation XYPoint

@synthesize x,y;

-(void) setX:(int)xVal andY:(int)yVal
{
    x=xVal;
    y=yVal;
}
@end

Output:
Quote
Rectangle w=5, h=8
Origin at 100, 200
Area = 40, Perimeter = 26
Origin at 50, 60
Origin at 120, 180

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.