'CS/iPhone'에 해당되는 글 9건

  1. 2012.01.24 [IPHONE] UUID 생성
  2. 2012.01.14 [IPHONE] TableViewCell style
  3. 2012.01.13 [IPHONE] UI Element size
  4. 2012.01.12 [IPHONE] Using Core Data
  5. 2011.12.29 [IPHONE] Core Data Core Competencies
  6. 2011.12.29 [IPHONE] 나눔고딕 적용
  7. 2010.11.24 [IPHONE] Xcode template
  8. 2010.08.25 [IPHONE] Break on exception in Xcode. & Enable NSZombie
  9. 2010.08.02 [IPHONE] There are three ways to access the contents of a NIB.

[IPHONE] UUID 생성

CS/iPhone 2012. 1. 24. 17:52
원문 : http://stackoverflow.com/questions/7016311/how-to-generate-unique-identifier

+ (NSString *)uuid

{

    CFUUIDRef uuidRef = CFUUIDCreate(NULL);

    CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);

    CFRelease(uuidRef);

    return [(NSString *)uuidStringRef autorelease];

}

 
:

[IPHONE] TableViewCell style

CS/iPhone 2012. 1. 14. 22:41
원문 : http://borkware.com/quickies/one?topic=UITableView

 
:

[IPHONE] UI Element size

CS/iPhone 2012. 1. 13. 13:33
:

[IPHONE] Using Core Data

CS/iPhone 2012. 1. 12. 23:20
원문 : http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html

Managed Object

Custom implementation

- NSManagedObject의 서브클래스에 대해 작성하는 accessor methods의 구현에는 일반적으로 다른 클래스를 작성하는것과는 다르다.
  • 만약 custom instance variable을 제공하지 않는다면, primitive accessor method를 사용하여 internal store로 값을 저장하고, internal store로 부터 property value를 가져오게 된다. 
  • NSManagedObject 는 modeld properties에 대해서 automatic KVO  change notification 을 비활성화 하며, primitive accessor methods는 access notification method와 change notification method를 invoke하지 않는다.
  • Entity model에서 정의되지 않은 property들의 accessor method에서, automatic change notification을 활성화 하거나 적절한 change notification method를 invoke할 수 있다.

Creating

NSManagedObject *newEmployee = [NSEntityDescription insertNewObjectForEntityForName:@"Employee"

                                                             inManagedObjectContext:context];


NSManagedObject *newEmployee = [[NSManagedObject alloc] initWithEntity:employeeEntity

                                        insertIntoManagedObjectContext:context];



Entity Description

NSManagedObjectContext *context = <#Get a context#>;

NSManagedObjectModel *managedObjectModel = [[context persistentStoreCoordinator] managedObjectModel];

NSEntityDescription *employeeEntity = [[managedObjectModel entitiesByName] objectForKey:@"Employee"];


NSManagedObjectContext *context = <#Get a context#>;

NSEntityDescription *employeeEntity = [NSEntityDescription entityForName:@"Employee"

                                                  inManagedObjectContext:context];



Deleting

NSManagedObjectContext *context = <#Get a context#>;

[context deleteObject:managedObject];


- managed object context에 deleteObject: 메세지를 보내면, context는 NSManagedObjectContextObjectsDidChangeNotification 통지를 post한다.
- 만약 object가 동일한 transaction에서 create되고 delete 된다면, managed object context의 deletedObject 의 결과 array나 NSManagedObjectContextDidSaveNotification 통지의 deleted object set에 나타나지 않을 것이다. 



To-many relationships

NSMutableSet *employees = [aDepartment mutableSetValueForKey:@"employees"];

[employees addObject:newEmployee];

[employees removeObject:firedEmployee];


// or


[aDepartment addEmployeesObject:newEmployee];

[aDepartment removeEmployeesObject:firedEmployee];


- mutableSetValueForKey: 에 의해 리턴되는 값과 dot accessor method에 의해 리턴되는 값의 차이를 이해하는 것은 중요하다.
- mutableSetValueForKey:는  mutable proxy object를 리턴한다.
- 만약 그것의 내용을 바꾼다면, relationship에 대한 적절한 KVO change 통지를 emit 할 것이다. 
- dot accessor 는 단순히 set을 리턴한다.
- 만약 [aDepartment.employees addObject:newEmployee] 와 같이 한다면, KVO change notification은  emit 되지 않을 것이며, inverse relationship은 적절하게 update되지 않을 것이다. 
- dot 은 accessor method를 invoke 하기 떄문에, [[aDepartment employees] addObject:newEmployee]; 도 같은 결과이다. 



Manipulating Relationships and Object Graph Integrity

- Core Data 는 object graph의 consistency를 관리하기 때문에, 관계의 한쪽 끝만을 변경하면 다른 면은 Core Data 가 관리해 준다.


anEmployee.department = newDepartment;

or

[newDepartment addEmployeeObject:anEmployee]; 



Managed Object Context

Undo management

- 각 managed object context는 undo manager를 유지한다.
- Undo 비활성화

[context processPendingChanges]; // Flush operations for which you want undos

[[context undoManager] disableUndoRegistration];


// Make changes for which undo operations are not to be recorded

// ...


[context processPendingChanges]; // Flush operations for which you do not want undos

[[context undoManager] enableUndoRegistration];




Managed Object Model

Runtime에  NSManagedObjectModel 얻기

[[<#A managed object context#> persistentStoreCoordinator] managedObjectModel];
[[<#A managed object#> entity] managedObjectModel];  



Fetch

Fetching managed objects

NSManagedObjectContext *context = [self managedObjectContext];

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee"

                                                     inManagedObjectContext:context];

NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setEntity:entityDescription];


NSNumber *minimumSalary = ...;

NSPredicate *predicate = [NSPredicate predicateWithFormat:

                          @"(lastName LIKE[c] 'Worsley') AND (salary > %@)", minimumSalary];

[request setPredicate:predicate];


NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];

[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];

[sortDescriptor release];


NSError *error = nil;

NSArray *array = [context executeFetchRequest:request error:&error];
[request release];
 

- transient properties에 기반한 predicate를 사용해서 fetch할 수는 없다.

 

Template 사용

NSManagedObjectModel *model = <#Get a model#>;

NSFetchRequest *requestTemplate = [[NSFetchRequest alloc] init];

NSEntityDescription *publicationEntity = [[model entitiesByName] objectForKey:@"Publication"];

[requestTemplate setEntity:publicationEntity]; 

NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat:

                                  @"(mainAuthor.firstName like[cd] $FIRST_NAME) AND \

                                  (mainAuthor.lastname like[cd] $LST_NAME) AND \

                                  (publicationDate > $DATE)"]; 

[requestTemplate setPredicate:predicateTemplate]; 

[model setFetchRequestTemplate:requestTemplate forName:@"PublicationsForAuthorSinceDate"]; 

[requestTemplate release];

 

NSError *error = nil;

NSDictionary *substitutionDictionary = [NSDictionary dictionaryWithObjectsAndKeys:

                                        @"Fiona", @"FIRST_NAME",

                                        @"Verde", @"LAST_NAME",

                                        [NSDate dateWithTimeIntervalSinceNow:-31356000], @"DATE",

                                        nil];

NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"PubliccationsForAuthorSinceDate"

                                                 substitutionVariables:substitutionDictionary]; 

NSManagedObjectContext *context = <#Get a managed object context#>;

NSArray *results = [context executeFetchRequest:fetchRequest error:&error];



Retrieving specific objects

NSManagedObjectContext *context = [self managedObjectContext];

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee"

                                                     inManagedObjectContext:context];

NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setEntity:entityDescription];

[request release];


NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self == %@", targetObject];

[request setPredicate:predicate];


NSError *error = nil;

NSArray *array = [context executeFetchRequest:request error:&error];


:

[IPHONE] Core Data Core Competencies

CS/iPhone 2011. 12. 29. 21:39
:

[IPHONE] 나눔고딕 적용

CS/iPhone 2011. 12. 29. 03:25
참고 : http://kgriff.posterous.com/45359635

1. plist 에 폰트 등록

<key>UIAppFonts</key>
<array>
<string>NanumGothicExtraBold.ttf</string>
<string>NanumGothicBold.ttf</string>
<string>NanumGothic.ttf</string>
</array>

혹은  "Fonts provided by application" 에 추가

OTF는 시뮬러에터에서는 동작하나, Device 에서 동작 안하는듯. (확인 필요)

2. 사용

[UIFont fontWithName:@"NanumGothicExtraBold" size:22.0];
[UIFont fontWithName:@"NanumGothicBold" size:22.0];
[UIFont fontWithName:@"NanumGothic" size:22.0]; 



Device 에서 보았을 때, 그다지 깔끔하지 않은 것 같음. OTL...

:

[IPHONE] Xcode template

CS/iPhone 2010. 11. 24. 14:53
Xcode template 위치 (Source)
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates

User template 위치
${USER}/Library/Application Support/Developer/Shared/Xcode/Project Templates
:

[IPHONE] Break on exception in Xcode. & Enable NSZombie

CS/iPhone 2010. 8. 25. 09:23
참조 

Break on exception in Xcode.
Double-Click for symbol > “objc_exception_throw

Enable NSZombie
1. Double-click an executable in the Executables group of your Xcode project.
2. Click the Arguments tab.
3. In the “Variables to be set in the environment:” section, make a variable called “NSZombieEnabled” and set its value to “YES”.
:

[IPHONE] There are three ways to access the contents of a NIB.

CS/iPhone 2010. 8. 2. 09:40

원문 :

Cocoa-dev mailing list

subject : [iPhone] Nib Loading Question


There are three ways to access the contents of a NIB.


1. Via -[UIViewController initWithNibName:bundle:], which connects the

references to outlets in File's Owner (the view controller itself). If a root object in the NIB doesn't have a link to the owner's outlet, that object is adrift and goes away at the next autorelease drain.


2. Via -[NSBundle loadNibNamed:owner:options:], you specify an owner object,

which again gets its IBOutlets filled in from links to File's Owner in the NIB. No link, no object.


3. By taking the NSArray returned by -[NSBundle loadNibNamed:owner:options:],

usually with owner: set to nil (though that's not required). The array contains all the root objects in the NIB.


Let's simplify for a beginner, concentrating only on how the nib's top-level objects are accessed, and for a moment ignoring the question of how the nib gets loaded in the first place.


There are *two* ways to access to the top-level objects of a nib: either through the NSArray returned by -[NSBundle loadNibNamed:owner:options:], or through a chain of outlets rooted in the instance that owns the nib at the time it loads (represented in the nib by the file's owner proxy). You (the beginner) will almost certainly use the latter. Back your outlets by a retain-policy setter (typically thru a property and synthesized accessors), since otherwise the loaded object will vanish in a puff of smoke and you'll crash when you send a message to a dangling pointer.

: