Re: Question about matrix of possibilities

2013-10-16 Thread Marco Tabini

On Oct 16, 2013, at 12:48 PM, Eric E. Dolecki edole...@gmail.com wrote:

 I've been asked to make a tableview with 8 rows. Each row has a UISwitch.
 Based on a combination of switch values, the result would be a different
 image displayed to the right of the table (this is for iPad).
 
 How would I best go about covering all of those combinations?
 
 When one switch changes I'll check it's on/off state and then run some
 evaluation method based on the values for all of the switches. How do I do
 that without getting too ugly about it?

There are a bunch of ways to handle this—for example, you can assign each 
switch a power-of-two value based on their index in the tableview's data 
source, and then add the ones that are on together; this will give you a 
separate number for each possible combination, which you can then use as the 
name of the corresponding image (0.png, 1.png … 255.png).
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Third time I ask - please help. How to trace visible change in a UIView (UIWebView)

2013-04-24 Thread Marco Tabini

 I seem to have a loose end though -- when I examine the UIWebView's 
 scrollView property, it initially has a non-nil delegate. I don't know if I 
 should interpose as delegate and after taking my snapshot, call the 
 original delegate, or only set myself as a delegate instead of the original. 
 
 I'm afraid that posing as the delegate but still maintaining the original 
 delegate, may imply that I need to implement the WHOLE delegate protocol, 
 just to pass on all delegate calls to the original delegate.
 
 Any ideas?

Nothing other than trying it out and see what happens… even if you have to 
interpose yourself between the scrollview and its original delegate, 
UIScrollViewDelegate only needs a dozen or so methods anyway.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Third time I ask - please help. How to trace visible change in a UIView (UIWebView)

2013-04-22 Thread Marco Tabini

On 2013-04-22, at 3:26 AM, Motti Shneor su...@bezeqint.net wrote:

 Hello everyone. I asked this several times before, but no one gave any hint 
 -- I'd like to know if anyone here has any clue, at least where to search for 
 an answer.
 
 I need to observe the visible contents of a UIWebView dIsplayed in my iOS 
 application. Each time the visible contents changes, I need to capture the 
 contents as image, and transmit it to our server. A bit like screen-sharing 
 on the Mac, but not for the whole screen contents, just a single view.

My apologies: another possibility would be to poll at regular intervals, but, 
instead of capturing the entire view, use Javascript to pull its HTML tree, 
compare it with the previous version, and perform a new capture if you detect 
changes. It's still brutal, but, in this case, you'd be comparing two strings, 
which is probably less effort than comparing two images and can be easily 
delegated to a secondary thread.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Third time I ask - please help. How to trace visible change in a UIView (UIWebView)

2013-04-22 Thread Marco Tabini

On 2013-04-22, at 9:04 AM, Motti Shneor su...@bezeqint.net wrote:

 To be very precise --- I'd like to know how to be notified about ANY UIView 
 visual change. It somehow seems very obvious to me that such delegate call 
 must exist. Maybe I'm overlooking something very basic here.

I think I had completely misunderstood what you wanted to do! I think what you 
want to do is interpose yourself as the delegate of the UIWebView's 
UIScrollView instance (accessible through the -scrollview property); that lets 
you track changes in scroll position, zoom level, etc. Is that what you meant?


—Mt.

___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to implement readonly property

2012-11-12 Thread Marco Tabini
Looking at the docs, dispatch_once takes care of the synchronization for you:

https://developer.apple.com/library/mac/ipad/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html

It should therefore be thread safe to use without any additional 
synchronization code. 

Sent from my New iPad. I blame all typos on the Fruit Company. May have been 
dictated. 

On 2012-11-12, at 7:56 AM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:

 I have a property:
 
 @property (readonly)  NSDictionary *someDictionary;
 
 This property should be computed on demand, and should be accessible by 
 several threads.
 
 My current implementation is:
 
 - (NSDictionary *)someDictionary;
 {
static NSDictionary *someDictionary;
static dispatch_once_t justOnce;
dispatch_once( justOnce, ^
{
// create a temp dictionary (might take some time)
someDictionary = temp;
}
);
 
return someDictionary;
 }
 
 The first thread which needs someDictionary will trigger its creation. Ok.
 
 But what happens when another thread wants to access someDictionary while it 
 is still being created? I guess it will receive just nil.
 This would be not correct; it really should wait until the dictionary is 
 ready.
 
 How to achieve this? Use a lock? Use @synchronize?
 
 10.8.2 with Arc.
 
 
 Gerriet.
 
 
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/mtabini%40me.com
 
 This email sent to mtab...@me.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to implement readonly property

2012-11-12 Thread Marco Tabini
 This is completely the wrong way to implement a property.  The static 
 variable will be shared between all instances.  Here's how you should be 
 doing a lazy loaded var:
 
 @implementation MyClass
 {
NSDictionary *_someDictionary
 }
 
 - (NSDictionary *)someDictionary
 {
static dispatch_once_t justOnce;
dispatch_once(justOnce, ^
{
someDictionary = [[NSDictionary alloc] initWithObjectsAndKeys: …… 
 nil];
});
return someDictionary;
 }

I don't think this does what you think it does; my understanding is that 
dispatch_once will execute only once for the lifetime of an app, so the code 
you posted will only run once for the first object that requires is, and then 
never run again, resulting in _dictionary being Nil in all other instances.

I understood the OP's request as wanting to implement a singleton, which, based 
on your reading, may not be the case. dispatch_once will be fine for a 
singleton, but if you need a thread-safe, lazily-instantiated read-only 
property, maybe something like this will do the trick:

@implementation MyClass {
  NSDictionary *_someDictionary
}

- (NSDictionary *) someDictionary {
  @synchronized(self) {
if (!_someDictionary) {
  _someDictionary = [[NSDictionary alloc] initWith… ]
}
  }

  return _someDictionary;
}
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC issue

2012-11-07 Thread Marco Tabini
I wonder if the problem might be that data is an autoreleased object, which 
automatically gets dealloc'ed at the end of the autorelease pool (as explained 
in the docs). Have you tried replacing

*error = data

with

*error = [data copy]

and seeing what happens?

On 2012-11-07, at 8:05 AM, Andreas Grosam agro...@onlinehome.de wrote:

 NSDictionary* fetchUser(NSNumber* ID, NSError** error)
 {
id user = nil;
//@autoreleasepool   // crashes when @autoreleasepool is enabled
{
id data = ...; // response body of a HTTP Response (NSData) or NSError 
 object, never nil.
if ([data isKindOfClass:[NSData class]]) {
user = [NSJSONSerialization JSONObjectWithData:data
  options:0
error:error];
}
else if (error) {
*error = data;
}
} // autoreleasepool
return user;
 }

___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: KVG generic enough?

2012-07-18 Thread Marco Tabini

On 2012-07-18, at 9:08 AM, William Squires wsqui...@satx.rr.com wrote:

  Okay, after reading some of the documentation on KVC coding, I understand (I 
 think) that the point is to allow me to specify a property of an object with 
 an NSString, then set/get that property value using KVC (i.e. valueForKey: or 
 setValue:forKey:). But it seems like the fact that there's no way to specify 
 (or grab) the value of the property in a generic-enough manner would be a 
 problem - anyone using it would still have to know the data type of the 
 property they want to access, and thus they might as well just use the 
 accessors. I can see this would work if ObjC had a generic data type (like 
 the 'variant' data type in VB/REALbasic), but AFAIK, ObjC doesn't have such, 
 and valueForKey: returns an id, right?
  How can I determine what I get back? (i.e. what does the id pointer point 
 to? an NSString? an NSNumber? NSDecimalNumber? NSData? another NSObject 
 subclass?)

id *is* ObjC's “variant” type. You can determine the type of the underlying 
data by first determining its class (e.g.: [obj isKindOfClass:[NSString 
class]]), and then going from there. Scalar or composite values are wrapped in 
the appropriate classes—e.g.: NSNumber for numeric values and NSValue for 
generic data. The whole system is really quite flexible, particularly when you 
consider that ObjC, unlike so many other languages, doesn't choke on Nil values.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

[ANN]: Beeblex - Free IAP verification service for iOS

2012-07-18 Thread Marco Tabini
Howdy!

My company launched a (completely free) verification service for in-app 
purchases on iOS, designed for apps that do not have a server-side component.

The service, called Beeblex, requires only minimal set up—we provide a simple 
SDK, which we have also open-sourced, and we perform the validation against 
Apple's IAP services through our own services. It is really free—we don't even 
collect any information we don't absolutely need to run it.

You can find it here: http://www.beeblex.com/


Thanks!


Marco Tabini
416-630-6202 x.666
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to implement an object whose properties are really dictionary entries.

2012-07-11 Thread Marco Tabini

On 2012-07-11, at 10:03 AM, Dave DeLong davedel...@me.com wrote:

 It sounds like the OP is looking for a model object that uses an 
 NSMutableDictionary as the backing store for its properties, as opposed to 
 individual ivars. You can do this. 
 
 You declare all your properties, and you declare a single NSMutableDictionary 
 ivar. All of the properties should be implemented as @dynamic in the .m file. 
 
 Since the properties are dynamic, the compiler will not generate 
 implementations for them. You'll have to do that yourself at runtime. 
 Fortunately, if you know what you're doing, that's not too hard. 
 
 You'll have to override +resolveInstanceMethod: to figure out what the user 
 is trying to do: get or set. You'll use the selector passed in to derive the 
 key under which you're storing the data in the dictionary. With this 
 information, you construct a block of the appropriate signature, capturing 
 whatever information you need, and turn it into an IMP using 
 imp_implementationWithBlock(). You can then add that method to the class 
 using class_addMethod(). 
 

Another way would be to override the invocation forwarding mechanism 
(-forwardInvocation: and -methodSignatureForSelector:) to funnel all the 
messages through a single getter/setter; this would (possibly) mean that less 
code is generated at runtime, perhaps at the expense of some added complexity 
and performance degradation.

I think, however, that the best solution here is to just adopt a newer 
compiler; recent versions of LLVM are capable of automatically synthesizing 
properties[1], and provide support for both literals and boxed expressions[2], 
which make initializing and using both NSArray and NSDictionary much closer to 
what the OP was looking for.


—Mt.


[1]: “Objective-C Autosynthesis of Properties” in 
http://clang.llvm.org/docs/LanguageExtensions.html#objc_lambdas
[2]: http://clang.llvm.org/docs/ObjectiveCLiterals.html



___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Dynamic modification of text search results

2012-07-04 Thread Marco Tabini
 Does anyone have any good suggestions as to how to update my search results 
 when the underlying source text changes? Do I have to listen for all changes 
 from the underlying text objects and try to adapt, or is there a better 
 pattern for doing this? Xcode does this nicely: no matter what changes you 
 make in the editor, the search results seem to be updated on the fly.

Couple of random suggestions:

* If you're using NSAttributedString, you can mark your search results by 
assigning custom attributes to specific ranges of text; as the text changes, 
those attributes will stick around and you can later find them using the 
attribute retrieval methods (I believe that's what Xcode does).

* As an alternative, a more naïve approach could be to simply repeat the search 
every time you detect the text changing, but depending on the size of your text 
files, that could eat up a lot of CPU cycles, and is just inelegant.

I'm sure there are other possibilities, too, but these two are the first ones 
that come to mind.

HTH,


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Dynamic modification of text search results

2012-07-04 Thread Marco Tabini

On 2012-07-04, at 1:01 PM, Martin Hewitson martin.hewit...@aei.mpg.de wrote:

 
 On 4, Jul, 2012, at 03:22 PM, Marco Tabini wrote:
 
 Does anyone have any good suggestions as to how to update my search results 
 when the underlying source text changes? Do I have to listen for all 
 changes from the underlying text objects and try to adapt, or is there a 
 better pattern for doing this? Xcode does this nicely: no matter what 
 changes you make in the editor, the search results seem to be updated on 
 the fly.
 
 Couple of random suggestions:
 
 * If you're using NSAttributedString, you can mark your search results by 
 assigning custom attributes to specific ranges of text; as the text changes, 
 those attributes will stick around and you can later find them using the 
 attribute retrieval methods (I believe that's what Xcode does).
 
 Just a follow up on this. I guess I would have to clear all text attachements 
 of a particular class from all files at the start of a search, right? 
 Otherwise the attachments will build up over time. I don't actually save 
 attributed text to disk (these are plain text files) but even so.  Does that 
 make sense? I wondering how computationally expensive this will turn out to 
 be.

That's correct. My experience has been that NSMutableAttributedString's 
performance is pretty good, but YMMV depending on platform, complexity, and 
size of the data. In my case, I wrote a Markdown syntax highlighter that could 
handily manage multi-MB text files on a run-of-the-mill Macbook. I guess 
there's no way to tell until you try :-)


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Using Instruments to profile UITableView drawing

2012-04-26 Thread Marco Tabini
I wonder if someone could point me to the right way to profile 
poorly-performing custom-drawn UITableView cells. I've come across this problem 
several times, and usually manage to figure out how to solve it, but my process 
is not very scientific—there's far too much trial and error involved, and I 
wonder whether there isn't a known way to pinpoint exactly which part of the 
code causes a table to stutter using Instruments. I've tried Googling for the 
problem, but it seems to me that the vast majority of people giving suggestions 
are focusing on known techniques to make table cells perform, rather than 
trying to understand where an already-implemented table is going astray.

Thanks!


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: iOS App - crash when clearing a UITableDetailView

2012-04-03 Thread Marco Tabini
Hi David—

On 2012-04-03, at 6:33 AM, David Delmonte wrote:

 After changing a setting and removing a subview from a UITableDetailView, I 
 get crashes when I accidentally swipe the detail view.

Can you reduce this down to a code sample? There is no such thing as a 
UITableDetailView (I used to work for the Department of Pedantry ;-)), which 
suggests that this is a custom class you wrote. Perhaps you're removing 
something from your table view in a way that ends up causing the crash. For 
example, are you using a table view with static cells designed in a storyboard? 
If so, removing rows at runtime is going to be very tricky and, unless you take 
a lot of precautions,  you are likely to get crashes. But, as I said, that's 
just a guess and we may be able to help you a bit more if we can see some code.

Cheers,


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Passing data through a segue

2012-04-02 Thread Marco Tabini

On 2012-04-02, at 7:15 AM, Rick Mann wrote:

 Thanks for the quick response.
 
 I think I'm okay with sending stuff through the sender parameter, although I 
 do agree it's a bit ugly.
 
 Problem is, my didSelectRowAtIndexPath isn't getting called... :-( The 
 delegate is set correctly, so I'm assuming iOS doesn't call it in the 
 presence of segues? It IS calling prepareSegue...

Have you tried to override -prepareForSegue:sender: and use -[UITableView 
indexPathForSelectedRow] to retrieve the selected row? That does the trick for 
me.

Incidentally, you'll probably find that -willSelectRowAtIndexPath does get 
called.

Cheers,


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions

2012-03-27 Thread Marco Tabini
Hi Ray—

 But this seems kludgy and it's using programmer's knowledge, so to speak. I 
 watched WWDC2010 session 134 Optimize your iPhone App for the Retina 
 Display again, searched stackoverflow etc. but I can't find a more elegant 
 solution. What would be a more thorough approach? Maybe it's staring me in 
 the face but I don't see it...

UIImage does not represent the actual bits of an image, but, rather, provides 
the logical metadata wrapper of an underlying image object (in this case, a 
CGImage) to store information like scale and orientation. When you save to a 
file format that supports metadata, like JPEG, some of the metadata is stored 
there, while other is derived from the file name. So, for example, if you were 
to save a PNG file to disk with an @2x suffix, upon loading it with 
-imageNamed: UIImage would automatically know to set up the resulting object as 
a 2x scale image.

When the filename convention is not available, that metadata needs to be saved 
somewhere—in your case, you derive it from the file size, which, as you 
mention, is not very portable. I would have saved the scale in a separate Core 
Object property, or avoided saving the image in a data store to start with, and 
used a file cache, in which case UIImage is a bit more self-reliant.

In practice, I would want to look at more significant problems with your 
approach in a real-life deployment scenario. For example, what happens when 
your Core Data store is transferred from a non-Retina device to a Retina 
device? This could happen in a variety of scenarios: the user could start using 
your app on a non-Retina device (say, an iPad 2), then buy a new Retina device 
(a New iPad), back up the old one and restore on the new one. Now, your images 
are cached at 1x scale, but the device wants to run at 2x. Or, perhaps, you 
may, at some point, want to sync your data store using iCloud, causing some 
images to be generated on Retina devices, and some others at 1x scale.

Conversely, if your data is only ever used for caching purposes and is stored 
in the Caches directory, then this is a non-problem. Since the images are both 
going to be generated and used on the very same device, you don't need to 
derive the scale of the image from its size—you can just use the scale of your 
main screen both when creating and recreating your UIImage objects.

Then again, if you move your images to individual files and save them with the 
appropriate @2x suffix, this whole problem goes away altogether—so, perhaps, 
that may be a better solution.

Cheers,


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

UIBezierPath stroke oddity

2012-03-20 Thread Marco Tabini
In an attempt to figure out how well gesture recognizers work, I've built a 
very simple app that uses a UIPanGestureRecognizer and using them to construct 
a UIBezierPath that I then stroke, but I am getting strange artifacts on the 
resulting drawing operation (see http://cl.ly/0N2R411O1t1x3w2N3Q3q for example).

The code I use is fairly simple; I start with a call to -moveToPoint:, followed 
by a bunch of -addLineToPoint: calls. Other than the fact that I am recording 
the points using touch, there is nothing unusual in the code (that I can see):

- (void) pannedRefineEdge:(UIPanGestureRecognizer *) recognizer {
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:

_path = [[UIBezierPath alloc] init];
[_path moveToPoint:[recognizer locationInView:self.backgroundView]];

break;

case UIGestureRecognizerStateChanged:

[_path addLineToPoint:[recognizer 
locationInView:self.backgroundView]];

break;

case UIGestureRecognizerStateEnded:

// This calls a function that sets up an image drawing context and 
then:

_path.lineCapStyle = kCGLineCapRound;
_path.lineJoinStyle = kCGLineJoinRound;
_path.lineWidth = 10.0;

[[UIColor colorWithRed:1.0 green:0.6 blue:0.6 alpha:1.0] setStroke];

[_path stroke];

break;

default:
break;
}
}

Any ideas what could be causing the problem?

Thanks,


Marco
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to get Mac codesign certificate?

2012-03-17 Thread Marco Tabini
On 2012-03-17, at 9:18 AM, Gerriet M. Denkmann wrote:

 But I want to codesign my OS X apps.
 So how do I get the necessary certificate?

You need to buy it from a certificate authority, like Thawte or Verisign (or 
one of the myriad resellers) and they will all be happy to sell you one at 
prices that range from around $80 to around $500/yr. Alternatively, you can get 
a certificate from Apple as part of the OS X Developer Program, which will cost 
you the extra $100/yr but also includes beta access to OS X system software. 

If you have control over the environment on which you deploy your software, you 
can also create a self-signed certificate and, essentially, be your own 
authority by adding yourself as a valid root CA on all the machines on which 
you software will run. If you don't, you can use a self-signed certificate to 
ensure the integrity of your code, but not your identity.

Apple has a bunch of good resources on this topic[1], which are worth a read if 
you want more info.

HTH,


—Mt.

[1]: 
https://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005929-CH1-SW1
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to get Mac codesign certificate?

2012-03-17 Thread Marco Tabini
 Can you not just use a free provider, like http://www.startssl.com/?

I'm not an expert, but I think the free cert they provide cannot be used for 
code signing.

One other alternative may be the Developer ID initiative that Apple has 
announced as part of OS X 10.8 Mountain Lion, but I can't figure out if that's 
still under NDA and don't want to incur the wrath of the mods :-)


—Mt.


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Why so many public properties all up in my grizzle?

2012-03-16 Thread Marco Tabini
 That time has passed now, so you can now completely specify IBOutlets (and 
 IBActions) in your implementation file and hide the details from the outside 
 world. If you want properties, you can use a class extension like so to add 
 them:

Sorry to hijack this conversation, but I've been meaning to ask: Where is this 
documented? I stumbled on this feature (and the ability to declare ivars 
directly in the .m file), but I didn't see it explained it anywhere. I'm sure 
I'm just not looking in the right place, but I can't find it anywhere.

Cheers,


Marco
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: The current preferred method for fetching HTTP URLs for IOS

2012-03-09 Thread Marco Tabini
 I've been reading (and trying out) a few approaches on HTTP communication 
 using GCD to do a dispatch_sync or dispatch_async to a dispatch queue or 
 using an NSURLRequest.
 
 Which of these is the preferred method for ingesting strings from HTTP URLs 
 on iOS?  Are there any plusses to one over the other?

FWIW, my view is that it depends on what your requirements are. For a simple 
request, you can go with an [NSString stringWithContentsOfURL] wrapped in a 
call to dispatch_async to avoid blocking the main thread. 

If you require a more sophisticated level of control over the transaction, 
NSURLRequest is obviously a better choice. Personally, I almost always find 
this to be the case, if only because I can cancel a request if necessary.

As for running an NSURLRequest on a thread other than the main thread, I've 
found very little use for it unless you need the download to continue after 
your app has been pushed into the background. Otherwise, it just introduces an 
additional level of complexity that I prefer to avoid if I can :-)


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: JSON validator for Xcode

2012-03-07 Thread Marco Tabini
 BOOL isTurnableToJSON = [NSJSONSerialization isValidJSONObject: responseData];
   NSLog(@Is legit for JSON: %d, isTurnableToJSON );
   NSLog(@Is legit for JSON: %@, isTurnableToJSON ? @YES : @NO); // 
 this is how we handle a bool :/


Are you sure that you are using isTurnableToJSON the way it's meant to be? My 
understanding is that its job is to check whether an existing Objective-C 
object (like an NSDictionary) can be safely converted to JSON, and not to check 
whether a string contains valid JSON.

From this code, it looks as though you are either trying to validate an NSData 
object—which you can't, because there's no way to represent NSData in JSON—or a 
string that has been converted into an NSData object. In either case, you will 
always get BOOL, and the method is functioning as expected.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Finding object array index when iterating through array

2012-03-07 Thread Marco Tabini
 I have an array and I am iterating through it using this technique:
 
 for (id object in array) {
// do something with object
 }
 
 Is there  way to obtain the object's current array index position or do I 
 have to add a counter?

[array indexOfObject:object] should do the trick, though, if you need to do it 
at every iteration, keeping a counter may be better.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Accessing array in thread safe way

2012-03-06 Thread Marco Tabini
On 2012-03-06, at 2:51 PM, Jan E. Schotsman wrote:

 Hello,
 
 I have an array of progress values (number objects) for subprojects, from 
 which I calculate the overall progress .
 The array is an atomic property of the project class.
 
 Is it safe to access this array from multiple threads, using methods like 
 objectAtIndex and replaceObjectAtIndex?
 

NSMutableArray is not (as far as I know) thread-safe while being mutated[1]. 
That said, it doesn't mean that you can't use the array in a multi-threaded 
environment: Just make sure that writes are all synchronized, and that 
enumerations only happen on immutable copies.

HTH,


—Mt.



[1]: 
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html
 


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Question on handling very large images

2012-03-03 Thread Marco Tabini
 The problem is that if you do this in a naive way, with a single huge pixmap, 
 you will have poor locality of reference. Once you get to 1024 RGBA pixels 
 across, every scan-line will occupy its own memory page. So any operation 
 that crosses lots of scan lines but only uses a small fraction of each one 
 (like drawing a vertical line) may involve a lot of paging.
 
 The usual workaround to that is to instead break the image up into 
 rectangular tiles, and store each as a separate pixmap. That way most 
 localized graphics operations will only involve a fraction of the total 
 number of tiles. (You can see Photoshop do this, if you run a slow operation 
 or if it’s had to page part of the image out to disk.) I think this will also 
 help with the GPU, because CoreGraphics likes to copy pixmaps to GPU memory 
 so they can be rendered and manipulated faster.

Thanks for the helpful tips! That's pretty much how I ended up organizing 
things, and it seems to work OK so far.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Question on handling very large images

2012-03-02 Thread Marco Tabini
Hi Everyone, 

I find myself in the situation of having to manipulate and display a few very 
large images in an app running on iOS (potentially in the tens of megapixels at 
24 bits/pixel), and I am trying to figure out what the correct pattern for 
doing so is. I've Googled for solutions, but there seems to be a large amount 
of variance in the kinds of answers that I've found, so I wanted to ask for 
some advice before heading out on a wild goose chase.

Can anyone share their view or point me in the direction of some good ideas? My 
first instinct is to use a memory-mapped file (e.g.: using NSMutableData) to 
hold the data while I work on it, but I worry that it will be very slow and 
that I'm missing a much simpler solution. All help greatly appreciated!

Cheers,


Marco
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Suggestions for forcing NSSlider to some values, without tickmarks

2012-03-01 Thread Marco Tabini
On 2012-03-01, at 4:18 PM, Sean McBride wrote:

 Hi all,
 
 I have a continuous linear NSSlider who's range is -180 to 180 degrees.  I 
 don't want tick marks because any value is acceptable.  However, the value 
 zero is important, and I need for the user to be able to get to exactly 0.0 
 (0.1 or whatever is no good).
 
 How would you suggest accomplishing this?

Off the top of my head, I would simply fence the NSSlider to zero when its 
value is within a given range from that value: on a change event, if (say) -5 ≤ 
0 ≤ 5, you can force the value to zero. You can then allow for finer tuning of 
the value by implementing the fencing only when the user moves the slides with 
the mouse, and instead allow any value when the user uses the arrow keys to 
reposition the slider's knob.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC in Snow Leopard?

2012-02-11 Thread Marco Tabini
On 2012-02-11, at 6:25 PM, William Squires wrote:

 is ARC a Lion-only feature or will an ARC-compiled app work on 10.6.8 
 assuming no other Lion features are used?

According to Apple, ARC-compiled apps run on SL, but they must be compiled on 
Lion, because the SL version of Xcode doesn't include the 10.7 SDK. More info 
in the Transitioning to ARC guide.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How do you run an app on the device with Instruments?

2012-01-30 Thread Marco Tabini
On 2012-01-30, at 5:10 PM, G S wrote:

 So... no one knows how to launch an app on the device with Instruments?


Launch Instruments
Select an iOS instrument
Click “All Processes,” select your device from the list
Click “All Processes” again, choose “Attach to Progress” is the app is already 
running, or “Choose Target” if it isn't

Is that what you meant, or did I misunderstand your q?


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to get the dispatch queue for the current thread's runloop?

2012-01-27 Thread Marco Tabini
On 2012-01-27, at 2:14 PM, Jens Alfke wrote:

 I'm really used to using -performSelector:withObject:afterDelay: to make 
 something happen later. But I'd much rather use a block than a target/action. 
 I can't find any API for this, however. Am I missing something? What I want 
 is basically like
   PerformBlockAfterDelay(^{ …code here…}, 5.0);
 
 It looks like I should just call dispatch_async, but I'm unsure which 
 dispatch queue to use. dispatch_get_main_queue only works for the main 
 thread. Can I use dispatch_get_current_queue? I'm unsure of what this does 
 when called on a background thread. The API docs say If the call is made 
 from any other thread, this function returns the default concurrent queue … 
 is that a queue associated with the thread's runloop, that's guaranteed to 
 execute tasks on that thread?

I just use a little category on NSObject that I think I pulled from 
somewhere—but I can't remember where from:

#pragma mark -
#pragma mark Delayed block execution


- (void) performBlock:(void (^)(void)) block afterDelay:(NSTimeInterval) delay {
block = [block copy];

[self performSelector:@selector(fireBlockAfterDelay:) 
   withObject:block 
   afterDelay:delay];
}


- (void)fireBlockAfterDelay:(void (^)(void))block {
block();
}

This is pretty old code (it relies on ARC, though), so there might be a better 
way to do it these days.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC and blocks

2012-01-26 Thread Marco Tabini
On 2012-01-26, at 3:51 PM, Jan E. Schotsman wrote:

 Hello,
 
 This code is given in the Transitioning to ARC Release Notes as an example 
 of accomodating blocks in an ARC environment:
 
 __block MyViewController *myController = [[MyViewController alloc] init…];
 // ...
 myController.completionHandler =  ^(NSInteger result) {
[myController dismissViewControllerAnimated:YES completion:nil];
myController = nil;
 };
 
 Supposedly this avoids a retain cycle. But where is the cycle? At least two 
 objects are needed for a cycle. What is the second one?

ARC has changed the behaviour of __block [1] so that it forces a retain of the 
value (previously, it forced a variable to behave like a weak property). This 
(as I understand it) is necessary because otherwise the value would be released 
at the end of the current method, which is obviously not what you want. Note 
that, even if you don't specify myController as __block, the variable will 
still be declared with an implicit __strong attribute.

The key is that, by declaring it as __block, you give your block the option to 
alter its contents. At the end of the block, you simply force it to Nil, which 
implicitly releases it, thus breaking the retain cycle. Pretty neat, eh?

HTH,


—Mt.


[1]: See the CLANG docs, section 7.5.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC and blocks

2012-01-26 Thread Marco Tabini
On 2012-01-26, at 6:09 PM, Jeff Kelley wrote:

 Without ARC, you would use __block to prevent the block from retaining the 
 object and causing the retain cycle. With ARC, however, the object is 
 retained when you put it into the variable, so to avoid a retain cycle, you 
 have to declare it like so:
 
   __unsafe_unretained __block MyViewController *myController = …
 
 It looks awful, yes, but without the first piece we were having extreme 
 memory leaks.

Maybe I'm reading this wrong, but I think this might be a bit too unsafe. If 
you declare something as __unsafe_unretained, ARC won't try to track the 
variable through its lifetime, so if for some reason that variable is 
deallocated and then your block gets called, your app will crash. The OP's code 
feels a bit safer to me: it retains the variable strongly, then Nils it at the 
end of the block to force a release. There's no retain cycle or memory leak, 
and the __block variable is guaranteed to stick around until your block is done 
with it.


—Mt.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Angle of touch point from center of view?

2012-01-08 Thread Marco Tabini
On 2012-01-05, at 1:49 PM, Eric E. Dolecki wrote:

 I'd like to calculate the angle from a center point of a view to a touch
 point.
 
 0º behind top of screen, 180º being bottom of screen.
 
 Calculating from touchesMoved.

I think you can just retrieve the arctangent between the x axis and the vector 
formed by the origin and location of the touch (reversing the y coordinate). 
For example:

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint center = self.center;
CGPoint location = [[touches anyObject] locationInView:self];

CGPoint vectorOfInterest = CGPointMake(location.x - center.x, center.y - 
location.y);

NSLog(@Vector: %@, Angle: %.2fº, 
  NSStringFromCGPoint(vectorOfInterest), 
  atan2(vectorOfInterest.x, vectorOfInterest.y) * 57.29);
}

The resulting angle will be [0, π) clockwise starting from the top, and [-π, 0) 
from the bottom (or something like that—my trig is horribly rusty).

HTH,


—Mt.___

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: Saving PNG files from NSImage

2011-08-29 Thread Marco Tabini
Hi Martin—

On 2011-08-29, at 8:18 AM, Martin Linklater wrote:

 Can anyone point me in the right direction as to how to save my NSImage to a 
 PNG file ? Or some documentation which actually describes how to convert the 
 NSCGImageSnapshotRep into something I can save out ? I've spent a few hours 
 on this now and I can't believe there isn't an easy solution I'm missing.


Take a look here: 
http://stackoverflow.com/questions/4438802/nscgimagesnapshotrep-how-get-bitmapdata

HTH,


—Mt.

--
Phone: +1-416-630-6202 x.666
Twitter: @mtabini


___

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