Date   

Re: Why would an instance of NSMutableArray be immutable?

 



On May 28, 2019, at 9:38 AM, James Walker <list2@...> wrote:

 po [formatsOfSize isKindOfClass: [NSMutableArray class]]

and the reply was '\x01'.  So it should be mutable, no?

Nope. This is due to the way CF bridging works — the magic class __NSCFArray (?) is bridged to CFArray and CFMutableArray. To support mutable arrays, that means __NSCFArray has to subclass NSMutableArray. So all bridged NSArrays subclass NSMutableArray, whether or not the instance is mutable.

 Is there a better run-time test for mutability?

There is no good test other than seeing if it throws an exception when you try to mutate it. :-p

At some point in your code you improperly cast something to NSMutableArray when you didn’t actually have a guarantee it was mutable; you may need to do a code review to figure out where. 

(It can be hard to tell, since Obj-C lets you implicitly cast from ‘id’ to an explicit class. I sometimes grouse about C++ making me write these explicitly, but it does make it clearer where I’m doing the type-casts.)

—Jens


Why would an instance of NSMutableArray be immutable?

James Walker
 

I was trying to add an object to an array and got an exception saying that I was trying to modify an immutable object. I set a breakpoint just before the addObject: line, and said to lldb

po [formatsOfSize isKindOfClass: [NSMutableArray class]]

and the reply was '\x01'. So it should be mutable, no? Is there a better run-time test for mutability?

If it's a clue,

po [formatsOfSize class]

produced

__NSCFArray
.


Re: Some gestures aren't working right away

Steve Mills
 

No ideas about this?

I have an iOS app that's giving me a pain. One view hierarchy has a scroll view, page view, and other views. The storyboard has 3 gesture recognizers scattered among a couple of the view controllers. The code has a few shouldBeRequiredToFailByGestureRecognizer and shouldRequireFailureOfGestureRecognizer delegate methods. The problem I'm seeing is that right after I segue to this view hierarchy and attempt to use one particular gesture (long press with 1 tap), it doesn't even get the gestureRecognizerShouldBegin message, but eventually seemingly times out and other gestures will fire, such as my single tap gesture or the page view's next page gesture. But after doing ANY gesture, this gesture behaves like it should.

I've tried logging all the pairs of gesture recognizers sent to all of the delegate methods. The strange thing is that the logged pairs of gesture recognizers is different on that first attempt to use the gesture in question than it is on every other time.

I was hoping the Simulator or Xcode had some sort of gesture debugging, like a way to spit out info about which gesture recognizers were attempted, failed, skipped, etc. But nope. So, what things can I try? I'm at a loss.

--
Steve Mills
Drummer, Mac geek


Some gestures aren't working right away

Steve Mills
 

I have an iOS app that's giving me a pain. One view hierarchy has a scroll view, page view, and other views. The storyboard has 3 gesture recognizers scattered among a couple of the view controllers. The code has a few shouldBeRequiredToFailByGestureRecognizer and shouldRequireFailureOfGestureRecognizer delegate methods. The problem I'm seeing is that right after I segue to this view hierarchy and attempt to use one particular gesture (long press with 1 tap), it doesn't even get the gestureRecognizerShouldBegin message, but eventually seemingly times out and other gestures will fire, such as my single tap gesture or the page view's next page gesture. But after doing ANY gesture, this gesture behaves like it should.

I've tried logging all the pairs of gesture recognizers sent to all of the delegate methods. The strange thing is that the logged pairs of gesture recognizers is different on that first attempt to use the gesture in question than it is on every other time.

I was hoping the Simulator or Xcode had some sort of gesture debugging, like a way to spit out info about which gesture recognizers were attempted, failed, skipped, etc. But nope. So, what things can I try? I'm at a loss.

--
Steve Mills
Drummer, Mac geek


Dragging a file unto an app in iOS simulator

Owen Hartnett
 

Hi:

Previously, you could drag and drop from the Mac desktop over an app in iOS Simulator, and if the app was set up for that file extension, it would open the app and open the file through the application:OpenURL:... method. Now dragging the file adds it to the “Files” app and it doesn’t seem to open from there. Is there a way to force a dragged file to open in its native app as before?

-Owen


Re: flagsChanged: not being called on NSControl subclass

Steve Mills
 

On May 20, 2019, at 11:29, James Walker <list2@...> wrote:

Does your control actually become first responder? That might be necessary for flagsChanged: to go to your control.
Aha! No, it was not. It does now and I’m getting flagsChanged. I guess that makes sense that the OS only sends those to the firstResponder. Thanks for your hunch.

Another option might be to use +[NSEvent addLocalMonitorForEventsMatchingMask:handler:].
Extending your suggestion, I added a global monitor so I could change the cursor in my floating window when the app wasn’t frontmost, but sadly it appears you can’t change the cursor when you’re not the front app, even if the mouse is over your window that’s in front of other apps’ windows. Oh well. The app I’m replacing couldn’t do that either.

Steve via iPhone


Re: flagsChanged: not being called on NSControl subclass

James Walker
 

On 5/17/19 11:22 PM, Steve Mills via Groups.Io wrote:
What do you have to do these days to make this work? I tried returning YES from acceptsFirstResponder, as was suggested somewhere.
There is 1 NSTrackingArea added to the view, using options NSTrackingCursorUpdate | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag.
isOpaque returns NO.
Not sure what else to try. Just trying to set the cursor when modifiers change.

Does your control actually become first responder? That might be necessary for flagsChanged: to go to your control.

A less than perfect option would be to poll the modifier flags on mouse moves.

Another option might be to use +[NSEvent addLocalMonitorForEventsMatchingMask:handler:].

The only case in which I have personal experience with receiving NSFlagsChanged is when I wrote my own local event loop that repeatedly called -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:].


Re: How to Display a Time Interval

Dave
 

They wanted the number of weeks - I didn’t ask questions, plus the Total Number of Weeks and Total Number of days.

Cheers
Dave

On 20 May 2019, at 14:50, Steve Mills via Groups.Io <sjmills@...> wrote:

On May 20, 2019, at 04:26:31, Dave <dave@...> wrote:

As far as I know I don’t have to worry about leap years, get the Interval between now and some future date, this includes all the leap years in between. I am displaying it at the moment by dividing by the number of seconds in a year, week, hours and minute which is accurate enough for this applications.

Here is a method to do it:


#define kLTWTimeSecondsPerMinute 60
#define kLTWTimeMinutesPerHour 60
#define kLTWTimeSecondsPerHour (kLTWTimeSecondsPerMinute * kLTWTimeMinutesPerHour)
#define kLTWTimeHoursPerDay 24
#define kLTWTimeDaysPerWeek 7
#define kLTWTimeWeeksPerYear 52

#define kLTWTimeSecondsPerDay (kLTWTimeSecondsPerHour * kLTWTimeHoursPerDay)
#define kLTWTimeSecondsPerWeek (kLTWTimeSecondsPerDay * kLTWTimeDaysPerWeek)
#define kLTWTimeSecondsPerYear (kLTWTimeSecondsPerWeek * kLTWTimeWeeksPerYear)
*snip*

I'm not sure why you needed to reinvent the wheel when NSCalendar and NSDateComponents already does this via:

-(NSDateComponents*) components:(NSCalendarUnit)unitFlags fromDate:(NSDate*)startingDate toDate:(NSDate*)resultDate options:(NSCalendarOptions)opts;

All you need to do is format the string, like you did. Plus, you didn't display months, and most people would want to see that rather than having to do math in their head.

--
Steve Mills
Drummer, Mac geek




Re: How to Display a Time Interval

Steve Mills
 

On May 20, 2019, at 04:26:31, Dave <dave@...> wrote:

As far as I know I don’t have to worry about leap years, get the Interval between now and some future date, this includes all the leap years in between. I am displaying it at the moment by dividing by the number of seconds in a year, week, hours and minute which is accurate enough for this applications.

Here is a method to do it:


#define kLTWTimeSecondsPerMinute 60
#define kLTWTimeMinutesPerHour 60
#define kLTWTimeSecondsPerHour (kLTWTimeSecondsPerMinute * kLTWTimeMinutesPerHour)
#define kLTWTimeHoursPerDay 24
#define kLTWTimeDaysPerWeek 7
#define kLTWTimeWeeksPerYear 52

#define kLTWTimeSecondsPerDay (kLTWTimeSecondsPerHour * kLTWTimeHoursPerDay)
#define kLTWTimeSecondsPerWeek (kLTWTimeSecondsPerDay * kLTWTimeDaysPerWeek)
#define kLTWTimeSecondsPerYear (kLTWTimeSecondsPerWeek * kLTWTimeWeeksPerYear)
*snip*

I'm not sure why you needed to reinvent the wheel when NSCalendar and NSDateComponents already does this via:

-(NSDateComponents*) components:(NSCalendarUnit)unitFlags fromDate:(NSDate*)startingDate toDate:(NSDate*)resultDate options:(NSCalendarOptions)opts;

All you need to do is format the string, like you did. Plus, you didn't display months, and most people would want to see that rather than having to do math in their head.

--
Steve Mills
Drummer, Mac geek


Re: How to Display a Time Interval

Dave
 

Hi,

As far as I know I don’t have to worry about leap years, get the Interval between now and some future date, this includes all the leap years in between. I am displaying it at the moment by dividing by the number of seconds in a year, week, hours and minute which is accurate enough for this applications.

Here is a method to do it:


#define kLTWTimeSecondsPerMinute 60
#define kLTWTimeMinutesPerHour 60
#define kLTWTimeSecondsPerHour (kLTWTimeSecondsPerMinute * kLTWTimeMinutesPerHour)
#define kLTWTimeHoursPerDay 24
#define kLTWTimeDaysPerWeek 7
#define kLTWTimeWeeksPerYear 52

#define kLTWTimeSecondsPerDay (kLTWTimeSecondsPerHour * kLTWTimeHoursPerDay)
#define kLTWTimeSecondsPerWeek (kLTWTimeSecondsPerDay * kLTWTimeDaysPerWeek)
#define kLTWTimeSecondsPerYear (kLTWTimeSecondsPerWeek * kLTWTimeWeeksPerYear)


-(NSString*) newIntevalStringWithDateString:(NSString*) theDateString andTitleString:(NSString*) theTitleString
{
NSDateFormatter* myDateFormatter;
NSDate* myIntevalDate;
NSString* myIntevalString;
NSTimeInterval myWorkTimeInteval;
NSInteger myNumberOfYears;
NSInteger myNumberOfWeeks;
NSInteger myNumberOfDays;
NSInteger myNumberOfHours;
NSInteger myNumberOfMinutes;

myDateFormatter = [[NSDateFormatter alloc] init];
[myDateFormatter setDateFormat:@"yyyy-MM-dd"];
myIntevalDate = [myDateFormatter dateFromString:theDateString];
myWorkTimeInteval = [myIntevalDate timeIntervalSinceNow];

myNumberOfYears = myWorkTimeInteval / kLTWTimeSecondsPerYear;
myWorkTimeInteval = myWorkTimeInteval - (myNumberOfYears * kLTWTimeSecondsPerYear);

myNumberOfWeeks = myWorkTimeInteval / kLTWTimeSecondsPerWeek;
myWorkTimeInteval = myWorkTimeInteval - (myNumberOfWeeks * kLTWTimeSecondsPerWeek);

myNumberOfDays = myWorkTimeInteval / kLTWTimeSecondsPerDay;
myWorkTimeInteval = myWorkTimeInteval - (myNumberOfDays * kLTWTimeSecondsPerDay);

myNumberOfHours = myWorkTimeInteval / kLTWTimeSecondsPerHour;
myWorkTimeInteval = myWorkTimeInteval - (myNumberOfHours * kLTWTimeSecondsPerHour);

myNumberOfMinutes = myWorkTimeInteval / kLTWTimeSecondsPerMinute;
myWorkTimeInteval = myWorkTimeInteval - (myNumberOfMinutes * kLTWTimeSecondsPerMinute);

myIntevalString = [[NSString alloc] initWithFormat:@"%@ - Years: %zd  Weeks: %2zd   Days: %zd   Hours: %zd   Minutes: %zd",theTitleString,myNumberOfYears,myNumberOfWeeks,myNumberOfDays,myNumberOfHours,myNumberOfMinutes];

return myIntevalString;
}

All the Best
Dave

On 19 May 2019, at 19:45, Marco S Hyman <marc@...> wrote:


I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.

Can not be done accurately using only a Time Interval in seconds.  You also need either the start or end date to figure out leap year complications.

Is there a method or class somewhere that does this or do I need to roll my own?

Don’t know of any.  I’d probably roll my own.

Marc




Re: How to Display a Time Interval

Shane Stanley
 

On 20 May 2019, at 4:20 am, Gary L. Wade <garywade@...> wrote:

After you get the components using the calendar you wish to use with your two dates, then call NSDateComponentsFormatter.
If he has a time interval, why not just use NSDateComponentsFormatter's -stringFromTimeInterval:?

Either way, be aware that NSDateComponentsFormatter doesn't cope with an interval of 2^32 or above. Which seems a bit extraordinary, given it didn't appear until macOS 10.10.

--
Shane Stanley <sstanley@...>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Re: How to Display a Time Interval

Gary L. Wade
 

Sorry, forgot the last part.  After you get the components using the calendar you wish to use with your two dates, then call NSDateComponentsFormatter.  For a simple case, you could get by with:

+ (nullable NSString *)localizedStringFromDateComponents:(NSDateComponents *)components unitsStyle:(NSDateComponentsFormatterUnitsStyle) unitsStyle;


On May 19, 2019, at 11:13 AM, Gary L. Wade <garywade@...> wrote:

Use NSCalendar’s method:

- (NSDateComponents *)components:(NSCalendarUnit)unitFlags fromDate:(NSDate *)startingDate toDate:(NSDate *)resultDate options:(NSCalendarOptions)opts;


On May 19, 2019, at 3:02 AM, Dave <dave@...> wrote:

Objective-C, Mac.

Hi,

I’m trying to display a countdown to a date in the future e.g. the number of years, weeks and days to 1/1/2021.

I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.

Is there a method or class somewhere that does this or do I need to roll my own?

All the Best
Dave



Re: How to Display a Time Interval

Marco S Hyman
 

Ooops, I’m wrong...

Can not be done accurately using only a Time Interval in seconds. You also need either the start or end date to figure out leap year complications.
Leap year complications should be part of the time interval and be ignored.

My programming history got the better of my knowledge... the first ever COBOL program I wrote figured out how many days until my military enlistment was over -- and it was off by one because of a leap year.


Re: How to Display a Time Interval

Gary L. Wade
 

Use NSCalendar’s method:

- (NSDateComponents *)components:(NSCalendarUnit)unitFlags fromDate:(NSDate *)startingDate toDate:(NSDate *)resultDate options:(NSCalendarOptions)opts;


On May 19, 2019, at 3:02 AM, Dave <dave@...> wrote:

Objective-C, Mac.

Hi,

I’m trying to display a countdown to a date in the future e.g. the number of years, weeks and days to 1/1/2021.

I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.

Is there a method or class somewhere that does this or do I need to roll my own?

All the Best
Dave


Re: How to Display a Time Interval

Marco S Hyman
 

I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.
Can not be done accurately using only a Time Interval in seconds. You also need either the start or end date to figure out leap year complications.

Is there a method or class somewhere that does this or do I need to roll my own?
Don’t know of any. I’d probably roll my own.

Marc


Re: How to Display a Time Interval

Shane Stanley
 

On 19 May 2019, at 8:02 pm, Dave <dave@...> wrote:

I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.
There's NSDateComponentsFormatter, although it's fairly limited.

--
Shane Stanley <sstanley@...>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Re: How to Display a Time Interval

Owen Hartnett
 

Look at the NSDate and NSDateFormatter classes.

-Owen

On May 19, 2019, at 6:02 AM, Dave <dave@...> wrote:

Objective-C, Mac.

Hi,

I’m trying to display a countdown to a date in the future e.g. the number of years, weeks and days to 1/1/2021.

I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.

Is there a method or class somewhere that does this or do I need to roll my own?

All the Best
Dave




How to Display a Time Interval

Dave
 

Objective-C, Mac.

Hi,

I’m trying to display a countdown to a date in the future e.g. the number of years, weeks and days to 1/1/2021.

I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.

Is there a method or class somewhere that does this or do I need to roll my own?

All the Best
Dave


flagsChanged: not being called on NSControl subclass

Steve Mills
 

What do you have to do these days to make this work? I tried returning YES from acceptsFirstResponder, as was suggested somewhere.

There is 1 NSTrackingArea added to the view, using options NSTrackingCursorUpdate | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag.

isOpaque returns NO.

Not sure what else to try. Just trying to set the cursor when modifiers change.

--
Steve Mills
Drummer, Mac geek


Re: Creating objects via AppleScript and setting readonly properties

Steve Mills
 

On May 10, 2019, at 23:06:30, Shane Stanley <sstanley@...> wrote:

If you're logging a feature request, I'd be delighted to back it. But when you said "is", I presumed you meant present tense.
Yes, I did mean if there was currently a way to do it, but then I meandered over to "wouldn't it be great" territory. I've submitted radar://50687965 for this feature suggestion.

I was also thinking back to my MultiAd days when Creator's 'aete' Terminology.r file, which would've been a total nightmare had there been no such thing as preprocessing .r files. It's 435k.

--
Steve Mills
Drummer, Mac geek

521 - 540 of 1478