Date   

How to get Extended File Info

Dave
 

Hi,

Looking at the Finder “Get Info” window, for instance for an mp3 file, it displays under the “More Info” tab, the Title, Authors, etc.

How can I get this information programatically?

Thanks a lot
All the Best
Dave


Re: NSFIleManager enumeratorAtPath problem

Sandor Szatmari
 

Are the folders actual folders? Or symlinks?

What OS, SDK, etc?

Sandor

On Jun 6, 2019, at 07:06, Dave <dave@looktowindward.com> wrote:

As I said,

myExistsFlag and myFolderFlag are set to YES.

So the folder exists, I copied and pasted the Path from the finder. Also I've tried it on a number of different folders and it still doesn’t work. There are definitely files present in the folders I’ve tried.

Cheers
Dave


On 6 Jun 2019, at 12:27, Sak Wathanasin <sw@network-analysis.ltd.uk> wrote:

Can anyone spot the problem
In the code you posted, there was no check for the value of myFolderFlag
on return from fileExistsAtPath:, so are you sure it's a directory? Doc
for enumeratorAtPath: says:

"Return Value
An NSDirectoryEnumerator object that enumerates the contents of the
directory at path.

If path is a filename, the method returns an enumerator object that
enumerates no files—the first call to nextObject will return nil."

Regards
Sak Wathanasin
Network Analysis Ltd





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#972): https://apple-dev.groups.io/g/cocoa/message/972
Mute This Topic: https://groups.io/mt/31949180/342607
Group Owner: cocoa+owner@apple-dev.groups.io
Unsubscribe: https://apple-dev.groups.io/g/cocoa/leave/defanged [admin.szatmari.net@gmail.com]
-


Re: NSFIleManager enumeratorAtPath problem

Dave
 

As I said,

myExistsFlag and myFolderFlag are set to YES.

So the folder exists, I copied and pasted the Path from the finder. Also I've tried it on a number of different folders and it still doesn’t work. There are definitely files present in the folders I’ve tried.

Cheers
Dave

On 6 Jun 2019, at 12:27, Sak Wathanasin <sw@network-analysis.ltd.uk> wrote:

Can anyone spot the problem
In the code you posted, there was no check for the value of myFolderFlag
on return from fileExistsAtPath:, so are you sure it's a directory? Doc
for enumeratorAtPath: says:

"Return Value
An NSDirectoryEnumerator object that enumerates the contents of the
directory at path.

If path is a filename, the method returns an enumerator object that
enumerates no files—the first call to nextObject will return nil."

Regards
Sak Wathanasin
Network Analysis Ltd





Re: NSFIleManager enumeratorAtPath problem

Sak Wathanasin
 

Can anyone spot the problem
In the code you posted, there was no check for the value of myFolderFlag
on return from fileExistsAtPath:, so are you sure it's a directory? Doc
for enumeratorAtPath: says:

"Return Value
An NSDirectoryEnumerator object that enumerates the contents of the
directory at path.

If path is a filename, the method returns an enumerator object that
enumerates no files—the first call to nextObject will return nil."

Regards
Sak Wathanasin
Network Analysis Ltd


NSFIleManager enumeratorAtPath problem

Dave
 

Hi,

I can’t for the life of see what is wrong with the following method. I’m basically doing the same as in the NSFileManager but I can’t seem to get it to work.

The enumeratorAtPath: methods returns what appears to be a valid enumerator, but the “while” statement fails on the first call.

myExistsFlag and myFolderFlag are set to YES.

Can anyone spot the problem? I’ve been at it about an hour now.

Thanks a lot
Dave

myDictionary = [self newDictionaryFromPath:@"/Users/devDave/Desktop/Accounts/"];

//*****************************************************************************************************
-(NSDictionary*) newDictionaryFromPath:(NSString*) theSourceFilePathString
{
NSFileManager* myFileManager;
NSString* myFilePathString;
NSDirectoryEnumerator* myDirectoryEnumarator;
NSMutableDictionary* myDictionary;
BOOL myExistsFlag;
BOOL myFolderFlag;

myDictionary = [[NSMutableDictionary alloc] init];
myFileManager = [NSFileManager defaultManager];

myExistsFlag = [myFileManager fileExistsAtPath:theSourceFilePathString isDirectory:&myFolderFlag];
myDirectoryEnumarator = [myFileManager enumeratorAtPath:theSourceFilePathString];

while (myFilePathString = [myDirectoryEnumarator nextObject])
{
if ([myDictionary objectForKey:myFilePathString] != nil)
{
NSLog(@"Dupe File: %@",myFilePathString);
continue;
}

NSLog(@"Added File: %@",myFilePathString);
[myDictionary setObject:myFilePathString forKey:myFilePathString];
}

return myDictionary;
}


Re: Dealing with unicodes in strings

Graham Cox
 

OK, makes sense. A simple NSString category using NSScanner internally makes it easy enough.

Thanks for the help,

—Graham

On 1 Jun 2019, at 1:18 pm, Jens Alfke <jens@mooseyard.com> wrote:

Those are JavaScript escape sequences. If you’re reading raw JS string literals out of the page, you need to decode all the escapes, which are like the C ones plus \uxxxx.

This isn’t anything to do with NSString; NSJSONSerialization could probably decode it since JSON string syntax is based on JS.

—Jens



Re: Dealing with unicodes in strings

 

Those are JavaScript escape sequences. If you’re reading raw JS string literals out of the page, you need to decode all the escapes, which are like the C ones plus \uxxxx.

This isn’t anything to do with NSString; NSJSONSerialization could probably decode it since JSON string syntax is based on JS.

—Jens


Re: Dealing with unicodes in strings

Roland King
 

Don’t really see how NSString would be able to deal with that, it has no way of knowing there are embedded escape sequences in what is otherwise UTF-8. This looks like a fairly standard web encoding of ’special characters’ which javascript is especially fond of. I would just detect \u and treat the next two bytes at a UTF-16 character. You might find an NSString extension or another class which deals with web encodings does it seamlessly but frankly if that’s all there is, I’d just deal with it by hand. 

On 1 Jun 2019, at 08:53, Graham Cox <graham@...> wrote:

Yes, I think it’s putting these 6 characters into the string.

The original data is an HTML page, and these strings come from some embedded javascript on the page - I’m scraping the page to extract specific bits of information, and it generally works OK, except for this minor formatting issue. Though the page declares it is using UTF8 encoding, I’m wondering if that applies even to embedded javascript strings - perhaps they need to be treated as C strings?

I can write some code to deal with it, but it just seems like something NSSString can already do.

—Graham



On 1 Jun 2019, at 12:57 am, Quincey Morris <quinceymorris@...> wrote:

On May 31, 2019, at 07:51 , Glenn L. Austin <glenn@...> wrote:

Is it possible that the code "\u002D" is in the string as the six characters? It is just the minus sign, but could the source have encoded certain characters so they wouldn't be accidentally interpreted?

That’s what I was thinking too.

This would easily be resolved if we could see the bytes of the NSData in hex.




Re: Dealing with unicodes in strings

Graham Cox
 

Yes, I think it’s putting these 6 characters into the string.

The original data is an HTML page, and these strings come from some embedded javascript on the page - I’m scraping the page to extract specific bits of information, and it generally works OK, except for this minor formatting issue. Though the page declares it is using UTF8 encoding, I’m wondering if that applies even to embedded javascript strings - perhaps they need to be treated as C strings?

I can write some code to deal with it, but it just seems like something NSSString can already do.

—Graham



On 1 Jun 2019, at 12:57 am, Quincey Morris <quinceymorris@...> wrote:

On May 31, 2019, at 07:51 , Glenn L. Austin <glenn@...> wrote:

Is it possible that the code "\u002D" is in the string as the six characters? It is just the minus sign, but could the source have encoded certain characters so they wouldn't be accidentally interpreted?

That’s what I was thinking too.

This would easily be resolved if we could see the bytes of the NSData in hex.



Re: Dealing with unicodes in strings

Quincey Morris
 

On May 31, 2019, at 07:51 , Glenn L. Austin <glenn@...> wrote:

Is it possible that the code "\u002D" is in the string as the six characters? It is just the minus sign, but could the source have encoded certain characters so they wouldn't be accidentally interpreted?

That’s what I was thinking too.

This would easily be resolved if we could see the bytes of the NSData in hex.


Re: Dealing with unicodes in strings

Glenn L. Austin
 

Is it possible that the code "\u002D" is in the string as the six characters? It is just the minus sign, but could the source have encoded certain characters so they wouldn't be accidentally interpreted?

-- 
Glenn L. Austin, Computer Wizard and Race Car Driver         <><
<http://www.austinsoft.com>

On May 31, 2019, at 6:09 AM, Graham Cox <graham@...> wrote:

I’m converting some NSData to a NSString using UTF8 encoding, which is what I believe it should be.

But the strings are sometimes ending up with embedded codes that are not converting, like @“this is a string\u002D with codes in it”

What is the proper way to deal with this? I tried the various ‘canonical’ and ‘compatibility’ mapping methods but they do nothing with this, but since I don’t really know what they do, it’s no surprise. Is there a method that will just deal with this?

—Graham







Dealing with unicodes in strings

Graham Cox
 

I’m converting some NSData to a NSString using UTF8 encoding, which is what I believe it should be.

But the strings are sometimes ending up with embedded codes that are not converting, like @“this is a string\u002D with codes in it”

What is the proper way to deal with this? I tried the various ‘canonical’ and ‘compatibility’ mapping methods but they do nothing with this, but since I don’t really know what they do, it’s no surprise. Is there a method that will just deal with this?

—Graham


Encoding / decoding an Array of structs

Peter Hudson
 

Hi All

I’m trying to encode / decode an Array of struct.
The struct in question is itself Codable - and the compiler is happy with it.

In the following code,  roles is an Array of struct called Scene…

try container.encode(roles, forKey: .roles)  

  and the compiler complains    ! Reference to member 'roles' cannot be resolved without a contextual type




roles  = try container.decode([SceneRole].self, forKey: .roles)

   and the compiler complains    !  Ambiguous reference to member 'decode(_:forKey:)



Any suggestions gratefully received !


Peter


Re: How to Display a Time Interval

Gary L. Wade
 

As has been discussed before, you most likely won’t have to roll your own with the modern, non-deprecated frameworks. If you do need something that seems basic but you can’t find it, please write a bug and include its number here. I’m sure there are some, but that’s how you get things changed.
--
Gary

On May 19, 2019, at 3:42 AM, Peter Hudson via Groups.Io <Peter.hudson=me.com@groups.io> wrote:

You have to roll the final string yourself - as far as I can see...


Re: How to Display a Time Interval

 



On May 19, 2019, at 3:42 AM, Peter Hudson via Groups.Io <Peter.hudson@...> wrote:

I seem to remember using NSCalendatDate  and the descriptionWithCalendarFormat:   method to get what you want.
NSCalendarDate is now deprecated - the docs advocate the use of NSDate, NSCalendar, NSDateComponents to do the job now.
You have to roll the final string yourself - as far as I can see...

You want NSDateComponentsFormatter:

/* NSDateComponentsFormatter provides locale-correct and flexible string formatting of quantities of time, such as "1 day" or "1h 10m", as specified by NSDateComponents. For formatting intervals of time (such as "2PM to 5PM"), see NSDateIntervalFormatter. NSDateComponentsFormatter is thread-safe, in that calling methods on it from multiple threads will not cause crashes or incorrect results, but it makes no attempt to prevent confusion when one thread sets something and another thread isn't expecting it to change.


Re: How to Display a Time Interval

Peter Hudson
 

Hi Dave


I seem to remember using NSCalendatDate and the descriptionWithCalendarFormat: method to get what you want.
NSCalendarDate is now deprecated - the docs advocate the use of NSDate, NSCalendar, NSDateComponents to do the job now.
You have to roll the final string yourself - as far as I can see...

Peter

On 19 May 2019, at 11:02, Dave <dave@looktowindward.com> 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: 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

481 - 500 of 1454