UUIDWithString crash when input invalid param [duplicate] - ios

This question already has answers here:
How to check the validity of a GUID (or UUID) using NSRegularExpression or any other effective way in Objective-C
(4 answers)
Closed 3 years ago.
When I use [CBUUID UUIDWithString:#"xxx"], something like that the invalid uuid string, the app will crash.
How to check if the param is a valid UUID-format.
The error is:
Assertion failure in -[CBUUID initWithString:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/MobileBluetoothFramework/MobileBluetooth-115.5.1/CoreBluetooth/CoreBluetooth/CBUUID.m:149
I can't understand why the assertion happens on release version. Maybe Apple forget to turn off assertion switch.

Try this:
-(BOOL)isUUID:(NSString *)string
{
return !![[NSUUID alloc] initWithUUIDString:string];
}

Related

Localization.strings: The data couldn’t be read because it isn’t in the correct format [duplicate]

This question already has answers here:
Localization in Swift 2
(3 answers)
Closed 5 years ago.
The data couldn’t be read because it isn’t in the correct format. The text in .string file. Please help me for it
abc = "abc"
xyz = "xyz"
You have to set a semicolon after each row, that´s why you´re getting that error:
Like this:
abc = "abc";
xyz = "xyz";

How to get iOS APP archive date using Swift [duplicate]

This question already has answers here:
Get build date and time in Swift
(6 answers)
Closed 5 years ago.
I have a requirement in my application that, i need to show .ipa file creation date using swift.
Can anybody tell me how to do that.
Thanks in advance.
You can get the url of your app using Bundle property executableURL and use url method resourceValues to get the bundle creation date:
if let executableURL = Bundle.main.executableURL,
let creation = (try? executableURL.resourceValues(forKeys: [.creationDateKey]))?.creationDate {
print(creation)
}

How to get String from a NSTaggedPointerString? [duplicate]

This question already has answers here:
convert NSTaggedPointerString to NSString
(5 answers)
Closed 6 years ago.
It's about a Get network request, for more information please see this pic.
I want to get the argument "pilotCode", but its value is "0xa00006e....", I want to get its real value which is "admin", please tell me what should I do?
Thank you very much.
I solved this problem just now.
just add this code:
"NSString *realStr = [NSString stringWithString:pilotCode];"

String Shown as Unicode - Swift [duplicate]

This question already has answers here:
Saving Hebrew text to NSUserDefaults return strange encoding
(3 answers)
Closed 7 years ago.
When I print a String array to the log most of the Strings show up like they're suppose to, but sometimes the show like this:
\U200e\U05d3\U05d5\U05e8\U05d9\U05ea \U05dc\U05d5\U05d9\U200e
What is causing this problem?
When you log an array with NSLog, or when you log an NSArray with print, you are relying on Cocoa's logging. It's very old so it represents a non-ASCII string by showing its codepoints.
If you don't like that, log with Swift's print and make sure you are logging a Swift Array, not an NSArray.
let s = "\u{200e}\u{05d3}\u{05d5}\u{05e8}\u{05d9}\u{05ea}"
NSLog("%#",[s]) // Cocoa is logging
print([s] as NSArray) // Cocoa is logging
print([s]) // Swift is logging

Not allowed to call release on NSString [duplicate]

This question already has answers here:
Release a NSMutableArray when using ARC
(2 answers)
Closed 9 years ago.
I have a string that I generate with JSON data from an URL
NSString *strResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
This code is inside viewDidLoad method. I want to release the string before I exit the method to avoid any memory leak, and I do this according to this post.
[strResult release];
However, xCode does not allow me by giving error: ARC forbids explicit send message of 'release'.
Anybody knows why? I tried to google it but no luck. I am new to iOS programming, and I have tried to google it before I asked. So any help will be appreciated.
ARC automatically adds the methods to deallocate objects, at compile time, for you.

Resources