Re: preventing bad memory access
Thanks for the answers guys. I mean I will use the f* operations. But they are really safe? There is anything that I can do for extreme situations in case to avoid bad memory access? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Oct 20, 2011 at 12:09 AM, Don Quixote de la Mancha quix...@dulcineatech.com wrote: On Tue, Oct 18, 2011 at 9:22 AM, Jens Alfke j...@mooseyard.com wrote: On Oct 17, 2011, at 9:26 PM, Wilker wrote: if the user is acessing a file from an external drive, and the file has 8gb, I only wanna read 64kb, so, I don't wanna read it all just for 64kb. Just use fopen/fseek/fread/fclose. Mapping in the entire file just so you can read 64kb is overkill. Specifically, if you fseek to the beginning of where you want to read, then fread what you want, the only part that will get cached is what you read. It will be faster than not caching. mapping the file then reading from memory also caches parts of the file, but only what you read. If you're going to read your file in large chunks then it will be faster to use the open(), lseek(), read() and close() system calls. The f calls from stdio use an in-process cache which is faster for small accesses but slower for large ones. -- Don Quixote de la Mancha Dulcinea Technologies Corporation Software of Elegance and Beauty http://www.dulcineatech.com quix...@dulcineatech.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/wilkerlucio%40gmail.com This email sent to wilkerlu...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
test on device using company registration
Hi guys, Today my company create a company account for iOS in order to test our product on device. They add me as an company developer using iTunes Connect. But I can't find how I create an certificate to me in order so I can test the product on device. I searched on internet but found nothing about it... How can I make this to test on device? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
trying to make mouse cursor changes when hover an NSImageView
Hi guys, I'm needing to make some linkable images on my software (for my about window), the part related to click and go to link is working fine, but I can't make the cursor change to hand (pointer) when mouse is over it, I tried some approaches like using mouseEntered and mouseExited to handle, but no luck, and them tried with addCursorRect, but still can't get it to work... How can I make it work, so user have a better idea that the images are clickable? This is the current code for my custom NSImageView (pretty simple): @implementation LinkableImageView @synthesize targetURL; - (void)mouseDown:(NSEvent *)theEvent { [super mouseDown:theEvent]; if (targetURL) { [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:targetURL]]; } } @end --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Crash Reporter for Lion
Nice to now about it Graham, But in my case its a beta-version of my software, so, It will be out of App Store (at least for now). The FeedbackReporter worked well here :) Thanks Sean. --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Sun, Aug 21, 2011 at 7:43 PM, Graham Cox graham@bigpond.com wrote: On 20/08/2011, at 6:18 AM, Wilker wrote: You have any recommendations on what I could use for that? If your app is going to be on the App Store, the standard Apple crash reporter is all you need - when Apple receive crash reports for your app, they are passed along to your App Store account and can be browsed in the iTunes Connect interface. So you might not need to do anything. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Crash Reporter for Lion
Hi Guys, I'm trying to setup a crash reporter on my Mac Application. I tried the UKCrashReporter, but it seems to not be working here (compiling with 10.7 target, 64 bits). You have any recommendations on what I could use for that? Thanks, --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Safe way to convert C String to NSString
Hi guys, I'm having some trouble by trying to convert a C String to NSString, I'm currently using: NSString *mystring = [NSString stringWithUTF8String:cstring]; But I don't know which encoding the string is using... And when it has some latin or other kind of characteres, the return is nil. In my case I really don't care about these characters, if I can just remove non-ascii from C String and them convert to NSString will be fine for me. What you guys suggest in order that I can convert it to NSString, even losing non-ascii chars, but keeping others? Or a good way to guess the encoding and convert property? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Safe way to convert C String to NSString
The Shawn solution worked really well for me :) In my case I'm hacking an Zip library that I'm using, this zip library has problems when inside the zip the name of files are using crazy encodings... In my case, all I need to know about the file name is it extension (this is why I don't care about just skipping unknown chars, they are not part of extension, so, don't matter). I did some hacks on it, using the [NSString stringWithFormat:%s, theString] and it worked as I needed :) Thanks you guys --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Aug 18, 2011 at 5:19 PM, Jens Alfke j...@mooseyard.com wrote: On Aug 18, 2011, at 1:02 PM, Wilker wrote: But I don't know which encoding the string is using... And when it has some latin or other kind of characteres, the return is nil. In my case I really don't care about these characters, if I can just remove non-ascii from C String and them convert to NSString will be fine for me. If you can find out what the actual encoding is, it’s best to use it. But I know there are cases where you don’t know, or the incorrect encoding is used (hello, RSS feeds…) What I’ve done as a heuristic is to first try UTF-8, as you’re doing; and if that fails (returns nil) fall back to CP-1252 (NSWindowsCP1252StringEncoding). The rationale is that (a) this is the default encoding used by MS Windows, at least in Western countries; (b) it’s a superset of the highly-standard ISO-8859-1 (aka ISO-Latin-1) which is a superset of ASCII; and (c) it defines all 256 code points. So the result is that the conversion to NSString will never fail; ASCII characters come out correctly; and non-ASCII Latin characters will quite often come out OK. Unfortunately this approach doesn’t work at all if the source data is not in an 8-bit encoding — like if it’s UTF-16 or one of the old multi-byte Asian encodings. I’m sure there are heuristics to use there, but I don’t know them. If you’re reading the string from a file or HTTP URL, you can also use -[NSString initWithContentsOfFile/URL:usedEncoding:error:], which will attempt to figure out the correct encoding using clues like the filename extension, leading BOM bytes, etc. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: recomendations for creating a beta with date to expire
I pretend to launch a beta with 2 months fixed for tests, but this beta is just to make sure it runs smoothy on other machines, and if some servers (that application depends on) will be ok with heavy access. If I got problems and need more things, for sure I will launch another beta with longer time to expire. But if it runs ok, I will just release and sell the official version. That's the current idea. --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Tue, Aug 16, 2011 at 1:14 PM, Scott Ribe scott_r...@elevated-dev.comwrote: On Aug 16, 2011, at 10:00 AM, Shawn Bakhtiar wrote: If the app date deceases, and they can not use it again, until you decide, find yourself another job. Well, yes, it's your responsibility to get another release into their hands well before the expiration date. And it's their responsibility to install new releases. And if they don't and complain when it expires, you tell them to just install the release you sent them 3 months ago--if they don't like that, they're not responsible enough to be beta testers. If things go wrong and your schedule for the next release goes way off, you make a new release anyway, even if you only change the expiration date. -- Scott Ribe scott_r...@elevated-dev.com http://www.elevated-dev.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/wilkerlucio%40gmail.com This email sent to wilkerlu...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
recomendations for creating a beta with date to expire
Hi Guys, I'm thinking about releasing a beta version of my software. Im thinking about use the same strategy as Reeder for Mac did, betas with fixed time to expire. What you recommendations to make it safer? Im thinking about do an internet request do get a world clock, and check with this time to see if the software is expired (and close the software in this case). You have any other hints for doing this? Maybe any encryption on code to make it harder to crack or other things like this? Thanks --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: recomendations for creating a beta with date to expire
The network is not a main issue, since my program is useless without network at all. And the idea is to people try it before it launched, in fact it will be an closed beta, I thing I will follow the Nick mind and use local clock just for speed up, anyway the program can be cracked anyway (easier or harder way...). --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Sun, Aug 14, 2011 at 8:29 PM, Gideon King gid...@novamind.com wrote: I agree, and would like to add that I have done this, and did encounter an issue where people had an expired beta and therefore couldn't use the program until they had downloaded an update, and were annoyed by that - especially if they were on the road and had no internet connection. Although I explained to them the benefits to all parties of them running the latest beta, it was still an issue. So if you're going to be doing an extended beta program, you might like to think about either having an expiry date that is always far enough in the future so that people who download a beta are never in a situation where they would have to download another version in just a few days time. And for the internet issue, maybe you could have something that would allow them to use the beta beyond the expiry for a couple of weeks if they don't have an internet connection, but require them to download the next beta, or release version if they have an internet connection. Obviously it depends on your exact situation, but I thought it worthwhile to mention my experiences of doing this sort of thing in case it is of some use to you. Regards Gideon On 15/08/2011, at 8:44 AM, Nick Zitzmann wrote: I would just use the system clock. Most people aren't going to change their clock to run something that's time-limited that has expired, especially if that would interfere with other applications, and the people who will do that probably won't buy the final product anyway. And requiring a network connection to run software that normally doesn't need a network connection, such as your proposal, is a major inconvenience for a lot of people. Restrictive DRM inconveniences people, and really restrictive DRM drives people to piracy if the pirated edition is more convenient to use than the legit version. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
connections appears to be not closing
Hi guys, I'm having a little complicated problem here... The main task of my software is do some complex operations on big lists. For managing the operations I'm using NSOperationQueue, so I'm limiting to 5 operations at once (these operations use a lot of HTTP connections). So, since I wanna have better control of them, to make it easy I'm using only synchronous requests, it all seems to working nice, before I'm start uploading things with multipart... To do the multipart I wrote my own code for it, can be found here (its really simple): https://github.com/wilkerlucio/cocoa_simple_multipart/blob/master/NSMutableURLRequest+MultipartBody.m I'm using GC, this is why there isn't any memory management there... The problem is, after doing like 10 uploads (it vary) the response code from the server starts being 500... In my case it means that the max simultaneous connections was reached, so I start trying again when it happens, but it takes a lot of retries (between 10 and 40) to be able to work again... But if I restart the program, all the first are working on first try, it seems that the upload connections are being retained after I finish it, so, the connections are alive, blocking new ones... The code that fetches the upload is basically this: NSMutableURLRequest *request = [SubdbSource createRequest:@upload withOptions:[NSDictionary dictionaryWithObject:hash forKey:@hash]]; [request setHTTPMethod:@POST]; [request addMultipartDataToBody:subtitleData fieldName:@file fileName: @content.str contentType:@application/octet-stream]; NSHTTPURLResponse *response; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:response error:err]; if (data) { return [response statusCode]; } else { return 0; } I retrieve the data, but in this case I use the data just to see if connection returned valid information (what is relevant to me is only the response code), but these connections seems to not be closing... Any ideas on how to fix that? I tried do some analysis but I got no luck... Anyone has any idea of what could be happening? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: connections appears to be not closing
Hi, I discovered the problem... Is not my issue, the problem is with a third service that the server users... Its limiting the request and server is responding bad because of that... At least my code is fine, just need to update server :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Aug 11, 2011 at 8:24 PM, Jens Alfke j...@mooseyard.com wrote: On Aug 11, 2011, at 4:06 PM, Wilker wrote: it seems that the upload connections are being retained after I finish it, so, the connections are alive, blocking new ones... Weird. You should be able to issue as many requests as you want, and CFNetwork will reuse a pool of connections for them. Perhaps this has something to do with issuing synchronous requests? Most people use the async form. You may get better replies on the macnetworkprog list, which is where several Apple networking gurus hang out. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
drop folders on dock
Hi, I'm trying to accept folder drops on dock icon, but I can't find how to do it... I'm already receiving some file types (I just had to declare them on Document Types), but I can't find where I configure it for accepting folders too... Any thoughts? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
how to get response code on HTTP request synchronous
I'm trying to get the response code from an synchronous http request, Im trying the following code: NSURLResponse *response = nil; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:response error:err] But I can't find any method on NSURLRespond that has the HTTP response code. There is any way to get this information? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: how to get response code on HTTP request synchronous
Thanks Andy :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Aug 11, 2011 at 12:46 AM, Andy Lee ag...@mac.com wrote: I think instead of NSURLResponse you want to use NSHTTPURLResponse, which has a statusCode method. --Andy On Aug 10, 2011, at 11:40 PM, Wilker wrote: I'm trying to get the response code from an synchronous http request, Im trying the following code: NSURLResponse *response = nil; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:response error:err] But I can't find any method on NSURLRespond that has the HTTP response code. There is any way to get this information? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/aglee%40mac.com This email sent to ag...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UI like Transmission BT
Hi Guys, Which components of XCode 4 I should use in order to make an UI like the Transmission BT (http://www.transmissionbt.com/) I mean the part of downloads, one below the other, its like each download is a view, but I don't know how to put them one below the order, and how to make background color cycle. I was looking on Collection View, but after reading doc it don't really seems to feet for me, I just need something simpler, one below the other, scroll when its bigger than screen. Any hints please? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UI like Transmission BT
Thanks guys, I mean I will take the NSTableView + NSView solution, Mac users migrate fast and my software will still on first release, I mean its ok for me for early adopting it :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Jul 28, 2011 at 6:15 AM, Thomas Davie tom.da...@gmail.com wrote: On 28 Jul 2011, at 09:16, Wilker wrote: Hi Guys, Which components of XCode 4 I should use in order to make an UI like the Transmission BT (http://www.transmissionbt.com/) I mean the part of downloads, one below the other, its like each download is a view, but I don't know how to put them one below the order, and how to make background color cycle. I was looking on Collection View, but after reading doc it don't really seems to feet for me, I just need something simpler, one below the other, scroll when its bigger than screen. You have three options: 1) Restrict yourself to 10.7 and use NSTableView with NSViews instead of NSCells. 2) Code an NSCell for that – this can be pretty damn horrible as NSCells can't keep their own state internally, because they will get reused for other rows. 3) Write your own view for putting a bunch of other views one above each other. 1 is trivially easy, 3 is pretty easy, 2 is a nightmare waiting to happen and the reason that 1 exists. Bob ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UI like Transmission BT
I'm trying a lot to make the NSTableView + NSView but I just can't make it work... I don't know the way to go, I was reading this doc here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TableView/ViewBasedTables/ViewBasedTables.html#//apple_ref/doc/uid/1026i-CH15-SW2 But it don't explains too much... I created an xib file for my view, but I don't know how to load it to be cell of the view... The doc says to use a CustomView component inside cell, I dropped one, but I can't see how to link it with my xib. You have any good tutorial about it guys? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Jul 28, 2011 at 1:30 PM, Corbin Dunn corb...@apple.com wrote: On Jul 28, 2011, at 2:15 AM, Thomas Davie wrote: On 28 Jul 2011, at 09:16, Wilker wrote: Hi Guys, Which components of XCode 4 I should use in order to make an UI like the Transmission BT (http://www.transmissionbt.com/) I mean the part of downloads, one below the other, its like each download is a view, but I don't know how to put them one below the order, and how to make background color cycle. I was looking on Collection View, but after reading doc it don't really seems to feet for me, I just need something simpler, one below the other, scroll when its bigger than screen. You have three options: 1) Restrict yourself to 10.7 and use NSTableView with NSViews instead of NSCells. I vote for this option. corbin ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UI like Transmission BT
Sorry guys, my bad... I tried to create a View Controller class by extending from NSView instead of NSViewController... Now its running fine :) Just one last question, I'm using a table with a single column, how I make this column fill 100% of table and follow the table size (in case of table growl or reduce)? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Jul 28, 2011 at 8:14 PM, Wilker wilkerlu...@gmail.com wrote: I'm trying a lot to make the NSTableView + NSView but I just can't make it work... I don't know the way to go, I was reading this doc here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TableView/ViewBasedTables/ViewBasedTables.html#//apple_ref/doc/uid/1026i-CH15-SW2 But it don't explains too much... I created an xib file for my view, but I don't know how to load it to be cell of the view... The doc says to use a CustomView component inside cell, I dropped one, but I can't see how to link it with my xib. You have any good tutorial about it guys? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Jul 28, 2011 at 1:30 PM, Corbin Dunn corb...@apple.com wrote: On Jul 28, 2011, at 2:15 AM, Thomas Davie wrote: On 28 Jul 2011, at 09:16, Wilker wrote: Hi Guys, Which components of XCode 4 I should use in order to make an UI like the Transmission BT (http://www.transmissionbt.com/) I mean the part of downloads, one below the other, its like each download is a view, but I don't know how to put them one below the order, and how to make background color cycle. I was looking on Collection View, but after reading doc it don't really seems to feet for me, I just need something simpler, one below the other, scroll when its bigger than screen. You have three options: 1) Restrict yourself to 10.7 and use NSTableView with NSViews instead of NSCells. I vote for this option. corbin ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
can't build iPhone apps, certificate error
Hi Guys, Im starting an iPhone app here, but I just can't build it... XCode clains: CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 4.3' But I don't have one yeth... I was able to develop iPhone apps before without any code signing... It as configured before to use 'iPhone Developer' certificate, but when I try with this one I get: Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain Any ideia on how to make it work again? I'm on Lion, with the most recent XCode (latest official, not beta/preview release). --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: can't build iPhone apps, certificate error
Thanks Conrad, Anyway, I found the problem here, and here is the solution if anyone else got in same situation: 1. Open Keychain 2. Go to Preferences 3. Go to tab Certificates 4. Set the first two select elements to Off (it was Best Attempt here) 5. Build the than thing :P This iPhone app Im working for my company, so, they will buy a licence, I'm waiting for them, later I will get one for me, just not now ;) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Mon, Jul 25, 2011 at 3:43 PM, Conrad Shultz con...@synthetiqsolutions.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 7/25/11 11:25 AM, Wilker wrote: Hi Guys, Im starting an iPhone app here, but I just can't build it... XCode clains: CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 4.3' But I don't have one yeth... I was able to develop iPhone apps before without any code signing... It as configured before to use 'iPhone Developer' certificate, but when I try with this one I get: Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain Any ideia on how to make it work again? I'm on Lion, with the most recent XCode (latest official, not beta/preview release). Full disclosure: I am not yet on Lion/Xcode 4 (perhaps thankfully, in light of certain other ongoing conversations on the list). That said, AFAIK you should be able to build without code signing _for the simulator_, so I guess I would start by verifying that your deployment target (or whatever scheme-based terminology Xcode 4 is using) is set to the simulator, not a device (or App Store). The Code Sign error you report means that Xcode (or, more likely, the codesign utility it calls during the build process) was unable to automatically select a certificate and private key from your keychain, which would make sense if you haven't set them up yet. Try configuring your build settings (or whatever the corresponding pane in Xcode 4 is) to not perform code signing period, since you shouldn't need to for simulator. (Btw, you probably should just shell out the $99 and get your signing certificate... not only will you want to test your app on an actual device sooner rather than later, but you will also get access to the relevant dev forums and, more importantly, WWDC videos, if you didn't otherwise have access to them.) - -- Conrad Shultz Synthetiq Solutions www.synthetiqsolutions.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFOLblOaOlrz5+0JdURAl3AAJ96Z6crAbXABx4RkMeOLNpi0ywX3wCfRJ3U GyQ3vN/DyGRUCgL74JulBQ4= =BBiA -END PGP SIGNATURE- ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Does anyone else dislike Xcode 4?
Another cool point of XCode 4 is in fact the Souce Control, using git by start is amazing, and being able to commit (and also edit files while commiting) is really awesome. In really new and started with XCode in the end times of XCode 3, I used XCode 3 just for a few weeks and them XCode 4 was released. I really prefer XCode 4 than 3, its awesome. --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Sun, Jul 24, 2011 at 8:08 PM, Kevin Bracey ke...@ilike.co.nz wrote: I also had concerns re the changes, no-one likes their main work apps changed, for unknown reasons. But there are reasons, and if you watch the WWDC vids on Xcode you will learn how to make the most of these changes and why Apple has made this change. Mastering Schemes in Xcode 4 Mastering Source Control in Xcode 4 Maximizing Productivity in Xcode 4 are good. cheers Kevin___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/wilkerlucio%40gmail.com This email sent to wilkerlu...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
problem with dataWithContentsOfFile on Lion
Hi guys, I updated to Lion yesterday, but I'm having an issue now with [NSData dataWithContentsOfFile] This code is to generate a hash based on 64kb of start and 64kb of end from a file: + (NSString *)generateHashFromPath:(NSString *)path { const NSUInteger CHUNK_SIZE = 65536; NSError *error = nil; NSData *fileData = [NSData dataWithContentsOfFile:path options: NSDataReadingMapped | NSDataReadingUncached error:error]; if (error) { return nil; } const uint8_t* buffer = [fileData bytes]; NSUInteger byteLength = [fileData length]; NSUInteger byteOffset = 0; if (byteLength CHUNK_SIZE) { byteOffset = byteLength - CHUNK_SIZE; byteLength = CHUNK_SIZE; } CC_MD5_CTX md5; CC_MD5_Init(md5); CC_MD5_Update(md5, buffer, (CC_LONG) byteLength); CC_MD5_Update(md5, buffer + byteOffset, (CC_LONG) byteLength); unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5_Final(digest, md5); NSMutableString *hexDigest = [NSMutableString stringWithCapacity: CC_MD5_DIGEST_LENGTH * 2]; for (int i = 0; i CC_MD5_DIGEST_LENGTH; i++) { [hexDigest appendFormat:@%02x, digest[i]]; } return [hexDigest lowercaseString]; } Before Lion, it really works well and fast, even on Wifi external drive (through Airport Extreme), but now it get's really slow... I did some checks, and now its reading the entire file... instead of just read 128kb (start and end). Anyone have an ideia on why its happening now? And how to make it works as before on Snow Leopard? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem with dataWithContentsOfFile on Lion
Thanks guys, I changed to NSDataReadingMappedAlways, since I will read just a little piece of data (which is generally really fast) is that ok, the crash risk is really low, so, I mean my software can live with that. --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Jul 21, 2011 at 5:30 PM, Greg Guerin glgue...@amug.org wrote: Wilker wrote: Before Lion, it really works well and fast, even on Wifi external drive (through Airport Extreme), but now it get's really slow... I did some checks, and now its reading the entire file... instead of just read 128kb (start and end). Anyone have an ideia on why its happening now? And how to make it works as before on Snow Leopard? You could use fopen(), fseek(), fread(), fclose(). Who knows, it might even be faster, since it doesn't have to call mmap(). Worst case, you call mmap() yourself. -- GG __**_ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.**apple.comhttp://lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/**mailman/options/cocoa-dev/** wilkerlucio%40gmail.comhttp://lists.apple.com/mailman/options/cocoa-dev/wilkerlucio%40gmail.com This email sent to wilkerlu...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
simple multipart upload implementation
Hi guys, Last days I spent a lot of time searching for multipart upload solutions to use in a Mac Cocoa project. The fact was I just found bad documented or too much complicated solutions... So I decided to develop one on my own. The result was this library here: https://github.com/wilkerlucio/cocoa_simple_multipart I'm still an obj-c newbie, so, the implementation is probably far away for an ideal one, but it's working for me (in my case, it's just small files being sent). So, I'm sharing this with you, so, if anyone is needing something simple, it will work, and if some expert here want's to make it better, I will be really happy to accept pull requests to make this library better :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
book about Cocoa testing
Hi fellows, I'm trying to find good material on how to test with XCode 4 default engine, you have any recommendations? Any books or articles that does good explanation will be nice. Thanks --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
getting path for files in test bundle
Hi, I'm trying to do some tests here, but in case my tests have some fixture files (video files), I added them to a group Fixtures on Test target, they are also already on Copy Resources Bundle phase, but I can't get the path for them... I'm trying with: NSString *dexterPath = [[NSBundle mainBundle] pathForResource: @dexter ofType:@mp4]; But it always returns (null) Any ideas on how to make it work? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: getting path for files in test bundle
Thanks a lot Fritz :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Jul 14, 2011 at 8:30 AM, Fritz Anderson fri...@manoverboard.orgwrote: On 14 Jul 2011, at 2:11 AM, Wilker wrote: I'm trying to do some tests here, but in case my tests have some fixture files (video files), I added them to a group Fixtures on Test target, they are also already on Copy Resources Bundle phase, but I can't get the path for them... I'm trying with: NSString *dexterPath = [[NSBundle mainBundle] pathForResource: @dexter ofType:@mp4]; [NSBundle bundleForClass: [self class]]. The test suite runs in the context of the application under test, and is not in the main bundle. Also, the group in which a file appears in the Project navigator has no influence over its role in the product; that's a matter for the build phases. — F ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
problem with applying md5 to data
Hi guys, I need to generate a hash from a file, the hash algorithm is here: http://thesubdb.com/api/ I'm trying to implement it on Objective-C but I'm having really trouble on it... This is my current implementation: // // SMSubdbSource.m // Subtitle Master // // Created by Wilker Lúcio da Silva on 6/23/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import SMSubdbSource.h #import CommonCrypto/CommonDigest.h @implementation SMSubdbSource +(NSString *)md5:(NSString *)str { const char *cStr = [str UTF8String]; unsigned char result[16]; CC_MD5(cStr, (unsigned int) strlen(cStr), result); return [NSString stringWithFormat: @%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X, result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15] ]; } +(NSString *)generateHashFromPath:(NSString *)path { const NSUInteger CHUNK_SIZE = 65536; NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path]; if (file == nil) return nil; unsigned long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize]; NSMutableData *fileData = [[NSMutableData alloc] initWithCapacity:CHUNK_SIZE * 2]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file seekToFileOffset:MAX(0, fileSize - CHUNK_SIZE)]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file closeFile]; NSString *dataString = [[NSString alloc] initWithData:fileData encoding:NSASCIIStringEncoding]; return [[SMSubdbSource md5:dataString] lowercaseString]; } @end It works well if file only contains ASCII simple chars, but the real files (that contains video binary data) generates wrong hash... I mean the problem should be when trying to generate the string and MD5 digest from it... How I can make it work correctly? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem with applying md5 to data
Thanks for the answer Quincey, I did resolved just before you post here :) Used this (now in separated files): +(NSString *)md5HexDigestFromChar:(const void *)str withLength:(CC_LONG)lenght { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(str, lenght, result); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; for (int i = 0; i CC_MD5_DIGEST_LENGTH; i++) { [ret appendFormat:@%02x, result[i]]; } return [ret lowercaseString]; } +(NSString *)generateHashFromPath:(NSString *)path { const NSUInteger CHUNK_SIZE = 65536; NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path]; if (file == nil) return nil; unsigned long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize]; NSMutableData *fileData = [[NSMutableData alloc] initWithCapacity:CHUNK_SIZE * 2]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file seekToFileOffset:MAX(0, fileSize - CHUNK_SIZE)]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file closeFile]; return [SMEncodingUtilities md5HexDigestFromChar:[fileData bytes] withLength:(unsigned int)[fileData length]]; } You said the way I readed the file is bad... But I don't need to read the entire file, just 64kb of first, and 64kb of last, are you sure that will be better to read it entirely? Thanks for the support :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jun 29, 2011 at 4:27 AM, Quincey Morris quinceymor...@earthlink.net wrote: On Jun 29, 2011, at 00:02, Wilker wrote: I'm trying to implement it on Objective-C but I'm having really trouble on it... There are many things wrong with your implementation. +(NSString *)generateHashFromPath:(NSString *)path { const NSUInteger CHUNK_SIZE = 65536; NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path]; if (file == nil) return nil; unsigned long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize]; NSMutableData *fileData = [[NSMutableData alloc] initWithCapacity:CHUNK_SIZE * 2]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file seekToFileOffset:MAX(0, fileSize - CHUNK_SIZE)]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file closeFile]; This is not the worst way to read the entire contents of a file into a NSData object, but it's pretty bad. :) It would be far easier and more efficient to use [NSData dataWithContentsOfFile: path options: NSDataReadingMapped | NSDataReadingUncached error: NULL]; NSString *dataString = [[NSString alloc] initWithData:fileData encoding:NSASCIIStringEncoding]; You say the file contains binary data. Running it through the ASCII string encoding is going to throw away every character that isn't ASCII (i.e. it will throw away every character with its high order bit set). That isn't what you want. Also, converting a large NSData object to a NSString via any encoding is going to be horrendously expensive (in CPU and memory cost). That isn't what you want. return [[SMSubdbSource md5:dataString] lowercaseString]; } +(NSString *)md5:(NSString *)str { const char *cStr = [str UTF8String]; Since you're passing in a (NSString) string of ASCII characters, you're going to get out a (C) string of exactly the same ASCII characters, since ASCII characters are represented by themselves in UTF8. This isn't what you want. unsigned char result[16]; CC_MD5(cStr, (unsigned int) strlen(cStr), result); return [NSString stringWithFormat: @%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X, result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15] ]; } If you're trying to compute the digest of the binary data, you can compute it directly from the NSData object like this: CC_MD5 (fileData.bytes, fileData.length, result); ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem with applying md5 to data
Thanks Quincey, these things for sure will be a lot helpful, Im still pretty new to Objective-C, but I will look in all of those things that you said, thanks :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jun 29, 2011 at 5:13 AM, Quincey Morris quinceymor...@earthlink.net wrote: On Jun 29, 2011, at 00:27, Quincey Morris wrote: [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file seekToFileOffset:MAX(0, fileSize - CHUNK_SIZE)]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file closeFile]; This is not the worst way to read the entire contents of a file into a NSData object, but it's pretty bad. :) It would be far easier and more efficient to use [NSData dataWithContentsOfFile: path options: NSDataReadingMapped | NSDataReadingUncached error: NULL]; Er, two things. I didn't notice until after I posted that you weren't reading the whole file. So, sorry, pretty bad was too strong -- I'm upgrading my response to not the best. :) I think the way I suggested is still the best way, because (typically) using the NSDataReadingMapped means the file contents are mapped into virtual memory, so pages (4KB, or whatever the VM page size is) are not actually read until you try to access them. If you use CC_MD5_Init/Update (first part)/Update (last part)/Final instead of the convenience method that does it all, only the parts of the file you need will actually be read. NSDataReadingMapped is in general the most efficient way to read a file when you only need to read any part once, I think. The problem with NSFileHandle is that it pretty much sucks as a class. It doesn't return any errors, so if something goes wrong it's either going to throw an exception or just ignore it. IIRC it has no API contract regarding error reporting. Second thing... I forgot to point out that your code has a glaring bug. With your declarations, 'fileSize - CHUNK_SIZE' in 'MAX(0, fileSize - CHUNK_SIZE)' is an unsigned expression. It can't go negative, and so that statement isn't doing what it looks like it's doing. One more thing ... Since you have no release/retain calls, I'm assuming you're using garbage collection. If that's the case, then this line is very, very dangerous: return [SMEncodingUtilities md5HexDigestFromChar:[fileData bytes] withLength:(unsigned int)[fileData length]]; You're passing an *interior* pointer to fileData's private storage, but the (compiler-optimized) lifetime of 'fileData' ends *before* the md5 method is entered, and so the object is subject to being collected *before* you've used the pointer. This will crash. In your code, the window of danger is pretty small. But it will crash eventually. The solution is to put a reference to the object after the call: NSString* result = [SMEncodingUtilities md5HexDigestFromChar:[fileData bytes] withLength:(unsigned int)[fileData length]]; [fileData self]; return result; It's a PITA, but you gotta be careful with NSData. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem with applying md5 to data
Quincey, I did some changes following your recommendations, this is my current version: +(NSString *)generateHashFromPath:(NSString *)path { const NSUInteger CHUNK_SIZE = 65536; NSData *fileData = [NSData dataWithContentsOfFile:path options:NSDataReadingMapped | NSDataReadingUncached error:NULL]; char buffer[CHUNK_SIZE]; CC_MD5_CTX md5; CC_MD5_Init(md5); [fileData getBytes:buffer range:NSMakeRange(0, CHUNK_SIZE)]; CC_MD5_Update(md5, buffer, CHUNK_SIZE); [fileData getBytes:buffer range:NSMakeRange(MAX(0, [fileData length] - CHUNK_SIZE), CHUNK_SIZE)]; CC_MD5_Update(md5, buffer, CHUNK_SIZE); unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5_Final(digest, md5); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; for (int i = 0; i CC_MD5_DIGEST_LENGTH; i++) { [ret appendFormat:@%02x, digest[i]]; } return [ret lowercaseString]; } Any other tip for improving it? (I know, I still need to handle the errors, hehe, but anything else?) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jun 29, 2011 at 10:31 AM, Wilker wilkerlu...@gmail.com wrote: Thanks Quincey, these things for sure will be a lot helpful, Im still pretty new to Objective-C, but I will look in all of those things that you said, thanks :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jun 29, 2011 at 5:13 AM, Quincey Morris quinceymor...@earthlink.net wrote: On Jun 29, 2011, at 00:27, Quincey Morris wrote: [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file seekToFileOffset:MAX(0, fileSize - CHUNK_SIZE)]; [fileData appendData:[file readDataOfLength:CHUNK_SIZE]]; [file closeFile]; This is not the worst way to read the entire contents of a file into a NSData object, but it's pretty bad. :) It would be far easier and more efficient to use [NSData dataWithContentsOfFile: path options: NSDataReadingMapped | NSDataReadingUncached error: NULL]; Er, two things. I didn't notice until after I posted that you weren't reading the whole file. So, sorry, pretty bad was too strong -- I'm upgrading my response to not the best. :) I think the way I suggested is still the best way, because (typically) using the NSDataReadingMapped means the file contents are mapped into virtual memory, so pages (4KB, or whatever the VM page size is) are not actually read until you try to access them. If you use CC_MD5_Init/Update (first part)/Update (last part)/Final instead of the convenience method that does it all, only the parts of the file you need will actually be read. NSDataReadingMapped is in general the most efficient way to read a file when you only need to read any part once, I think. The problem with NSFileHandle is that it pretty much sucks as a class. It doesn't return any errors, so if something goes wrong it's either going to throw an exception or just ignore it. IIRC it has no API contract regarding error reporting. Second thing... I forgot to point out that your code has a glaring bug. With your declarations, 'fileSize - CHUNK_SIZE' in 'MAX(0, fileSize - CHUNK_SIZE)' is an unsigned expression. It can't go negative, and so that statement isn't doing what it looks like it's doing. One more thing ... Since you have no release/retain calls, I'm assuming you're using garbage collection. If that's the case, then this line is very, very dangerous: return [SMEncodingUtilities md5HexDigestFromChar:[fileData bytes] withLength:(unsigned int)[fileData length]]; You're passing an *interior* pointer to fileData's private storage, but the (compiler-optimized) lifetime of 'fileData' ends *before* the md5 method is entered, and so the object is subject to being collected *before* you've used the pointer. This will crash. In your code, the window of danger is pretty small. But it will crash eventually. The solution is to put a reference to the object after the call: NSString* result = [SMEncodingUtilities md5HexDigestFromChar:[fileData bytes] withLength:(unsigned int)[fileData length]]; [fileData self]; return result; It's a PITA, but you gotta be careful with NSData. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem with applying md5 to data
Thanks again Quincey. Just for curiousity, if I do the line: const uint8_t* buffer = [fileData bytes]; it will not read the entire file? or these address are pointed direct on disk so they are load on demand? also, just to mean if I understand here: CC_MD5_Update(md5, buffer + byteOffset, byteLength); in the sum buffer + byteOffset, in case, adding a number to an array pointer will change it offset? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jun 29, 2011 at 2:53 PM, Quincey Morris quinceymor...@earthlink.net wrote: On Jun 29, 2011, at 07:08, Wilker wrote: char buffer[CHUNK_SIZE]; [fileData getBytes:buffer range:NSMakeRange(0, CHUNK_SIZE)]; CC_MD5_Update(md5, buffer, CHUNK_SIZE); [fileData getBytes:buffer range:NSMakeRange(MAX(0, [fileData length] - CHUNK_SIZE), CHUNK_SIZE)]; CC_MD5_Update(md5, buffer, CHUNK_SIZE); Personally, having tried to get the file reads as cheaply as possible**, I'd just do this: const uint8_t* buffer = [fileData bytes]; // calculate byteLength and byteOffset (see below) CC_MD5_Update(md5, buffer, byteLength); CC_MD5_Update(md5, buffer + byteOffset, byteLength); [fileData self]; to avoid copying the raw data unnecessarily. Your code still has the bug in the MAX parameters (if [fileData length] CHUNK_SIZE, then [fileData length] - CHUNK_SIZE is a *very* large positive number), and you've introduced a new one -- 'getBytes:range:' will crash if the range goes past the end of the NSData data, so I'd calculate the length and offset like this: NSUInteger byteLength = [fileData length]; NSUInteger byteOffset = 0; if (byteLength CHUNK_SIZE) { // *** byteLength = CHUNK_SIZE; byteOffset = byteLength - CHUNK_SIZE; } ** There are some drawbacks to using very large stack-based structures. At least: a. If this code is ever part of a background thread, the default maximum stack size isn't large enough to accommodate 65K data structures. b. If this is running under garbage collection, the collector must scan the entire 65K every time it runs, uselessly and wastefully. What's the usual way to solve these problems? To move the data structure off the stack into the heap. But you already have the data in the heap, in your NSData object. *** Someone once pointed out on this list that you should never use MIN and MAX (and other such convenience macros) in production code, because you are never quite certain how they're implemented (in terms of handling mismatched sign expressions, for example) and how they might be implemented on some future platform you might want to port this code to. Therefore, he said, you should write the code you want, not hope for the code you need. I think maybe his point was a little obsessive, but I have to admit I now cringe and hesitate before writing MIN or MAX. :) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem with applying md5 to data
Nice :) This is my latest code, I mean it should be right now, hehe (and yeth, Im using GC): +(NSString *)generateHashFromPath:(NSString *)path { const NSUInteger CHUNK_SIZE = 65536; NSError *error = nil; NSData *fileData = [NSData dataWithContentsOfFile:path options:NSDataReadingMapped | NSDataReadingUncached error:error]; if (error) { return nil; } const uint8_t* buffer = [fileData bytes]; NSUInteger byteLength = [fileData length]; NSUInteger byteOffset = 0; if (byteLength CHUNK_SIZE) { byteOffset = byteLength - CHUNK_SIZE; byteLength = CHUNK_SIZE; } CC_MD5_CTX md5; CC_MD5_Init(md5); CC_MD5_Update(md5, buffer, (unsigned int) byteLength); CC_MD5_Update(md5, buffer + byteOffset, (unsigned int) byteLength); unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5_Final(digest, md5); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; for (int i = 0; i CC_MD5_DIGEST_LENGTH; i++) { [ret appendFormat:@%02x, digest[i]]; } return [ret lowercaseString]; } I tried it against a video of 8.5GB, stored on external drive (at wifi with Airport Extreme), and it's blazing fast :) Thanks a lot --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jun 29, 2011 at 4:18 PM, Quincey Morris quinceymor...@earthlink.net wrote: On Jun 29, 2011, at 11:32, Wilker wrote: Just for curiousity, if I do the line: const uint8_t* buffer = [fileData bytes]; it will not read the entire file? or these address are pointed direct on disk so they are load on demand? [fileData bytes] is a pointer to some memory address or other, in your application's virtual memory address space. The actual pages of data don't exist yet, they are indeed loaded on demand. The demand will happen when CC_MD5_Update tries to retrieve bytes to update its calculations. As its internal pointer increments into each new page, its data accesses will cause VM faults, which will cause the pages to be read from disk, which in this case is your video file. That's why this is efficient. A normal read will transfer pages of data into the system's disk cache, then transfer some of it again into your application's address space, and if those pages in your address space happen to be swapped out sometime, your data is written *back* to disk (in the system VM backing store) for later rereading. Using mapped reads with no caching avoids all of that. also, just to mean if I understand here: CC_MD5_Update(md5, buffer + byteOffset, byteLength); in the sum buffer + byteOffset, in case, adding a number to an array pointer will change it offset? 'buffer' is not an array, it's just a pointer. It's a pointer to an array of bytes, if you choose to think of it that way, but so are all pointers, if you choose to think of them that way. Think of it this way. You were using 'getBytes:range:NSMakeRange(offset,length)' to copy the bytes to a local buffer. That buffer must have copied the bytes *from* somewhere. The place where the bytes are being copied from is, literally, '[fileData bytes] + offset', and NSData's API makes it perfectly legal to go to the source yourself. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem with applying md5 to data
Thanks :) I will make the conversion to CC_LONG to be more clear, but about the bug, I mean it will be impossible to happen on this case, since the max length will be always 64kb :) About the remote thing, I mean its more low level things, the HD is just mounted as an Volume (on /Volumes/Wilker-1), so, I mean the handling on this case should be transparent, the low level drivers should take care of it :) I learned a lot from this thread, thanks :) --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jun 29, 2011 at 5:31 PM, Quincey Morris quinceymor...@earthlink.net wrote: On Jun 29, 2011, at 12:26, Wilker wrote: +(NSString *)generateHashFromPath:(NSString *)path { const NSUInteger CHUNK_SIZE = 65536; NSError *error = nil; NSData *fileData = [NSData dataWithContentsOfFile:path options:NSDataReadingMapped | NSDataReadingUncached error:error]; if (error) { return nil; } const uint8_t* buffer = [fileData bytes]; NSUInteger byteLength = [fileData length]; NSUInteger byteOffset = 0; if (byteLength CHUNK_SIZE) { byteOffset = byteLength - CHUNK_SIZE; byteLength = CHUNK_SIZE; } CC_MD5_CTX md5; CC_MD5_Init(md5); CC_MD5_Update(md5, buffer, (unsigned int) byteLength); CC_MD5_Update(md5, buffer + byteOffset, (unsigned int) byteLength); unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5_Final(digest, md5); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; for (int i = 0; i CC_MD5_DIGEST_LENGTH; i++) { [ret appendFormat:@%02x, digest[i]]; } return [ret lowercaseString]; } This looks good to me, but since we're noodling around various topics here, let me nitpick at some details: 1. Format specifier '%x' produces lower case letters, so you don't need to lowercase the returned string. If you'd happened to want uppercase, there's '%X'. If you're just trying to return an immutable string, there are three possible answers: a. Don't bother. It's almost always fine to return a NSMutableString when your method's API's return type says NSString. b. Return '[ret copy]'. That allows NSString to do the fastest copy of the character data that it's capable of. The result is an immutable string. c. Go back to the way you first did it, where you spelled out the entire format string, so you don't ever create a NSMutableString. 2. There still a flashing danger signal in your code. Pretty much any time you have to cast a scalar type, your code gets smelly ( http://en.wikipedia.org/wiki/Code_smell). If you consult the CC_MD5 man page, you'll see that the length parameter type is officially CC_LONG. What happens if byteLength is bigger than the largest possible CC_LONG? (In other words, what happens if your file is bigger than 4GB?) WIth this code, the consequences would not be catastrophic, but the wrong digest would likely be calculated. So, declare 'byteLength' as type CC_LONG and get rid of those ad hoc casts. You might still need a cast, but pair it with a safety check: CC_LONG byteLength = (CC_LONG) ([file length] CHUNK_SIZE ? CHUNK_SIZE : [file length]); That messes up the setting of byteOffset, so you need to change that to something like: NSUInteger byteOffset = [file length] CHUNK_SIZE ? [file length] - CHUNK_SIZE : 0; Depending on your aesthetic tastes, you might actually want to do: NSUInteger fileLength = [fileData length]; CC_LONG byteLength = (CC_LONG) (fileLength CHUNK_SIZE ? CHUNK_SIZE : fileLength); NSUInteger byteOffset = fileLength CHUNK_SIZE ? fileLength - CHUNK_SIZE : 0; Anyone reading your code can now see that the cast is harmless, because you've explicitly checked for the error condition. I tried it against a video of 8.5GB, stored on external drive (at wifi with Airport Extreme), and it's blazing fast :) This is a remarkable statement, if you think about it. My pitch for 'NSDataReadingMapped' relied on the assumption that the file was local. If NSData is really providing the effect of memory mapping with a remote file, it's really doing a *lot* of heavy lifting for you. That's really quite a surprising result. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Good and updated book for iPhone development
Thanks guys, I bought the: Beginning iPhone 4 Development: Exploring the iOS SDK Kindle Version It seems cool, but I will sure I will look for others later :) Thanks for you suggestions. --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Sat, Jun 4, 2011 at 3:36 AM, Geoffrey GOUTALLIER cod...@farfadet.netwrote: There is an upcoming book from Aaron Hillegass @ Big Nerd Ranch : iOS Programming: The Big Nerd Ranch Guide http://www.amazon.com/iOS-Programming-Ranch-Guide-Guides/dp/0321773772/ref=sr_1_1?ie=UTF8qid=1306951634sr=8-1 Haven't read it yet, as it is not yet released, but I think that it will be a great book, as the Cocoa Programming book, still from Aaron, is a must have. ++ Geoffrey On 4 juin 2011, at 07:42, Rikza Azriyan wrote: Beginning iphone 4 prograaming by jeff lamarche i tought Rikza Azriyan Student of Sriwijaya University Palembang, Indonesia Sent from my iPhone 4 Provided by Telkomsel. On Jun 4, 2011, at 11:46 AM, David Rowland rowla...@sbcglobal.net wrote: I like Programming iOS4 by Matt Neuburg (O'Reilly) David On Jun 2, 2011, at 1:37 AM, Wilker wrote: Hi Guys, I have some general experience on programming (8 years) but I'm just starting on Cocoa / Objective-C world now. Currently I'm reading the: Cocoa Programming by Pragmatic Programmershttp://pragprog.com/titles/dscpq/cocoa-programming http://pragprog.com/titles/dscpq/cocoa-programmingThis book is a nice intro and cover the basics nice, but after I finish it I wanna get some book for iPhone specific stuff, if possible some updated book for XCode 4 and iOS 4. What you guys can recommend to me? Thanks --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/rowlandd%40sbcglobal.net This email sent to rowla...@sbcglobal.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/rikzaxtrmsprt%40yahoo.com This email sent to rikzaxtrms...@yahoo.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/coding%40farfadet.net This email sent to cod...@farfadet.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Good and updated book for iPhone development
Hi Guys, I have some general experience on programming (8 years) but I'm just starting on Cocoa / Objective-C world now. Currently I'm reading the: Cocoa Programming by Pragmatic Programmershttp://pragprog.com/titles/dscpq/cocoa-programming http://pragprog.com/titles/dscpq/cocoa-programmingThis book is a nice intro and cover the basics nice, but after I finish it I wanna get some book for iPhone specific stuff, if possible some updated book for XCode 4 and iOS 4. What you guys can recommend to me? Thanks --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com