Amazon.com Widgets Recent Posts
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 26, 2015, 10:45:12 PM
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: January 04, 2015, 08:45:12 AM 
Started by martinileemart - Last post by martinileemart
Code: (Objective-C)
-(void) setOrigin:(XYPoint *)pt
{
    if (! origin) {
        origin = [[XYPoint alloc] init];
    }
    origin.x = pt.x;
    origin.y = pt.y;
}

 22 
 on: December 31, 2014, 10:52:04 AM 
Started by kotyara - Last post by kotyara
//  main.m

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSArray *myArray = [[NSArray alloc] initWithObjects:@4,@9,@9,@5,@8,@8,@8,@5,@1, nil];
       
        NSCountedSet *mySet = [[NSCountedSet alloc]initWithArray:myArray];
        NSLog(@"object  count");
        for (NSNumber *element in mySet){
            NSLog(@"   %@ %6lu", element, (unsigned long)[mySet countForObject:element]);
        }
    }
    return 0;
}

output:

2014-12-31 20:51:45.537 q10[11560:807189] object  count
2014-12-31 20:51:45.539 q10[11560:807189]    1      1
2014-12-31 20:51:45.539 q10[11560:807189]    9      2
2014-12-31 20:51:45.539 q10[11560:807189]    5      2
2014-12-31 20:51:45.539 q10[11560:807189]    8      3
2014-12-31 20:51:45.540 q10[11560:807189]    4      1
Program ended with exit code: 0

 23 
 on: December 31, 2014, 03:55:17 AM 
Started by ctlockey - Last post by kotyara
//  Fraction+Comparison.h

#import "Fraction.h"

@interface Fraction (Comparison)

-(NSComparisonResult) comparison: (id) element;

@end

//  Fraction+Comparison.m

import "Fraction+Comparison.h"

@implementation Fraction (Comparison)

-(NSComparisonResult)comparison:(id)element{
    NSNumber * selfNumber = @([self convertToNum]);
    NSNumber * elementNumber = @([element convertToNum]);
    return [selfNumber compare: elementNumber];
}

@end

//  main.m

#import <Foundation/Foundation.h>
#import "Fraction.h"
#import "Fraction+Comparison.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Fraction * f1 = [[Fraction alloc] init];
        Fraction * f2 = [[Fraction alloc] init];
        Fraction * f3 = [[Fraction alloc] init];
        Fraction * f4 = [[Fraction alloc] init];
        Fraction * f5 = [[Fraction alloc] init];
       
        [f1 setTo:2 over:2];
        [f2 setTo:3 over:4];
        [f3 setTo:23 over:567];
        [f4 setTo:56 over:90];
        [f5 setTo:567 over:612];
       
        NSMutableArray * myArray = [NSMutableArray arrayWithObjects:f1, f2, f3, f4, f5, nil];
       
        NSLog(@"Unsorted array:\n ");
       
        for (Fraction *element in myArray){
            NSLog(@"%@", element);
        }
        NSLog(@"Now, check out the sorted array:\n ");
       
        NSArray *sortedArray = [myArray sortedArrayUsingSelector:@selector(comparison:)];
       
        for (Fraction *element in sortedArray){
            NSLog(@"%@", element);
        }
    }
    return 0;
}

output:

2014-12-31 13:48:39.358 q07[10298:730061] Unsorted array:
 
2014-12-31 13:48:39.359 q07[10298:730061] 2/2
2014-12-31 13:48:39.360 q07[10298:730061] 3/4
2014-12-31 13:48:39.360 q07[10298:730061] 23/567
2014-12-31 13:48:39.360 q07[10298:730061] 56/90
2014-12-31 13:48:39.360 q07[10298:730061] 567/612
2014-12-31 13:48:39.360 q07[10298:730061] Now, check out the sorted array:
 
2014-12-31 13:48:39.361 q07[10298:730061] 23/567
2014-12-31 13:48:39.361 q07[10298:730061] 56/90
2014-12-31 13:48:39.361 q07[10298:730061] 3/4
2014-12-31 13:48:39.361 q07[10298:730061] 567/612
2014-12-31 13:48:39.362 q07[10298:730061] 2/2
Program ended with exit code: 0

 24 
 on: December 30, 2014, 09:48:26 AM 
Started by kotyara - Last post by kotyara
//  AddressBook.h

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

@interface AddressBook : NSObject
...
...
-(NSArray *) lookup: (NSString *) theName;

@end

//  AddressBook.m

#import "AddressBook.h"

@implementation AddressBook
...
...
-(NSArray *)lookup:(NSString *) Name{
    NSMutableArray *resultingArray = [NSMutableArray array];
    for (AddressCard *theCard in book){
        if ([theCard.name rangeOfString: Name options:NSCaseInsensitiveSearch].length != 0) {
            [resultingArray addObject:theCard];
        }
    }
    return resultingArray;
}

//  main.m

#import <Foundation/Foundation.h>
#import "AddressCard.h"
#import "AddressBook.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        ...
        ...
        [myBook list];
       
        NSArray *myArray = [[NSArray alloc]initWithArray:[myBook lookup:@"Steve"]];
        for (AddressCard *object in myArray){
            NSLog(@"%-20s   %-32s", [object.name UTF8String], [object.email UTF8String]);
        }
    }
    return 0;
}

output:

2014-12-30 19:33:50.183 q03[8450:639692] ========= Contents of My address book =========
2014-12-30 19:33:50.184 q03[8450:639692] Steve Kochan            stevekochan@gmail.com           
2014-12-30 19:33:50.184 q03[8450:639692] Mark Stevenson         mstevenson@gmail.com           
2014-12-30 19:33:50.184 q03[8450:639692] Stephen Kochan         steve@classroom.com             
2014-12-30 19:33:50.185 q03[8450:639692] steVe Baker               jbaker@classroom.com           
2014-12-30 19:33:50.185 q03[8450:639692] ==================================
2014-12-30 19:33:50.185 q03[8450:639692] Steve Kochan            stevekochan@gmail.com           
2014-12-30 19:33:50.185 q03[8450:639692] Mark Stevenson         mstevenson@gmail.com           
2014-12-30 19:33:50.186 q03[8450:639692] steVe Baker               jbaker@classroom.com           
Program ended with exit code: 0

 25 
 on: December 30, 2014, 08:23:52 AM 
Started by Shaun@lss - Last post by kotyara
Hey guys, check out my solution.

//  AddressBook.h

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

@interface AddressBook : NSObject
...
...
...
-(void) lookup: (NSString *) theName;
@end

//  AddressBook.m

#import "AddressBook.h"

@implementation AddressBook
...
...
...
-(void)lookup:(NSString *) Name{
    for (AddressCard *theCard in book){
        if ([theCard.name rangeOfString: Name options:NSCaseInsensitiveSearch].length != 0) {
            NSLog(@"%-20s   %-32s", [theCard.name UTF8String], [theCard.email UTF8String]);
        }
    }
}
@end

//  main.m

#import <Foundation/Foundation.h>
#import "AddressCard.h"
#import "AddressBook.h"
...
...
...       
        [myBook list];
        [myBook lookup:@"steve"];
    }
    return 0;
}

output:

2014-12-30 18:15:15.039 q02[8186:621929] ========= Contents of My address book =========
2014-12-30 18:15:15.040 q02[8186:621929] Steve Kochan            stevekochan@gmail.com           
2014-12-30 18:15:15.041 q02[8186:621929] Mark Stevenson         mstevenson@gmail.com           
2014-12-30 18:15:15.041 q02[8186:621929] Stephen Kochan         steve@classroom.com             
2014-12-30 18:15:15.041 q02[8186:621929] steVe Baker               jbaker@classroom.com           
2014-12-30 18:15:15.041 q02[8186:621929] ==================================
2014-12-30 18:15:15.041 q02[8186:621929] Steve Kochan            stevekochan@gmail.com           
2014-12-30 18:15:15.042 q02[8186:621929] Mark Stevenson         mstevenson@gmail.com           
2014-12-30 18:15:15.042 q02[8186:621929] steVe Baker               jbaker@classroom.com           
Program ended with exit code: 0

 26 
 on: December 30, 2014, 03:15:14 AM 
Started by kotyara - Last post by kotyara
//  NSDate+ElapsedDays.h

#import <Foundation/Foundation.h>

@interface NSDate (ElapsedDays)

-(unsigned long) elapsedDays: (NSDate *) theDate;

@end

//  NSDate+ElapsedDays.m

#import "NSDate+ElapsedDays.h"

@implementation NSDate (ElapsedDays)

-(unsigned long)elapsedDays:(NSDate *)theDate{
    return [self timeIntervalSinceDate:theDate]/86400;
}

@end

//  main.m

#import <Foundation/Foundation.h>
#import "NSDate+ElapsedDays.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSString *dateFormat = [NSDateFormatter dateFormatFromTemplate:@"ddMMyyyy" options:0 locale:[NSLocale currentLocale]];
       
        NSDateFormatter *sinceDateFormatter = [[NSDateFormatter alloc]init];
        [sinceDateFormatter setDateFormat:dateFormat];
        NSDate *sinceDate = [sinceDateFormatter dateFromString:@"2.7.2004"];
       
        NSDateFormatter *toDateFormatter = [[NSDateFormatter alloc]init];
        [toDateFormatter setDateFormat:dateFormat];
        NSDate *toDate = [toDateFormatter dateFromString:@"13.9.2013"];

        NSLog(@"%lu days elapsed between %@ and %@", [toDate elapsedDays:sinceDate], [sinceDateFormatter stringFromDate:sinceDate], [toDateFormatter stringFromDate:toDate]);
    }
    return 0;
}

output:

2014-12-30 14:33:49.696 q01[7444:586684] 3360 days elapsed between 02.07.2004 and 13.09.2013
Program ended with exit code: 0

 27 
 on: December 29, 2014, 09:01:17 PM 
Started by stanleys2307 - Last post by mitchb
Your questions can be better answered at the Big Nerds Ranch Forum:

http://forums.bignerdranch.com/index.php

Mitch

 28 
 on: December 29, 2014, 08:31:54 PM 
Started by barrettlikespizza - Last post by mitchb
I would think it has to do with consistency. Of the four choices Swift, C++, and C are languages but foundation is not. Change foundation to Objective-C and now all four choices are a computer language.

Mitch

 29 
 on: December 29, 2014, 06:49:41 PM 
Started by barrettlikespizza - Last post by BrianLawson
Mitch is right, my bad. Sorry.

 30 
 on: December 29, 2014, 06:25:01 PM 
Started by barrettlikespizza - Last post by barrettlikespizza
I made a new project and specified Objective C, and all my dreams came true.

Thank you BrianLawson and mitchb!

Just out of curiosity, do you guys know the "why" behind this change in the new Xcode?

Did they just want to make the program approachable to other variants of the C language? Apple moving away from Obj C?
Or maybe this involves the new Swift thing somehow?

Feel free to comment on these new questions but my original question is answered and I can now begin coding again. Thank you so much!

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.