Optional�Ȃ�Swift��Objective-C�̈Ⴂ���ӎ�����Photos Framework���g���FiPhone 6�^6 Plus�A�v���J������i4�j�i1/3 �y�[�W�j

iPhone 6�^6 Plus�A�v����Swift����ō쐬���Ă݂����Ƃ������S�Ҍ�����iOS 8�̐V�@�\���g�����A�v���̍������ꂩ�����������A�ځB����́A�O��̋L���Œlj������ʐ^�̏����uPhotos Framework�v�̋@�\���g�p���Ď��o���A�ʐ^�̏��ɂЂ��t�������W�Ƀs����\�����܂��B�܂��A���̉ߒ���Optional�Ȃ�Swift��Objective-C�̈Ⴂ�ɂ‚��ĉ�����܂��B

» 2015�N03��03�� 17��40�� ���J
[�����^���C�N���X���\�b�h�������]
uiPhone 6^6 PlusAvJṽCfbNX

�A�ږڎ�

�ʐ^�̏��ɂЂ��t�������W�Ƀs����\������

�@�O��́uSwift�ł̕ϐ��̒�`�AXcode�ł̃A�E�g���b�g�ڑ��AiOS�V�~�����[�^�[�ւ̉摜�f�ޒlj��v�ł́ASwift�ł̕ϐ���`�ɂ‚��ĉ�����AMapView��փs���̒lj��Ɖ摜�f�ނ̒lj����s���܂����B

�O��̐}11�@iOS�V�~�����[�^�[�iiPhone 4S�j�̎��s���ʁi���F�ʐ^�A�v����Photos�^�u�A�E�F�ʐ^�A�v���̏ڍ׉�ʁj

�@����͑O��̋L���Œlj������ʐ^�̏����uPhotos Framework�v�̋@�\���g�p���Ď��o���A�ʐ^�̏��ɂЂ��t�������W�Ƀs����\�����܂��B

�@������A�O��Ɉ��������uViewController.swift�v�t�@�C���ɃR�[�h��lj����Ă����܂��B

���\�b�h���̃R�[�h�����t�@�N�^�����O���ēǂ݂₷������

�@�O��̋L���ŁuViewController.swift�v�t�@�C���́uviewDidLoad�v���\�b�h����MapView�̐ݒ�Ɋւ���R�[�h��lj����܂����B

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
 
    self.mapView.rotateEnabled = false
    self.mapView.pitchEnabled = false
 
    let centerCoordinate = CLLocationCoordinate2D(latitude: 35.681382, longitude: 139.766084)
    let initialSpan = MKCoordinateSpan(latitudeDelta: 0.4, longitudeDelta: 0.4)
    let initialRegion = MKCoordinateRegion(center: centerCoordinate, span: initialSpan)
    self.mapView.setRegion(initialRegion, animated: true)
}
�O���viewDidLoad���\�b�h

�@����A����ɃR�[�h��lj����Ă����̂ŁA5�`12�s�ڂ̏����̂ЂƂ܂Ƃ܂��ʂ̃��\�b�h�ɕ����Ă��܂��܂��傤�B

Swift�̃��\�b�h�̊�{�`

�@Swift�̃��\�b�h�̊�{�`�͈ȉ��̂悤�ɂȂ�܂��B

func ���\�b�h�� (������: �^) -> �߂�l�̌^ {
  // ����
}

���\�b�h��V�K�쐬

�@MapView�̏����ݒ���s��5�`12�s�ڂ̏������uprepareMapView�v���\�b�h�Ƃ��āuViewController.swift�v�t�@�C���́udidReceiveMemoryWarning�v���\�b�h�̎��̍s�ɒlj����܂��傤�B

�@����lj����郁�\�b�h�͈����E�߂�l�Ƃ��Ɂg�Ȃ��h�Ȃ̂ŁA�ufunc prepareMapView()�v�Ƃ����L�q���”\�ł��B�܂��A���̃��\�b�h��viewController.swift�����炵���g�p���Ȃ��̂ŁA�A�N�Z�X�C���q�uprivate�v���w�肵�Ă��܂��B

private func prepareMapView() {
    self.mapView.rotateEnabled = false
    self.mapView.pitchEnabled = false
 
    let centerCoordinate = CLLocationCoordinate2D(latitude: 35.681382, longitude: 139.766084)
    let initialSpan = MKCoordinateSpan(latitudeDelta: 0.4, longitudeDelta: 0.4)
    let initialRegion = MKCoordinateRegion(center: centerCoordinate, span: initialSpan)
    self.mapView.setRegion(initialRegion, animated: true)
}
prepareMapView���\�b�h

viewDidLoad���\�b�h����prepareMapView���\�b�h���Ăяo��

�@�ȉ��̂悤��viewDidLoad���\�b�h���C�����āuprepareMapView�v���\�b�h���Ăяo���悤�ɂ��܂��傤�B

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
 
    self.prepareMapView()
}

�t�H�g���C�u�����ւ̃A�N�Z�X���‚����߂�R�[�h��lj�����

�@���悢��uPhotos Framework�v�̋@�\���g���n�߂܂��B

import���̒lj�

�@�uViewController.swift�v�t�@�C���̐擪�́uimport MapKit�v�̎��̍s�Ɂuimport Photos�v�Ƃ���1�s��lj����܂��B

import UIKit
import MapKit
import Photos // �lj�

��‚̃��\�b�h��lj�

�@��قǍ쐬�����uprepareMapView�v���\�b�h�ɉ����ē�‚̃��\�b�h��lj����܂��B

�@�ucheckAuthorizationStatus�v���\�b�h���ł́A�t�H�g���C�u�����ւ̃A�N�Z�X���‚��`�F�b�N���A�����‚ł���΋��‚����߂鏈�����s���܂��B�t�H�g���C�u�����ւ̃A�N�Z�X�����‚���Ă��Ȃ��ƃA���o����ʐ^�̏����擾�ł��܂���̂ŁA�^����Ƀ`�F�b�N�������s���܂��B

�@�uprepareAnnotations�v���\�b�h��MapView�ɒ��߃I�u�W�F�N�g��lj����郁�\�b�h�ł��B�������e�͌�قǐ������܂��B

private func checkAuthorizationStatus() {
    let status = PHPhotoLibrary.authorizationStatus()
 
    switch status {
    case .Authorized:
        self.prepareAnnotations()
    default:
        PHPhotoLibrary.requestAuthorization{ status in
            if status == .Authorized {
                self.prepareAnnotations()
            }
        }
    }
}
 
private func prepareAnnotations() {
    // ����
}

�@�܂��A�ȉ��̂悤��viewDidLoad���\�b�h�C�����āucheckAuthorizationStatus�v���\�b�h���Ăяo���悤�ɂ��Ă����܂��B

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    self.prepareMapView()
    self.checkAuthorizationStatus()
}

�@�ucheckAuthorizationStatus�v���\�b�h���̃R�[�h�����Ă����܂��傤�B

�uPHPhotoLibrary�v�N���X�́uauthorizationStatus�v���\�b�h

�@�uPHPhotoLibrary�v�N���X�́uauthorizationStatus�v���\�b�h���g�p����ƁA�uPHAuthorizationStatus�v�^�̒l���擾�ł��܂��B

�@�uPHAuthorizationStatus�v�^�̊e�l�̓��e�͈ȉ��̒ʂ�ł��B

�X�e�[�^�X ���e
NotDetermined �A�v���ɗ^���錠�������[�U�[�͂܂��I�����Ă��Ȃ�
Restricted �t�H�g���C�u�����ւ̃A�N�Z�X�����‚���Ă��Ȃ��i�y�A�����^���R���g���[���Ȃǁj
Denied �t�H�g���C�u�����ւ̃A�N�Z�X�����[�U�[�������I�ɋ��ۂ��Ă���
Authorized �t�H�g���C�u�����ւ̃A�N�Z�X�����[�U�[�����‚��Ă���

�@�܂��A�uPHAuthorizationStatus�v�^�̒�`�͈ȉ��̂悤�ɂȂ��Ă��܂��B

enum PHAuthorizationStatus : Int {
    case NotDetermined
    case Restricted
    case Denied
    case Authorized
}

�@switch������case���ł́ucase .Authorized:�v�ƋL�q���Ă��܂����A����́ucase PHAuthorizationStatus.Authorized:�v�Ƃ����L�q�̊ȗ��\�L�ł��B�萔�ustatus�v�̌^���^���_�Ō��܂邽�߁A���̂悤�ȋL�q���”\�ɂȂ��Ă��܂��B

�@�@�@�@�@�@ 1|2|3 ���̃y�[�W��

Copyright © ITmedia, Inc. All Rights Reserved.

'; this.insertTarget = document.querySelector('#cmsBody .subscription') || document.querySelector('#cmsBody .inner'); }; BodyAdIMSWithCCE.prototype = Object.create(BodyAdContent.prototype); BodyAdIMSWithCCE.prototype.activate = function () { refreshGam('InArtSpecialLink'); } // global reference window.itm = itm; //entry point BodyAdEventBase.polyfill(); const bodyAdManager = BodyAdManager.getInstance(); bodyAdManager.addEventListener(BodyAdManager.EVENTS.READY, function (ev) { bodyAdManager.loadAdvertise(); }); bodyAdManager.init(); })();
�X�|���T�[����̂��m�点PR

���ڂ̃e�[�}

Microsoft  WindowsőO2025
AI for GWjAO
[R[h^m[R[h Zg by IT - ITGWjArWlX̒SŊ􂷂gD
Cloud Native Central by IT - XP[uȔ\͂gD
�V�X�e���J���m�E�n�E �y�����i�r�zPR
���Ȃ��ɂ������߂̋L��PR

RSS�ɂ‚���

�A�C�e�B���f�B�AID�ɂ‚���

���[���}�K�W���o�^

��IT�̃��[���}�K�W���́A �������A���ׂĖ����ł��B���Ѓ��[���}�K�W�������w�ǂ��������B