Amazon.com Widgets Recent Posts
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 28, 2014, 11:39:20 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: July 18, 2014, 02:10:40 AM 
Started by lukamath - Last post by lukamath
If I have understood well the method "-(void) intersectSet: nsset" is not inherited from NSSet (that is "(BOOL) intersectsSet: nsset) but exclusive of NSMutableSet. Am I right? However probably I am making some mistake in coding too that I can't understand. I attach the zip of the code so that you can check it too. It is the ex.9 of Chapter 15th (5th edition). The reported error is in a note in "removeSongInLibrary:" method in the file AddressBook.m.
The target was to remove song from the library of the MusicCollection and then to intersect the library with all playlists attached to the same MusicCollection to remove the song from there too.
I have made a not so elegant workaround to let the program work anyway, but I would like to use "intersectSet:" if possible.

Where is the mistake?

 22 
 on: July 17, 2014, 01:37:04 PM 
Started by simul7 - Last post by BrianLawson
Either way works. When I designed the program I may have thought the testContainment function might need to do more that it actually does so I created a separate function for it.

 23 
 on: July 17, 2014, 01:23:52 PM 
Started by simul7 - Last post by mzeeshan
What's the point in adding an extra step:
Code: (Objective-C)
testContainment(myRect, myPoint);
while we can directly call our containsPoint: method in this way:
Code: (Objective-C)
NSLog(@"Rectangle %s contain the point.", [myRect containsPoint: myPoint] ? "does" : "does not");
Please guide. Thanks

 24 
 on: July 16, 2014, 10:18:42 PM 
Started by lukamath - Last post by BrianLawson
Mutable sets are a subclass of NSSet so all NSSet methods are available to NSMutableSet as well. You should be able to call intersectSet on your mutable set. How big is your code, can you post it here or zip it up to be downloaded so I can take a look at it?

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

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

    @autoreleasepool {
        NSMutableSet *mset1 = [[NSMutableSet alloc] init];
        NSMutableSet *mset2 = [[NSMutableSet alloc] init];

for (int i = 1; i < 5; i++) {
[mset1 addObject:[NSNumber numberWithInt:i]];
}
NSLog(@"Mutable set 1: %@", mset1);

for (int i = 3; i < 7; i++) {
[mset2 addObject:[NSNumber numberWithInt:i]];
}
NSLog(@"Mutable set 2: %@", mset2);

[mset2 intersectSet:mset1];
NSLog(@"Mutable set 2 after intersect with mset1: %@", mset2);
    }

    return 0;
}
produces this output:

2014-07-16 23:24:27.409 test[32617:303] Mutable set 1: {(
    3,
    2,
    1,
    4
)}
2014-07-16 23:24:28.473 test[32617:303] Mutable set 2: {(
    3,
    6,
    5,
    4
)}
2014-07-16 23:24:28.474 test[32617:303] Mutable set 2 after intersect with mset1: {(
    3,
    4
)}
Program ended with exit code: 0

 25 
 on: July 16, 2014, 03:16:56 AM 
Started by lukamath - Last post by lukamath
Is it possible and is there any method like intersectSet: that I can use to intersect two NSMutableSet?
Example: if I use this
Code: (Objective-C)
[aPlaylist.listOfSongs intersectSet: _library];
where
aPlaylist.listOfSongs and _library are both NSMutableSet i received the exceptions as follows
[]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM intersectSet:]: unrecognized selector sent to instance 0x100115f90'
[]
As I have understood I have to pass to intersectSet a NSSet, but how to do if I want to pass a NSMutableSet?
Did I miss something?


 26 
 on: July 14, 2014, 10:09:49 AM 
Started by harrykar - Last post by BrianLawson
Hi Harry,

Sorry I misunderstood the question. I also misread the %i (eye) for %l (ell) my bad.

Your example provides the answer to your question. Smiley When an integer value is read using the %i format specifier, it performs conversion between octal & hexadecimal inputs to a decimal value. Octal values are specified by entering a leading 0 (zero), and hexadecimal values are entered by leading with the characters '0x'. The %d format specifier reads whatever value is entered strictly as a decimal value. When 0x5 is input to the following code snippet scanf(%d, &x); printf("%i", x) 0 is what gets printed. scanf stops reading the input at the x character with the %d format specifier.

 27 
 on: July 14, 2014, 08:53:49 AM 
Started by harrykar - Last post by harrykar
You use %d when the variable you are scanning into is an int, %l is for a long int.

Hi  Brian
I know about the scanf()'s  format specifiers
Code: (Objective-C)
char c, s[10]; int i; float f; double d;

 scanf("%c", &c); // reads next character and puts its value in c

 scanf("%s", s); // reads next word and converts it to a string

 scanf("%i", &i); // reads next word and converts it to an integer

 scanf("%d", &i); // reads next word and converts it to an integer

 scanf("%f", &f); // reads next word and converts it to a float

 scanf("%lf", &d); // reads next word and converts it to a double

 scanf("%c %s %i %f", &c, s, &i, &f); // multiple reads

 printf("c=%c s=%s i=%i r=%3.1f\n", c, s, i, f);
 
 while (scanf("%c %s %i %f", %c, s, &i, &f) < 4) {

     // do the appropriate error treatment and retry
 
 }// at this step, the 4 input fields have been readed successfully

etc...



...but my point instead was different... let's illustrate it trough an example it's better  Smiley
Code: (Objective-C)
#include <stdio.h>
#include <stdbool.h> // for true macro in while loop


int main (void) {

  int n_i, n_d;   //scanf()'s input list
  int error_i, error_d; // scanf() returns the number of successfully matched and assigned input
           // items as a value


  printf("Press Ctrl-C to break the inf loop!!!\n\n");  // Prompt
  while ( true ) {

 printf("%%i Case: Give me a number: "); // Prompt
 error_i = scanf( "%i", &n_i);
 printf("you have pressed %i\n\n", n_i);
 printf("scanf's number of successfully matched and assigned input items: %d\n\n", error_i);

 printf("%%d Case: Give me a number: "); // Prompt
 error_d = scanf( "%d", &n_d);
 printf("you have pressed %d\n", n_d);
 printf("scanf's number of successfully matched and assigned input items: %d\n\n", error_d);

 printf("Press Ctrl-C to break the inf loop!!!\n\n");  // Prompt
  }

}

A)
if you try as input 10 (in either cases %i and %d) you get that output:
Code: (Objective-C)
Press Ctrl-C to break the inf loop!!!

%i Case: Give me a number: 10
you have pressed 10
scanf's number of successfully matched and assigned input items: 1

%d Case: Give me a number: 10
you have pressed 10
scanf's number of successfully matched and assigned input items: 1

B)
if you try as input 010 (in either cases %i and %d) you get that output:
Code: (Objective-C)
Press Ctrl-C to break the inf loop!!!

%i Case: Give me a number: 010
you have pressed 8
scanf's number of successfully matched and assigned input items: 1

%d Case: Give me a number: 010
you have pressed 10
scanf's number of successfully matched and assigned input items: 1

C)
if you try as input 0xA (in either cases %i and %d) you get that output:
Code: (Objective-C)
Press Ctrl-C to break the inf loop!!!

%i Case: Give me a number: 0xa
you have pressed 10
scanf's number of successfully matched and assigned input items: 1

%d Case: Give me a number: 0xa
you have pressed 0
scanf's number of successfully matched and assigned input items: 1

Now let's connect all that experiments;
Empirically we got that :
firstly scanf() reads and assign correctly his input and

in A) %d and %i have similar behaviour : scanf() converts the input string into a decimal (base 10) number

in B)  scanf(%i,) converts the input string 010  into an octal number (base 10) instead
        scanf(%d, ) converts the input string 010  into a decimal number (base 10)

in C)  scanf(%i,) converts the input string 01xA  into an hex number (base 16) instead  
        scanf(%d, ) converts the input string 01xA  into a decimal number (base 10) (in that case takes 0 and get rid of xA)



PS:
1. in the latest case for some reason the console's output goes speedily down  so to see the output i add
#include <stdlib.h>
system("pause");  // after the last printf()
and yes actually i am far away from my loved POSIX environment Sad


2.
Actually i haven't time but i promise to myself to clear that question soon; Almost i hope now my question should be clear

Ceers,
Harry

 28 
 on: July 14, 2014, 06:24:33 AM 
Started by harrykar - Last post by harrykar
I don't saw a errata and/or suggestion section for C here so i open that thread for report everything IMHO is not correct in the book or do suggestions


p 100 Chapter 7 Working with Arrays  
Code: (Objective-C)
Program 7.1 Output
values[0] = 197
values[1] = 0
values[2] = -101
values[3] = 547
values[4] = 0
values[5] = 350
values[6] = 0
values[7] = 0
values[8] = 0
values[9] = 35

Although the 0's meaning in that list  is correctly (wordy) explained maybe is better signing with junk, cruft ( http://en.wikipedia.org/wiki/Cruft ) or otherwise instead of 0 values? before read the explanation below that list in book i thunk "values is automatic how is possible autoinitialize to 0 his unused places?"

 29 
 on: July 14, 2014, 05:23:10 AM 
Started by harrykar - Last post by BrianLawson
You use %d when the variable you are scanning into is an int, %l is for a long int.

 30 
 on: July 13, 2014, 03:35:49 PM 
Started by harrykar - Last post by harrykar
Actually i'm starting Ch 7 about arrays. So far in book i encountered  scanf("%i", ) but no scanf("%d", ); if i remember well somewhere in the book is explicitly reported that "we use the scanf("%i", ) throughout the book"; curiosity arise and i did some tests; as result i notice  different behaviour; Right now i haven't a clear idea about that issue; In substance my question is: what' s  precisely the difference among them ?

TIA
Harry G. K.  

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.