Creating UUIDs

+ UUID

Create and returns a new UUID with RFC 4122 version 4 random bytes.

Example

NSUUID *uuid = [NSUUID UUID];
NSLog(@"%@",uuid);
		

Output

2014-04-16 08:09:46.309 iOS-Tutorial[2617:a0b] <__NSConcreteUUID 0x9819fc0> A4B00212-0BC8-47AE-9FD9-ADBED148D269		

- init

Create and returns a new UUID with RFC 4122 version 4 random bytes.

Example

NSUUID *uuid = [[NSUUID alloc]init];
NSLog(@"%@",uuid);
		

Output

2014-04-16 08:10:15.572 iOS-Tutorial[2630:a0b] <__NSConcreteUUID 0x8d783b0> 20B0DDE7-6087-4607-842A-E97C72E4D522		

- initWithUUIDString:

Creates and returns a new UUID from the formatted string.

Example

NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"20B0DDE7-6087-4607-842A-E97C72E4D522"];
NSLog(@"%@",uuid);
		

Output

2014-04-16 08:13:57.572 iOS-Tutorial[2648:a0b] <__NSConcreteUUID 0x9890660> 20B0DDE7-6087-4607-842A-E97C72E4D522
		

Get UUID Values

- UUIDString

Returns the UUID as a string.

Example

NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"20B0DDE7-6087-4607-842A-E97C72E4D522"];
NSLog(@"%@",[uuid UUIDString]);		
	

Output

2014-04-16 08:15:04.765 iOS-Tutorial[2663:a0b] 20B0DDE7-6087-4607-842A-E97C72E4D522
		

Advertisements